Class: DynamicScaffold::List::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamic_scaffold/list/item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.extract_options!
  @classnames = @html_attributes.delete(:class)
  @attribute_name = args[0]
  @block = block
  @show_only = nil
end

Instance Attribute Details

#classnamesObject (readonly)

Returns the value of attribute classnames.



6
7
8
# File 'lib/dynamic_scaffold/list/item.rb', line 6

def classnames
  @classnames
end

#html_attributesObject (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

Returns:

  • (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