Class: Databasium::Model::ModelData
- Inherits:
-
Object
- Object
- Databasium::Model::ModelData
- Defined in:
- app/services/databasium/model.rb
Defined Under Namespace
Classes: Attribute, Validation
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#model_name ⇒ Object
readonly
Returns the value of attribute model_name.
-
#relations ⇒ Object
readonly
Returns the value of attribute relations.
-
#unknown ⇒ Object
readonly
Returns the value of attribute unknown.
Instance Method Summary collapse
- #get_binding ⇒ Object
-
#initialize(model_name:, attributes:, relations:, unknown: []) ⇒ ModelData
constructor
A new instance of ModelData.
- #longest_name_length ⇒ Object
- #relation_name(relation) ⇒ Object
Constructor Details
#initialize(model_name:, attributes:, relations:, unknown: []) ⇒ ModelData
Returns a new instance of ModelData.
98 99 100 101 102 103 |
# File 'app/services/databasium/model.rb', line 98 def initialize(model_name:, attributes:, relations:, unknown: []) @model_name = model_name @attributes = attributes @relations = relations @unknown = unknown end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
96 97 98 |
# File 'app/services/databasium/model.rb', line 96 def attributes @attributes end |
#model_name ⇒ Object (readonly)
Returns the value of attribute model_name.
96 97 98 |
# File 'app/services/databasium/model.rb', line 96 def model_name @model_name end |
#relations ⇒ Object (readonly)
Returns the value of attribute relations.
96 97 98 |
# File 'app/services/databasium/model.rb', line 96 def relations @relations end |
#unknown ⇒ Object (readonly)
Returns the value of attribute unknown.
96 97 98 |
# File 'app/services/databasium/model.rb', line 96 def unknown @unknown end |
Instance Method Details
#get_binding ⇒ Object
105 106 107 |
# File 'app/services/databasium/model.rb', line 105 def get_binding binding end |
#longest_name_length ⇒ Object
109 110 111 |
# File 'app/services/databasium/model.rb', line 109 def longest_name_length attributes.map { |a| (a[:name] || a["name"]).to_s.length }.max || 0 end |
#relation_name(relation) ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'app/services/databasium/model.rb', line 113 def relation_name(relation) table_name = relation[:table_name].to_s case relation[:type] when "has_many", "has_and_belongs_to_many" table_name.tableize when "belongs_to", "has_one" table_name.singularize.underscore end end |