Module: Mince::Model::Fields
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/mince/model/fields.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#attributes=(hash = {}) ⇒ Object
Sets values (for assignable fields only, defined by calling .field or .fields) in the hash to the object.
-
#initialize(hash = {}) ⇒ Object
Sets values (for fields defined by calling .field or .fields) in the hash to the object includes assignable and non-assignable fields.
Instance Method Details
#attributes=(hash = {}) ⇒ Object
Sets values (for assignable fields only, defined by calling .field or .fields) in the hash to the object.
Allows the proxy to have whitelisted attributes to be assigned from http requests.
82 83 84 85 86 |
# File 'lib/mince/model/fields.rb', line 82 def attributes=(hash={}) assignable_fields.each do |field| send("#{field}=", hash[field]) if hash[field] end end |
#initialize(hash = {}) ⇒ Object
Sets values (for fields defined by calling .field or .fields) in the hash to the object includes assignable and non-assignable fields
70 71 72 73 74 75 76 |
# File 'lib/mince/model/fields.rb', line 70 def initialize(hash={}) @id = hash[:id] readonly_fields.each do |field_name| self.instance_variable_set("@#{field_name}", hash[field_name]) if hash[field_name] end self.attributes = hash end |