Module: SettingsManager::Extension

Extended by:
ActiveSupport::Concern
Includes:
Scopes
Defined in:
lib/settings-manager/extension.rb,
lib/settings-manager/extension/scopes.rb

Defined Under Namespace

Modules: ClassMethods, Scopes

Instance Method Summary collapse

Instance Method Details

#settingsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/settings-manager/extension.rb', line 9

def settings
  base_class = self.class.settings_base_class.to_s.constantize

  wrapped_class = base_class.clone
  wrapped_class.instance_variable_set(:@base_obj, self)

  wrapped_class.instance_eval do
    def base_query
      where(
        :base_obj_id => @base_obj.id,
        :base_obj_type => @base_obj.class.base_class.to_s
      )
    end

    def model_name
      @base_obj.class.settings_base_class.to_s.constantize.model_name
    end
  end

  wrapped_class
end