Class: ActsAsActsAs::Requirements::Collector
- Inherits:
-
Object
- Object
- ActsAsActsAs::Requirements::Collector
- Defined in:
- lib/acts_as_acts_as/requirements/collector.rb
Overview
A specialized object we pass into the block of ‘acts_as` so the DSL is nice and pretty. It basically just builds a hash of requirements matchers.
Defined Under Namespace
Modules: Context
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#options_collectors ⇒ Object
Returns the value of attribute options_collectors.
-
#requirements ⇒ Object
Returns the value of attribute requirements.
Instance Method Summary collapse
-
#all ⇒ Object
Convenience method for getting the whole tree of collectors that may have been spawned off via ‘with`.
- #all_requirements ⇒ Object
- #collect(&block) ⇒ Object
-
#initialize(options = {}) ⇒ Collector
constructor
A new instance of Collector.
-
#should(matcher) ⇒ Object
Should just add the results of calling a matcher (i.e. the returned hash) to the list of requirements.
-
#with(options) ⇒ Object
spin off a duplicate collector with the extra options specified.
Constructor Details
#initialize(options = {}) ⇒ Collector
Returns a new instance of Collector.
6 7 8 9 10 11 12 13 |
# File 'lib/acts_as_acts_as/requirements/collector.rb', line 6 def initialize(={}) @requirements = {} = [] = # run into nil problems with temp_model if require_columns is nil @requirements[:require_columns] = [] end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/acts_as_acts_as/requirements/collector.rb', line 4 def end |
#options_collectors ⇒ Object
Returns the value of attribute options_collectors.
4 5 6 |
# File 'lib/acts_as_acts_as/requirements/collector.rb', line 4 def end |
#requirements ⇒ Object
Returns the value of attribute requirements.
4 5 6 |
# File 'lib/acts_as_acts_as/requirements/collector.rb', line 4 def requirements @requirements end |
Instance Method Details
#all ⇒ Object
Convenience method for getting the whole tree of collectors that may have been spawned off via ‘with`
32 33 34 |
# File 'lib/acts_as_acts_as/requirements/collector.rb', line 32 def all return [self] + .inject([]) { |a, c| a + c.all } end |
#all_requirements ⇒ Object
36 37 38 |
# File 'lib/acts_as_acts_as/requirements/collector.rb', line 36 def all_requirements all.inject({}) { |h, c| h.merge(c.requirements) } end |
#collect(&block) ⇒ Object
46 47 |
# File 'lib/acts_as_acts_as/requirements/collector.rb', line 46 def collect(&block) end |
#should(matcher) ⇒ Object
Should just add the results of calling a matcher (i.e. the returned hash) to the list of requirements
17 18 19 20 21 |
# File 'lib/acts_as_acts_as/requirements/collector.rb', line 17 def should(matcher) raise "Bad Matcher" unless matcher.is_a?(Array) and matcher.length == 2 key, args = matcher @requirements[key] = (@requirements.key?(key)) ? @requirements[key] + args : args end |
#with(options) ⇒ Object
spin off a duplicate collector with the extra options specified
24 25 26 27 28 |
# File 'lib/acts_as_acts_as/requirements/collector.rb', line 24 def with() << self.class.new() .last.requirements = self.requirements.dup # dup important so my reqs don't change return .last end |