Class: Seedie::ModelFields

Inherits:
Object
  • Object
show all
Defined in:
lib/seedie/model_fields.rb

Constant Summary collapse

DEFAULT_DISABLED_FIELDS =
%w[id created_at updated_at].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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_fieldsObject (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

#fieldsObject (readonly)

Returns the value of attribute fields.



7
8
9
# File 'lib/seedie/model_fields.rb', line 7

def fields
  @fields
end

#foreign_fieldsObject (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_configObject (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_nameObject (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