Class: Fynd::Criteria
- Inherits:
-
Object
- Object
- Fynd::Criteria
- Extended by:
- Forwardable
- Defined in:
- lib/fynd/criteria.rb
Instance Attribute Summary collapse
-
#paths ⇒ Object
Returns the value of attribute paths.
-
#sieve ⇒ Object
Returns the value of attribute sieve.
Instance Method Summary collapse
- #files ⇒ Object
-
#initialize(*paths) ⇒ Criteria
constructor
A new instance of Criteria.
- #method_missing(symbol, *args, &block) ⇒ Object
-
#run ⇒ Object
def find(*paths) where(:paths => paths) self end.
Constructor Details
#initialize(*paths) ⇒ Criteria
Returns a new instance of Criteria.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fynd/criteria.rb', line 14 def initialize(*paths) @paths = paths @sieve = Sieve.new @sieve.collection = [] @sieve.conditions = {} @sieve.conditions['actions'] = {} @sieve.conditions['operators'] = {} @sieve.conditions['tests'] = {} # Flatten it and strip out non-unique files end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fynd/criteria.rb', line 50 def method_missing(symbol, *args, &block) if sieve.respond_to?(symbol) if ACTIONS.include?(symbol) # Only one action per expression sieve.conditions['action'] = { symbol.to_s => args[0] } elsif OPERATORS.include?(symbol) sieve.conditions['operations'].deep_merge!({ symbol.to_s => args[0] }) elsif TESTS.include?(symbol) sieve.conditions['tests'].deep_merge!({ symbol.to_s => args[0] }) else super(symbol, *args, &blocks) end self else super(symbol, *args, &blocks) end end |
Instance Attribute Details
#paths ⇒ Object
Returns the value of attribute paths.
10 11 12 |
# File 'lib/fynd/criteria.rb', line 10 def paths @paths end |
#sieve ⇒ Object
Returns the value of attribute sieve.
10 11 12 |
# File 'lib/fynd/criteria.rb', line 10 def sieve @sieve end |
Instance Method Details
#files ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/fynd/criteria.rb', line 40 def files files = run if block_given? yield files else return files end end |
#run ⇒ Object
def find(*paths)
where(:paths => paths)
self
end
32 33 34 35 36 37 38 |
# File 'lib/fynd/criteria.rb', line 32 def run @sieve.collection = paths.map do |path| Find.find(File.(path)).to_a end.flatten.uniq sieve.run return sieve.files end |