Sha256: 12740e24db49e96b0cb8abcf04ce9967b2ccafe076e60ba49abeb301f224d231

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

class HungryForm
  class BaseElement
    attr_accessor :name, :placeholders, :resolver, :visible, :label, :dependency
    alias_method :visible?, :visible

    def initialize(name, parent, resolver, options = {})
      @_options = options

      @placeholders ||= {}
      @resolver = resolver

      # The element is visible if no visible parameter passed or
      # visible param equals true and the dependency is resolved positively
      self.visible = options.has_key?(:visible)? options[:visible] : true
      self.visible &&= resolver.resolve_dependency(::JSON.parse(options[:dependency])) if options[:dependency]
      self.dependency = options[:dependency] || ''
      self.name = (parent.nil?? "" : "#{parent.name}_") + resolver.get_value(name, self)

      unless options[:label]
        self.label = resolver.get_value(name, self).humanize
      else
        self.label = resolver.get_value(options[:label], self)
      end
    end

    def method_missing(name, *args, &block)
      # Check if an option exists
      return @_options.has_key?(name.to_s[0..-2].to_sym) if name.to_s[-1] == '?'
      # Return an option
      return @_options[name] if @_options.has_key?(name)
      super
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hungryform-0.0.2 lib/hungryform/elements/base_element.rb