Sha256: cd41a4966a248e2dbfd3e5c53f6a33c6956b61c2ad48700bd741bf057e048682

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

require 'tengine/support/config/definition'

class Tengine::Support::Config::Definition::Field
  attr_accessor :__name__, :__parent__, :__block__, :__type__
  attr_accessor :type, :default_description, :default, :description, :hidden
  def initialize(attrs = {})
    attrs.each{|k, v| send("#{k}=", v)}
  end

  def field?; @__type__ == :field; end
  def action?; @__type__ == :action; end
  def separator?; @__type__ == :separator; end

  def hidden?; !!self.hidden; end

  def update(attrs)
    attrs.each{|k, v| send("#{k}=", v)}
  end

  def description_value
    [
      __parent__.get_value(description),
      __parent__.get_value(default_description)
    ].join(' ')
  end

  def default_value
    default.respond_to?(:to_proc) ? __parent__.instance_eval(&default) : default
  end

  def to_hash
    default_value
  end

  def accept_visitor(visitor)
    visitor.visit(self)
  end

  def name_array
    (__parent__ ? __parent__.name_array : []) + [__name__]
  end

  def root
    __parent__ ? __parent__.root : nil
  end

  def short_opt
    r = root.mapping[ name_array ]
    r ? "-#{r}" : nil
  end

  def long_opt
    '--' << name_array.join('-').gsub(%r{_}, '-')
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tengine_support-0.3.6 lib/tengine/support/config/definition/field.rb
tengine_support-0.3.5 lib/tengine/support/config/definition/field.rb
tengine_support-0.3.4 lib/tengine/support/config/definition/field.rb