>
> 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'