Module: Ripple::AttributeMethods::InstanceMethods
- Defined in:
- lib/ripple/attribute_methods.rb
Instance Method Summary collapse
-
#attributes ⇒ Hash
A copy of the values of all attributes in the Document.
-
#attributes=(attrs, guard_protected_attrs = true) ⇒ Object
Mass assign the document’s attributes.
- #initialize(attrs = {}) {|_self| ... } ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to?(*args) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
89 90 91 92 |
# File 'lib/ripple/attribute_methods.rb', line 89 def method_missing(method, *args, &block) self.class.define_attribute_methods super end |
Instance Method Details
#attributes ⇒ Hash
A copy of the values of all attributes in the Document. The result is not memoized, so use sparingly. This does not include associated objects, nor embedded documents.
59 60 61 62 63 64 |
# File 'lib/ripple/attribute_methods.rb', line 59 def attributes self.class.properties.values.inject(@attributes.with_indifferent_access) do |hash, prop| hash[prop.key] = attribute(prop.key) hash end end |
#attributes=(attrs, guard_protected_attrs = true) ⇒ Object
Mass assign the document’s attributes.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ripple/attribute_methods.rb', line 68 def attributes=(attrs, guard_protected_attrs = true) raise ArgumentError, t('attribute_hash') unless Hash === attrs (guard_protected_attrs ? sanitize_for_mass_assignment(attrs) : attrs).each do |k,v| next if k.to_sym == :key if respond_to?("#{k}=") __send__("#{k}=",v) else __send__(:attribute=,k,v) end end end |
#initialize(attrs = {}) {|_self| ... } ⇒ Object
81 82 83 84 85 86 |
# File 'lib/ripple/attribute_methods.rb', line 81 def initialize(attrs={}) super() @attributes = attributes_from_property_defaults self.attributes = attrs yield self if block_given? end |
#respond_to?(*args) ⇒ Boolean
95 96 97 98 |
# File 'lib/ripple/attribute_methods.rb', line 95 def respond_to?(*args) self.class.define_attribute_methods super end |