Class: Cms::Settings::CmsModuleProxy

Inherits:
ActiveSupport::BasicObject
Defined in:
lib/bcms_settings/cms/settings.rb

Overview

Calls to Cms::Settings.bcms_yxz, where bcms_yxz is a previously registered cms module, do not return ActiveRecord objects. Instead, the CmsModule object is wrapped in an instance of the CmsModuleProxy class, which provides acces to the underlying serialized hash through arbitrary method names.

Instance Method Summary collapse

Constructor Details

#initialize(cms_module) ⇒ CmsModuleProxy

Returns a new instance of CmsModuleProxy.



219
220
221
# File 'lib/bcms_settings/cms/settings.rb', line 219

def initialize(cms_module)
  @cms_module = cms_module
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/bcms_settings/cms/settings.rb', line 232

def method_missing(method_id, *args)
  num_args = args.length
  method_name = method_id.to_s
  if method_name.chomp!("=")
    @cms_module.settings[method_name] = args.first
    @cms_module.save
  elsif num_args == 0
    @cms_module.settings[method_name]
  else
    super(method_id, *args)
  end
end

Instance Method Details

#delete(key) ⇒ Object



223
224
225
226
# File 'lib/bcms_settings/cms/settings.rb', line 223

def delete(key)
  @cms_module.settings.delete(key)
  @cms_module.save
end

#inspectObject



228
229
230
# File 'lib/bcms_settings/cms/settings.rb', line 228

def inspect
  "#<Cms::Settings: #{@cms_module.name} => #{@cms_module.settings.inspect}>"
end