Class: Devlin::Column
- Inherits:
-
Object
- Object
- Devlin::Column
- Defined in:
- lib/devlin/column.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #arguments ⇒ Object
- #definition ⇒ Object
- #human_attribute_name ⇒ Object
-
#initialize(name, config, *args) ⇒ Column
constructor
A new instance of Column.
- #select_definition ⇒ Object
- #value(value) ⇒ Object
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. end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/devlin/column.rb', line 3 def config @config end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/devlin/column.rb', line 3 def name @name end |
Instance Method Details
#arguments ⇒ Object
31 32 33 |
# File 'lib/devlin/column.rb', line 31 def arguments @arguments end |
#definition ⇒ Object
15 16 17 |
# File 'lib/devlin/column.rb', line 15 def definition @config[:definition] end |
#human_attribute_name ⇒ Object
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_definition ⇒ Object
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 |