Class: Troles::Common::Macros::Configuration
- Defined in:
- lib/troles/common/macros/configuration.rb,
lib/troles/common/macros/configuration/base_loader.rb,
lib/troles/common/macros/configuration/config_loader.rb,
lib/troles/common/macros/configuration/storage_loader.rb,
lib/troles/common/macros/configuration/strategy_loader.rb
Defined Under Namespace
Classes: BaseLoader, ConfigLoader, StorageLoader, StrategyLoader
Instance Attribute Summary collapse
-
#auto_load ⇒ Object
readonly
Returns the value of attribute auto_load.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#orm ⇒ Object
readonly
Returns the value of attribute orm.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
-
#subject_class ⇒ Object
readonly
Returns the value of attribute subject_class.
Instance Method Summary collapse
- #apply_strategy_options! ⇒ Object
- #define_hooks ⇒ Object
-
#initialize(subject_class, strategy, options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #load_adapter ⇒ Object
- #strategy_module ⇒ Object
Constructor Details
#initialize(subject_class, strategy, options = {}) ⇒ Configuration
Returns a new instance of Configuration.
8 9 10 11 12 13 14 15 |
# File 'lib/troles/common/macros/configuration.rb', line 8 def initialize subject_class, strategy, = {} @subject_class = subject_class @strategy = strategy @orm = [:orm] || Troles::Config.default_orm @auto_load = [:auto_load] || Troles::Config.auto_load? [:strategy] = strategy @options = end |
Instance Attribute Details
#auto_load ⇒ Object (readonly)
Returns the value of attribute auto_load.
6 7 8 |
# File 'lib/troles/common/macros/configuration.rb', line 6 def auto_load @auto_load end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/troles/common/macros/configuration.rb', line 6 def @options end |
#orm ⇒ Object (readonly)
Returns the value of attribute orm.
6 7 8 |
# File 'lib/troles/common/macros/configuration.rb', line 6 def orm @orm end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
6 7 8 |
# File 'lib/troles/common/macros/configuration.rb', line 6 def strategy @strategy end |
#subject_class ⇒ Object (readonly)
Returns the value of attribute subject_class.
6 7 8 |
# File 'lib/troles/common/macros/configuration.rb', line 6 def subject_class @subject_class end |
Instance Method Details
#apply_strategy_options! ⇒ Object
32 33 34 35 36 37 |
# File 'lib/troles/common/macros/configuration.rb', line 32 def subject_class.troles_config. # StrategyOptions.new(subject_class) # extract_macros(options).each{|m| apply_macro m} end |
#define_hooks ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/troles/common/macros/configuration.rb', line 39 def define_hooks storage_class = storage_loader.storage_class subject_class.send :define_method, :storage do @storage ||= storage_class end config_class = config_loader.config_class puts "config_class: #{config_class}" if Troles::Config.log_on subject_class.singleton_class.class_eval %{ def troles_config @troles_config ||= #{config_class}.new #{subject_class}, #{.inspect} end } end |
#load_adapter ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/troles/common/macros/configuration.rb', line 21 def load_adapter return false if !auto_load? path = "#{namespace}/adapters/#{orm.to_s.underscore}" begin require path rescue raise "Adapter for :#{orm} could not be found at: #{path}" end end |
#strategy_module ⇒ Object
17 18 19 |
# File 'lib/troles/common/macros/configuration.rb', line 17 def strategy_module strategy_loader.strategy_module end |