Module: Goods::Containable
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/goods/containable.rb', line 3 def self.included(base) # Class macro that defined mathod to access instance variable @field_name # in the following way (illustrative example) # # def field_name # @field_name ||= description[field_name] # end base.define_singleton_method :attr_field do |field_name| define_method field_name do if field = instance_variable_get("@#{field_name}") field else instance_variable_set("@#{field_name}", _info_hash[field_name]) instance_variable_get("@#{field_name}") end end end end |
Instance Method Details
#id ⇒ Object
27 28 29 |
# File 'lib/goods/containable.rb', line 27 def id @id ||= _info_hash[:id] end |
#invalid_fields ⇒ Object
31 32 33 |
# File 'lib/goods/containable.rb', line 31 def invalid_fields @invalid_fields ||= [] end |
#valid? ⇒ Boolean
35 36 37 38 39 |
# File 'lib/goods/containable.rb', line 35 def valid? reset_validation apply_validation_rules invalid_fields.empty? end |