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.
6 7 8 9 10 11 12 13 |
# File 'lib/dynamic_scaffold/list/item.rb', line 6 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.
4 5 6 |
# File 'lib/dynamic_scaffold/list/item.rb', line 4 def classnames @classnames end |
#html_attributes ⇒ Object (readonly)
Returns the value of attribute html_attributes.
4 5 6 |
# File 'lib/dynamic_scaffold/list/item.rb', line 4 def html_attributes @html_attributes end |
Instance Method Details
#label(label = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dynamic_scaffold/list/item.rb', line 34 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
20 21 22 23 24 |
# File 'lib/dynamic_scaffold/list/item.rb', line 20 def show?(view, record) return true if @show_only.nil? view.instance_exec(record, &@show_only) end |
#show_only(&block) ⇒ Object
15 16 17 18 |
# File 'lib/dynamic_scaffold/list/item.rb', line 15 def show_only(&block) @show_only = block self end |
#value(view, record) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/dynamic_scaffold/list/item.rb', line 26 def value(view, record) if @block view.instance_exec(record, @attribute_name, &@block) else record.public_send(@attribute_name) end end |