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.
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/sunrise/config/field.rb', line 19
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
17
18
19
|
# File 'lib/sunrise/config/field.rb', line 17
def block
@block
end
|
#if_condition ⇒ Object
The condition that must be met on an object
11
12
13
|
# File 'lib/sunrise/config/field.rb', line 11
def if_condition
@if_condition
end
|
#unless_condition ⇒ Object
The condition that must not be met on an object
14
15
16
|
# File 'lib/sunrise/config/field.rb', line 14
def unless_condition
@unless_condition
end
|
Instance Method Details
#association? ⇒ Boolean
54
55
56
|
# File 'lib/sunrise/config/field.rb', line 54
def association?
input_options[:association] === true
end
|
#block_given? ⇒ Boolean
30
31
32
|
# File 'lib/sunrise/config/field.rb', line 30
def block_given?
!block.nil?
end
|
#dom_id ⇒ Object
66
67
68
|
# File 'lib/sunrise/config/field.rb', line 66
def dom_id
@dom_id ||= "#{name}_field"
end
|
#html_options ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/sunrise/config/field.rb', line 46
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
42
43
44
|
# File 'lib/sunrise/config/field.rb', line 42
def human_name
@config_options[:label] || abstract_model.model.human_attribute_name(@name)
end
|
38
39
40
|
# File 'lib/sunrise/config/field.rb', line 38
def input_options
@config_options.dup
end
|
#label? ⇒ Boolean
58
59
60
|
# File 'lib/sunrise/config/field.rb', line 58
def label?
@config_options[:label] != false
end
|
#nested? ⇒ Boolean
62
63
64
|
# File 'lib/sunrise/config/field.rb', line 62
def nested?
false
end
|
#visible?(object = nil) ⇒ Boolean
34
35
36
|
# File 'lib/sunrise/config/field.rb', line 34
def visible?(object = nil)
object.nil? || matches_conditions?(object)
end
|