Class: Flattener::Attribute

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, Utils
Defined in:
lib/has_helpers/flattener/attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#combine_names, #underscore_type

Instance Attribute Details

#columnObject

Returns the value of attribute column.



9
10
11
# File 'lib/has_helpers/flattener/attribute.rb', line 9

def column
  @column
end

#resourceObject

Returns the value of attribute resource.



9
10
11
# File 'lib/has_helpers/flattener/attribute.rb', line 9

def resource
  @resource
end

Instance Method Details

#column_associationObject



34
35
36
# File 'lib/has_helpers/flattener/attribute.rb', line 34

def column_association
  @column_association ||= column.association
end

#column_association_nameObject



38
39
40
# File 'lib/has_helpers/flattener/attribute.rb', line 38

def column_association_name
  column_association && combine_names(resource.name, column_association.name)
end

#column_nameObject



16
17
18
19
# File 'lib/has_helpers/flattener/attribute.rb', line 16

def column_name
  column_name = column.name.dup unless column.name == "name" && (column.klass.include?(HasHelpers::Constant) || resource.parent.present?)
  column_name
end

#editable?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/has_helpers/flattener/attribute.rb', line 26

def editable?
  [is_primary_key?, resource.is_constant?].uniq == [false]
end

#keyObject

TODO: not finished



22
23
24
# File 'lib/has_helpers/flattener/attribute.rb', line 22

def key
  "#{resource.prefix}[#{column.name}]"
end

#nameObject



12
13
14
# File 'lib/has_helpers/flattener/attribute.rb', line 12

def name
  combine_names(resource.name, column.alias_name || column_name)
end

#to_hObject



30
31
32
# File 'lib/has_helpers/flattener/attribute.rb', line 30

def to_h
  { name: name, key: key, type: column.sql_type, percent: column.is_percent?, currency: column.is_currency?, editable: editable? }
end