Module: DataGuru::Model
- Defined in:
- lib/data_guru/model.rb
Instance Attribute Summary collapse
-
#data_types ⇒ Object
readonly
Returns the value of attribute data_types.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#permitted_attributes ⇒ Object
readonly
Returns the value of attribute permitted_attributes.
-
#required_attributes ⇒ Object
readonly
Returns the value of attribute required_attributes.
Instance Method Summary collapse
- #attributes ⇒ Object
- #initialize(key, attrs, config, config_data) ⇒ Object
- #invalid_data_type_attributes ⇒ Object
- #missing_attributes ⇒ Object
- #valid? ⇒ Boolean
Instance Attribute Details
#data_types ⇒ Object (readonly)
Returns the value of attribute data_types.
3 4 5 |
# File 'lib/data_guru/model.rb', line 3 def data_types @data_types end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/data_guru/model.rb', line 3 def id @id end |
#permitted_attributes ⇒ Object (readonly)
Returns the value of attribute permitted_attributes.
3 4 5 |
# File 'lib/data_guru/model.rb', line 3 def permitted_attributes @permitted_attributes end |
#required_attributes ⇒ Object (readonly)
Returns the value of attribute required_attributes.
3 4 5 |
# File 'lib/data_guru/model.rb', line 3 def required_attributes @required_attributes end |
Instance Method Details
#attributes ⇒ Object
18 19 20 |
# File 'lib/data_guru/model.rb', line 18 def attributes @attributes ||= all_attributes end |
#initialize(key, attrs, config, config_data) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/data_guru/model.rb', line 5 def initialize(key, attrs, config, config_data) @id = key @permitted_attributes = config.permitted_attributes @required_attributes = config.required_attributes @data_types = config.data_types permitted_attributes.each do |attribute| set_attr_getter(attribute) default_value = config_data[attribute.to_s]["default_value"] set_attr_value(attribute, attrs[attribute.to_s], default_value) end end |
#invalid_data_type_attributes ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/data_guru/model.rb', line 30 def invalid_data_type_attributes data_types.map do |name, value| next if attributes[name].nil? if value == "boolean" name unless [true, false].include? attributes[name] else name unless attributes[name].class == value.classify.constantize end end .compact end |
#missing_attributes ⇒ Object
26 27 28 |
# File 'lib/data_guru/model.rb', line 26 def missing_attributes required_attributes - present_required_attributes end |
#valid? ⇒ Boolean
22 23 24 |
# File 'lib/data_guru/model.rb', line 22 def valid? missing_attributes.empty? && invalid_data_type_attributes.empty? end |