Module: ActiveEnumerable::EnglishDsl
- Includes:
- ScopeMethod, Where
- Included in:
- ActiveEnumerable
- Defined in:
- lib/active_enumerable/english_dsl.rb
Constant Summary collapse
- UnmetCondition =
Class.new(StandardError)
Instance Method Summary collapse
- #and(matches = nil) ⇒ Object
- #has(attr) ⇒ Object
- #of(matches = nil, &block) ⇒ Object
-
#or(matches) ⇒ Object
After calling #of(matches) providing additional matches to #or(matches) build a either or query.
- #where(*args) { ... } ⇒ ActiveEnumerable
Methods included from Where
Methods included from ScopeMethod
Instance Method Details
#and(matches = nil) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/active_enumerable/english_dsl.rb', line 54 def and(matches=nil) if matches all_conditions.last[1].merge!(matches) evaluation_results << english_where end self end |
#has(attr) ⇒ Object
22 23 24 25 |
# File 'lib/active_enumerable/english_dsl.rb', line 22 def has(attr) all_conditions << [attr] self end |
#of(matches = nil, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/active_enumerable/english_dsl.rb', line 29 def of(matches=nil, &block) raise ArgumentError if matches.nil? && block.nil? if all_conditions.empty? || !(all_conditions.last.count == 1) raise UnmetCondition, ".has(attr) must be call before calling #of." else all_conditions.last << (matches || block) self end end |
#or(matches) ⇒ Object
After calling #of(matches) providing additional matches to #or(matches) build a either or query.
42 43 44 45 46 47 48 |
# File 'lib/active_enumerable/english_dsl.rb', line 42 def or(matches) raise UnmetCondition, ".has(attr).of(matches) must be call before calling #or(matches)." if all_conditions.empty? || !(all_conditions.last.count == 2) evaluation_results << english_where all_conditions.last[1] = matches evaluation_results << english_where self end |
#where(*args) { ... } ⇒ ActiveEnumerable
12 13 14 15 16 17 18 |
# File 'lib/active_enumerable/english_dsl.rb', line 12 def where(*args, &block) if block_given? scope(&block).send(:_english_eval__) else super end end |