Class: Seedie::ModelFields
- Inherits:
-
Object
- Object
- Seedie::ModelFields
- Defined in:
- lib/seedie/model_fields.rb
Constant Summary collapse
- DEFAULT_DISABLED_FIELDS =
%w[id created_at updated_at].freeze
Instance Attribute Summary collapse
-
#disabled_fields ⇒ Object
readonly
Returns the value of attribute disabled_fields.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#foreign_fields ⇒ Object
readonly
Returns the value of attribute foreign_fields.
-
#model_config ⇒ Object
readonly
Returns the value of attribute model_config.
-
#model_name ⇒ Object
readonly
Returns the value of attribute model_name.
Instance Method Summary collapse
-
#initialize(model, model_config) ⇒ ModelFields
constructor
A new instance of ModelFields.
Constructor Details
#initialize(model, model_config) ⇒ ModelFields
Returns a new instance of ModelFields.
9 10 11 12 13 14 15 16 |
# File 'lib/seedie/model_fields.rb', line 9 def initialize(model, model_config) @model_name = model.to_s @model_config = model_config @custom_fields = model_config["attributes"]&.keys || [] @disabled_fields = [(model_config["disabled_fields"] || []) + DEFAULT_DISABLED_FIELDS].flatten.uniq @foreign_fields = model.reflect_on_all_associations(:belongs_to).map(&:foreign_key) @other_fields = model.column_names - @disabled_fields - @custom_fields - @foreign_fields end |
Instance Attribute Details
#disabled_fields ⇒ Object (readonly)
Returns the value of attribute disabled_fields.
7 8 9 |
# File 'lib/seedie/model_fields.rb', line 7 def disabled_fields @disabled_fields end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
7 8 9 |
# File 'lib/seedie/model_fields.rb', line 7 def fields @fields end |
#foreign_fields ⇒ Object (readonly)
Returns the value of attribute foreign_fields.
7 8 9 |
# File 'lib/seedie/model_fields.rb', line 7 def foreign_fields @foreign_fields end |
#model_config ⇒ Object (readonly)
Returns the value of attribute model_config.
7 8 9 |
# File 'lib/seedie/model_fields.rb', line 7 def model_config @model_config end |
#model_name ⇒ Object (readonly)
Returns the value of attribute model_name.
7 8 9 |
# File 'lib/seedie/model_fields.rb', line 7 def model_name @model_name end |