File system adapter

2 views
Skip to first unread message

JLF

unread,
Oct 14, 2008, 9:37:26 AM10/14/08
to ambition.rb
Hello,

I just discovered 'ambition' an I am really interested. I would like
to write an adapter for looking for files and dirs with conditions
such as:

files = XXX.select { |f| f.name == 'foo*' || f.is_dir? && f.mtime <=
Date.today - 3 }

I need some advice. What class should I extend (XXX in the above
example) ?

- File
- Dir
- my own base class

Thanks,

jlf

Matthew King

unread,
Oct 14, 2008, 2:18:22 PM10/14/08
to ambit...@googlegroups.com
On Tue, Oct 14, 2008 at 8:37 AM, JLF <paradi...@gmail.com> wrote:

>
> files = XXX.select { |f| f.name == 'foo*' || f.is_dir? && f.mtime <=
> Date.today - 3 }
>
> I need some advice. What class should I extend (XXX in the above
> example) ?
>
> - File
> - Dir
> - my own base class

Ambition extends an object so that calling #select on it creates a
constructor for some sort of query. Ideally, there would exist some
class or object that already has a way of querying the external
dataset (in this case, a filesystem).

Dir can do that, but only with filenames. File works on strings that
are alleged to be file paths. You could probably rig some symbiotic
relationship between Dir and File, but that seems like a lot of buck
for very little bang to me.

How about this:

class UnixFind
attr_accessor :root
def query(string)
`find #{root} #{string}`
end
end

Then craft an Ambition adapter that compiles the expression for use
with find(1):

UnixFind.select { |f| f.name == "foo*" && f.type == "d" }.to_s # =>
'-name "foo*" -type d'

trans

unread,
Oct 14, 2008, 2:50:17 PM10/14/08
to ambition.rb


On Oct 14, 9:37 am, JLF <paradigma...@gmail.com> wrote:
> Hello,
>
> I just discovered 'ambition' an I am really interested. I would like
> to write an adapter for looking for files and dirs with conditions
> such as:
>
> files = XXX.select { |f| f.name == 'foo*' || f.is_dir? && f.mtime <=
> Date.today - 3 }

This is an interesting idea.

> I need some advice. What class should I extend (XXX in the above
> example) ?
>
> - File
> - Dir
> - my own base class

It would need to be a separate class. But I'm working on an improved
way for working with the file system, a project called Folio. This
would fit very nicely in with that project. the main idea of Folio is
to provide a virtual shell --though clearly Ruby. Eg.

shell = Folio.shell

shell.ls #=> ...list of entries current directory...

shell.cd('subdir')

And so on. So adding #find makes perfect sense. And supporting #select
would good too.

http://folio.rubyforge.org (note: the website is a bit behind the
actual code).

T.

JLF

unread,
Oct 15, 2008, 8:40:23 AM10/15/08
to ambition.rb
Thanks for the answers. I think I'll start playing with Folio.

trans

unread,
Oct 15, 2008, 3:22:34 PM10/15/08
to ambition.rb


On Oct 15, 8:40 am, JLF <paradigma...@gmail.com> wrote:
> Thanks for the answers. I think I'll start playing with Folio.

Cool. If you run into any bugs/issues/suggestions, feel free to beat
me over the head with them ;)

Best use the git repo at this point, btw. This project is brand
spanking new so expect rough spots.

T.
Reply all
Reply to author
Forward
0 new messages