class Sunrise::Config::Field
Attributes
block[R]
Store form block
if_condition[R]
The condition that must be met on an object
unless_condition[R]
The condition that must not be met on an object
Public Class Methods
new(abstract_model, parent, options = {}, &block)
click to toggle source
Calls superclass method
Sunrise::Config::Base::new
# 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) # Build conditionals @if_condition = options.delete(:if) @unless_condition = options.delete(:unless) @block = block end
Public Instance Methods
association?()
click to toggle source
# File lib/sunrise/config/field.rb, line 54 def association? input_options[:association] === true end
block_given?()
click to toggle source
# File lib/sunrise/config/field.rb, line 30 def block_given? !block.nil? end
dom_id()
click to toggle source
# File lib/sunrise/config/field.rb, line 66 def dom_id @dom_id ||= "#{name}_field" end
html_options()
click to toggle source
# 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()
click to toggle source
# File lib/sunrise/config/field.rb, line 42 def human_name @config_options[:label] || abstract_model.model.human_attribute_name(@name) end
input_options()
click to toggle source
# File lib/sunrise/config/field.rb, line 38 def input_options @config_options.dup end
label?()
click to toggle source
# File lib/sunrise/config/field.rb, line 58 def label? @config_options[:label] != false end
nested?()
click to toggle source
# File lib/sunrise/config/field.rb, line 62 def nested? false end
visible?(object = nil)
click to toggle source
# File lib/sunrise/config/field.rb, line 34 def visible?(object = nil) object.nil? || matches_conditions?(object) end
Protected Instance Methods
matches_conditions?(object)
click to toggle source
Verifies that the conditionals for this field evaluate to true for the given object
# File lib/sunrise/config/field.rb, line 74 def matches_conditions?(object) return true if if_condition.nil? && unless_condition.nil? Array.wrap(if_condition).all? { |condition| evaluate_method(object, condition) } && Array.wrap(unless_condition).none? { |condition| evaluate_method(object, condition) } end