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.
102 103 104 105 106 107 |
# File 'app/services/databasium/model.rb', line 102 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.
100 101 102 |
# File 'app/services/databasium/model.rb', line 100 def attributes @attributes end |
#model_name ⇒ Object (readonly)
Returns the value of attribute model_name.
100 101 102 |
# File 'app/services/databasium/model.rb', line 100 def model_name @model_name end |
#relations ⇒ Object (readonly)
Returns the value of attribute relations.
100 101 102 |
# File 'app/services/databasium/model.rb', line 100 def relations @relations end |
#unknown ⇒ Object (readonly)
Returns the value of attribute unknown.
100 101 102 |
# File 'app/services/databasium/model.rb', line 100 def unknown @unknown end |
Instance Method Details
#get_binding ⇒ Object
109 110 111 |
# File 'app/services/databasium/model.rb', line 109 def get_binding binding end |
#longest_name_length ⇒ Object
113 114 115 |
# File 'app/services/databasium/model.rb', line 113 def longest_name_length attributes.map { |a| (a[:name] || a["name"]).to_s.length }.max || 0 end |
#relation_name(relation) ⇒ Object
117 118 119 120 121 122 123 124 125 126 |
# File 'app/services/databasium/model.rb', line 117 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 |