Class: TroleGroups::Macros::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/trole_groups/macros/configuration.rb,
lib/trole_groups/macros/configuration/base_loader.rb,
lib/trole_groups/macros/configuration/config_loader.rb,
lib/trole_groups/macros/configuration/storage_loader.rb,
lib/trole_groups/macros/configuration/strategy_loader.rb

Defined Under Namespace

Classes: BaseLoader, ConfigLoader, StorageLoader, StrategyLoader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject_class, strategy, options = {}) ⇒ Configuration

Returns a new instance of Configuration.



11
12
13
14
15
16
17
18
# File 'lib/trole_groups/macros/configuration.rb', line 11

def initialize subject_class, strategy, options = {}
  @subject_class = subject_class
  @strategy = strategy
  @orm = options[:orm] || Troles::Config.default_orm
  @auto_load = options[:auto_load] || Troles::Config.auto_load?
  options[:strategy] = strategy
  @options = options
end

Instance Attribute Details

#auto_loadObject (readonly)

Returns the value of attribute auto_load.



9
10
11
# File 'lib/trole_groups/macros/configuration.rb', line 9

def auto_load
  @auto_load
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/trole_groups/macros/configuration.rb', line 9

def options
  @options
end

#ormObject (readonly)

Returns the value of attribute orm.



9
10
11
# File 'lib/trole_groups/macros/configuration.rb', line 9

def orm
  @orm
end

#singularityObject (readonly)

Returns the value of attribute singularity.



9
10
11
# File 'lib/trole_groups/macros/configuration.rb', line 9

def singularity
  @singularity
end

#strategyObject (readonly)

Returns the value of attribute strategy.



9
10
11
# File 'lib/trole_groups/macros/configuration.rb', line 9

def strategy
  @strategy
end

#subject_classObject (readonly)

Returns the value of attribute subject_class.



9
10
11
# File 'lib/trole_groups/macros/configuration.rb', line 9

def subject_class
  @subject_class
end

Instance Method Details

#apply_strategy_options!Object



35
36
37
38
39
40
# File 'lib/trole_groups/macros/configuration.rb', line 35

def apply_strategy_options!        
  trolegroups_config.apply_options! options

  # StrategyOptions.new(subject_class)
  # extract_macros(options).each{|m| apply_macro m}
end

#define_hooksObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/trole_groups/macros/configuration.rb', line 46

def define_hooks
  storage_class = storage_loader.storage_class
  # puts "storage_class: #{storage_class}"
  subject_class.send :define_method, :group_storage do 
    @group_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 trolegroups_config
      @trolegroups_config ||= #{config_class}.new #{subject_class}, #{options.inspect}
    end
  }
end

#load_adapterObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/trole_groups/macros/configuration.rb', line 24

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_moduleObject



20
21
22
# File 'lib/trole_groups/macros/configuration.rb', line 20

def strategy_module
  strategy_loader.strategy_module
end

#trolegroups_configObject



42
43
44
# File 'lib/trole_groups/macros/configuration.rb', line 42

def trolegroups_config
  subject_class.trolegroups_config
end