Class: CmAdmin::Models::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/cm_admin/models/column.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field_name, attributes = {}) ⇒ Column

Returns a new instance of Column.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cm_admin/models/column.rb', line 7

def initialize(field_name, attributes = {})
  @field_name = field_name
  set_default_values
  attributes.each do |key, value|
    self.send("#{key.to_s}=", value)
  end

  #formatting header (either field_name or value present in header attribute)
  self.send("header=", format_header)
  self.height = 50 if self.field_type == :image && self.height.nil?
  self.width = 50 if self.field_type == :image && self.width.nil?
  self.display_if = lambda { |arg| return true } if self.display_if.nil?
end

Instance Attribute Details

#cm_css_classObject

Returns the value of attribute cm_css_class.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def cm_css_class
  @cm_css_class
end

#custom_methodObject

Returns the value of attribute custom_method.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def custom_method
  @custom_method
end

#display_ifObject

Returns the value of attribute display_if.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def display_if
  @display_if
end

#drawer_partialObject

Returns the value of attribute drawer_partial.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def drawer_partial
  @drawer_partial
end

#exportableObject

Returns the value of attribute exportable.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def exportable
  @exportable
end

#field_nameObject

Returns the value of attribute field_name.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def field_name
  @field_name
end

#field_typeObject

Returns the value of attribute field_type.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def field_type
  @field_type
end

#formatObject

Returns the value of attribute format.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def format
  @format
end

#headerObject

Returns the value of attribute header.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def header
  @header
end

#heightObject

Returns the value of attribute height.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def height
  @height
end

#helper_methodObject

Returns the value of attribute helper_method.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def helper_method
  @helper_method
end

Returns the value of attribute link.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def link
  @link
end

#lockableObject

Returns the value of attribute lockable.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def lockable
  @lockable
end

#managableObject

Returns the value of attribute managable.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def managable
  @managable
end

#prefixObject

Returns the value of attribute prefix.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def prefix
  @prefix
end

#roundObject

Returns the value of attribute round.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def round
  @round
end

#suffixObject

Returns the value of attribute suffix.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def suffix
  @suffix
end

#tag_classObject

Returns the value of attribute tag_class.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def tag_class
  @tag_class
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def url
  @url
end

#widthObject

Returns the value of attribute width.



4
5
6
# File 'lib/cm_admin/models/column.rb', line 4

def width
  @width
end

Class Method Details

.find_by(model, search_hash) ⇒ Object



34
35
36
# File 'lib/cm_admin/models/column.rb', line 34

def find_by(model, search_hash)
  model.available_fields.find { |i| i.name == search_hash[:name] }
end

Instance Method Details

#format_headerObject

returns a string value as a header (either field_name or value present in header attribute)



22
23
24
# File 'lib/cm_admin/models/column.rb', line 22

def format_header
  self.header.present? ? self.header.to_s.gsub(/_/, ' ')&.upcase : self.field_name.to_s.gsub(/_/, ' ').upcase
end

#set_default_valuesObject



26
27
28
29
30
31
# File 'lib/cm_admin/models/column.rb', line 26

def set_default_values
  self.exportable = true
  self.managable = true
  self.lockable = false
  self.tag_class = {}
end