Class: HashAttributeAssignment::HashAttributeAssignor
- Inherits:
-
Object
- Object
- HashAttributeAssignment::HashAttributeAssignor
- Defined in:
- lib/hash_attribute_assignment.rb
Instance Method Summary collapse
- #assign ⇒ Object
-
#initialize(instance, hash = {}) ⇒ HashAttributeAssignor
constructor
A new instance of HashAttributeAssignor.
Constructor Details
#initialize(instance, hash = {}) ⇒ HashAttributeAssignor
Returns a new instance of HashAttributeAssignor.
18 19 20 21 22 23 |
# File 'lib/hash_attribute_assignment.rb', line 18 def initialize(instance, hash = {}) @hash = hash @klass = instance.class @instance = instance @hash_validations = klass.class_variable_get(:@@hash_validations) end |
Instance Method Details
#assign ⇒ Object
25 26 27 28 29 30 |
# File 'lib/hash_attribute_assignment.rb', line 25 def assign check_required_keys if klass.const_defined?(:REQUIRED_KEYS) merge_default_hash! if klass.const_defined?(:DEFAULT_HASH) validate_hash! assign_asstributes end |