Sha256: ccf524cc1077210ab55a7f2c698a9a21bed89f0bdcdd9a6cb0fd11be970b3e40
Contents?: true
Size: 1.7 KB
Versions: 1
Compression:
Stored size: 1.7 KB
Contents
require 'sunrise/config/base' module Sunrise module Config class Field < Base include Sunrise::Utils::EvalHelpers # The condition that must be met on an object attr_reader :if_condition # The condition that must *not* be met on an object attr_reader :unless_condition def initialize(abstract_model, parent, options = {}) super(abstract_model, parent, options) # Build conditionals @if_condition = options.delete(:if) @unless_condition = options.delete(:unless) end def visible?(object = nil) object.nil? || matches_conditions?(object) end def input_options @config_options.dup end def human_name @config_options[:label] || abstract_model.model.human_attribute_name(@name) end def html_options css = ["padder"] css << "grey-but" if input_options[:boolean] css << "tags-edit" if association? { :class => css.join(' ') } end def association? input_options[:association] === true end def label? @config_options[:label] != false end def nested? false end protected # Verifies that the conditionals for this field evaluate to true for the # given object 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).any? {|condition| evaluate_method(object, condition)} end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sunrise-cms-0.4.2 | lib/sunrise/config/field.rb |