class RailsProperties::PropertyObject
Constants
- REGEX_GETTER
- REGEX_SETTER
Public Instance Methods
method_missing(method_name, *args, &block)
click to toggle source
Calls superclass method
# File lib/rails-properties/property_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
respond_to?(method_name, include_priv=false)
click to toggle source
Calls superclass method
# File lib/rails-properties/property_object.rb, line 27 def respond_to?(method_name, include_priv=false) super || method_name.to_s =~ REGEX_SETTER || _property?(method_name) end
Protected Instance Methods
sanitize_for_mass_assignment(attributes, role = nil)
click to toggle source
Simulate attr_protected by removing all regular attributes
# File lib/rails-properties/property_object.rb, line 50 def sanitize_for_mass_assignment(attributes, role = nil) attributes.except('id', 'var', 'value', 'target_id', 'target_type', 'created_at', 'updated_at') end
Private Instance Methods
_get_value(name)
click to toggle source
# File lib/rails-properties/property_object.rb, line 56 def _get_value(name) if value[name].nil? _target_class.default_properties[var.to_sym][name] else value[name] end end
_property?(method_name)
click to toggle source
# File lib/rails-properties/property_object.rb, line 80 def _property?(method_name) _target_class.default_properties[var.to_sym].keys.include?(method_name.to_s) end
_set_value(name, v)
click to toggle source
# File lib/rails-properties/property_object.rb, line 64 def _set_value(name, v) if value[name] != v value_will_change! if v.nil? value.delete(name) else value[name] = v end end end
_target_class()
click to toggle source
# File lib/rails-properties/property_object.rb, line 76 def _target_class target_type.constantize end