Class: RailsSettings::SettingObject

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/rails-settings/setting_object.rb

Constant Summary collapse

REGEX_SETTER =
/\A([a-z]\w+)=\Z/i
REGEX_GETTER =
/\A([a-z]\w+)\Z/i

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rails-settings/setting_object.rb', line 31

def method_missing(method_name, *args, &block)
  if block_given?
    super
  else
    if attribute_names.include?(method_name.to_s.sub('=',''))
      super
    elsif method_name.to_s =~ REGEX_SETTER && args.size == 1
      _set_value($1, args.first)
    elsif method_name.to_s =~ REGEX_GETTER && args.size == 0
      _get_value($1)
    else
      super
    end
  end
end

Instance Method Details

#respond_to?(method_name, include_priv = false) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/rails-settings/setting_object.rb', line 27

def respond_to?(method_name, include_priv=false)
  super || method_name.to_s =~ REGEX_SETTER || _setting?(method_name)
end