Class: Devlin::Column

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, config, *args) ⇒ Column

Returns a new instance of Column.



5
6
7
8
9
# File 'lib/devlin/column.rb', line 5

def initialize(name, config, *args)
  @name = name
  @config = config
  @arguments = args.extract_options!
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/devlin/column.rb', line 3

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/devlin/column.rb', line 3

def name
  @name
end

Instance Method Details

#argumentsObject



31
32
33
# File 'lib/devlin/column.rb', line 31

def arguments
  @arguments
end

#definitionObject



15
16
17
# File 'lib/devlin/column.rb', line 15

def definition
  @config[:definition]
end

#human_attribute_nameObject



27
28
29
# File 'lib/devlin/column.rb', line 27

def human_attribute_name
  I18n.t(self.name, scope: [:devlin, config[:scope].name], default: self.name.capitalize)
end

#select_definitionObject



11
12
13
# File 'lib/devlin/column.rb', line 11

def select_definition
  "#{@config[:definition]} AS #{@name}"
end

#value(value) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/devlin/column.rb', line 19

def value(value)
  if @config[:getter].respond_to?(:call)
    @config[:getter].call(value)
  else
    value
  end
end