Class: Sunrise::Config::Field
Instance Attribute Summary collapse
Attributes inherited from Base
#abstract_model, #name, #parent
Instance Method Summary
collapse
#evaluate_method
Methods inherited from Base
register_class_option, register_instance_option, #register_instance_option
Constructor Details
#initialize(abstract_model, parent, options = {}, &block) ⇒ Field
Returns a new instance of Field.
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/sunrise/config/field.rb', line 17
def initialize(abstract_model, parent, options = {}, &block)
options = {:multiply => false, :sort => false}.merge(options)
super(abstract_model, parent, options)
@if_condition = options.delete(:if)
@unless_condition = options.delete(:unless)
@block = block
end
|
Instance Attribute Details
#block ⇒ Object
15
16
17
|
# File 'lib/sunrise/config/field.rb', line 15
def block
@block
end
|
#if_condition ⇒ Object
The condition that must be met on an object
9
10
11
|
# File 'lib/sunrise/config/field.rb', line 9
def if_condition
@if_condition
end
|
#unless_condition ⇒ Object
The condition that must not be met on an object
12
13
14
|
# File 'lib/sunrise/config/field.rb', line 12
def unless_condition
@unless_condition
end
|
Instance Method Details
#association? ⇒ Boolean
52
53
54
|
# File 'lib/sunrise/config/field.rb', line 52
def association?
input_options[:association] === true
end
|
#block_given? ⇒ Boolean
28
29
30
|
# File 'lib/sunrise/config/field.rb', line 28
def block_given?
!block.nil?
end
|
#dom_id ⇒ Object
64
65
66
|
# File 'lib/sunrise/config/field.rb', line 64
def dom_id
@dom_id ||= "#{name}_field"
end
|
#html_options ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/sunrise/config/field.rb', line 44
def html_options
css = ["padder"]
css << "grey-but" if input_options[:boolean]
css << "tags-edit" if association?
{:class => css, :id => dom_id}.merge(input_options[:html] || {})
end
|
#human_name ⇒ Object
40
41
42
|
# File 'lib/sunrise/config/field.rb', line 40
def human_name
@config_options[:label] || abstract_model.model.human_attribute_name(@name)
end
|
36
37
38
|
# File 'lib/sunrise/config/field.rb', line 36
def input_options
@config_options.dup
end
|
#label? ⇒ Boolean
56
57
58
|
# File 'lib/sunrise/config/field.rb', line 56
def label?
@config_options[:label] != false
end
|
#nested? ⇒ Boolean
60
61
62
|
# File 'lib/sunrise/config/field.rb', line 60
def nested?
false
end
|
#visible?(object = nil) ⇒ Boolean
32
33
34
|
# File 'lib/sunrise/config/field.rb', line 32
def visible?(object = nil)
object.nil? || matches_conditions?(object)
end
|