Class: DynamicScaffold::List::Item
- Inherits:
-
Object
- Object
- DynamicScaffold::List::Item
- Defined in:
- lib/dynamic_scaffold/list/item.rb
Instance Attribute Summary collapse
-
#classnames ⇒ Object
readonly
Returns the value of attribute classnames.
-
#html_attributes ⇒ Object
readonly
Returns the value of attribute html_attributes.
Instance Method Summary collapse
-
#initialize(config, *args, block) ⇒ Item
constructor
A new instance of Item.
- #label(label = nil) ⇒ Object
- #show?(view, record) ⇒ Boolean
- #show_only(&block) ⇒ Object
- #value(view, record) ⇒ Object
Constructor Details
#initialize(config, *args, block) ⇒ Item
Returns a new instance of Item.
8 9 10 11 12 13 14 15 |
# File 'lib/dynamic_scaffold/list/item.rb', line 8 def initialize(config, *args, block) @config = config @html_attributes = args. @classnames = @html_attributes.delete(:class) @attribute_name = args[0] @block = block @show_only = nil end |
Instance Attribute Details
#classnames ⇒ Object (readonly)
Returns the value of attribute classnames.
6 7 8 |
# File 'lib/dynamic_scaffold/list/item.rb', line 6 def classnames @classnames end |
#html_attributes ⇒ Object (readonly)
Returns the value of attribute html_attributes.
6 7 8 |
# File 'lib/dynamic_scaffold/list/item.rb', line 6 def html_attributes @html_attributes end |
Instance Method Details
#label(label = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dynamic_scaffold/list/item.rb', line 36 def label(label = nil) if label @label = label self elsif @label @label elsif @attribute_name @config.model.human_attribute_name @attribute_name end end |
#show?(view, record) ⇒ Boolean
22 23 24 25 26 |
# File 'lib/dynamic_scaffold/list/item.rb', line 22 def show?(view, record) return true if @show_only.nil? view.instance_exec(record, &@show_only) end |
#show_only(&block) ⇒ Object
17 18 19 20 |
# File 'lib/dynamic_scaffold/list/item.rb', line 17 def show_only(&block) @show_only = block self end |
#value(view, record) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/dynamic_scaffold/list/item.rb', line 28 def value(view, record) if @block view.instance_exec(record, @attribute_name, &@block) else record.public_send(@attribute_name) end end |