Class: Cohabit::Strategy
- Inherits:
-
Object
- Object
- Cohabit::Strategy
- Includes:
- Configuration::Settings
- Defined in:
- lib/cohabit/strategy.rb
Constant Summary
Constants included from Configuration::Settings
Configuration::Settings::CUSTOM_HANDLERS, Configuration::Settings::DEFAULT_SETTINGS
Instance Attribute Summary collapse
-
#model_code ⇒ Object
readonly
Returns the value of attribute model_code.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#strategies ⇒ Object
readonly
Returns the value of attribute strategies.
Attributes included from Configuration::Settings
Instance Method Summary collapse
- #include_strategy(name, options = {}) ⇒ Object
-
#initialize(*args, &block) ⇒ Strategy
constructor
A new instance of Strategy.
- #model_eval(&block) ⇒ Object
Methods included from Configuration::Settings
#generate_settings_hash!, included, #initialize_with_settings, #merge_settings!, #set, #set_globals
Constructor Details
#initialize(*args, &block) ⇒ Strategy
Returns a new instance of Strategy.
6 7 8 9 10 11 12 |
# File 'lib/cohabit/strategy.rb', line 6 def initialize(*args, &block) raise ArgumentError, "you must supply a name" if args.empty? @strategies = [] @name = args.shift.to_sym @settings = args.last.is_a?(Hash) ? args.last : {} instance_eval(&block) unless block.nil? end |
Instance Attribute Details
#model_code ⇒ Object (readonly)
Returns the value of attribute model_code.
16 17 18 |
# File 'lib/cohabit/strategy.rb', line 16 def model_code @model_code end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/cohabit/strategy.rb', line 16 def name @name end |
#strategies ⇒ Object (readonly)
Returns the value of attribute strategies.
16 17 18 |
# File 'lib/cohabit/strategy.rb', line 16 def strategies @strategies end |
Instance Method Details
#include_strategy(name, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/cohabit/strategy.rb', line 23 def include_strategy(name, = {}) name = name.to_sym raise ArgumentError if name.nil? if @strategies.include?(name) raise Argumenterror, "can't nest the same strategy twice or use two model_eval blocks in the same strategy" end @strategies << name end |
#model_eval(&block) ⇒ Object
18 19 20 21 |
# File 'lib/cohabit/strategy.rb', line 18 def model_eval(&block) @model_code = block @strategies << @name end |