Sha256: d1a98754def46e3b6152765b2f981e9cdf1d1abfaf876d20faa9f60ba28a9e11

Contents?: true

Size: 1.19 KB

Versions: 13

Compression:

Stored size: 1.19 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
    __parent__.send(__name__) || 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

13 entries across 13 versions & 1 rubygems

Version Path
tengine_support-0.3.19 lib/tengine/support/config/definition/field.rb
tengine_support-0.3.18 lib/tengine/support/config/definition/field.rb
tengine_support-0.3.17 lib/tengine/support/config/definition/field.rb
tengine_support-0.3.16 lib/tengine/support/config/definition/field.rb
tengine_support-0.3.15 lib/tengine/support/config/definition/field.rb
tengine_support-0.3.14 lib/tengine/support/config/definition/field.rb
tengine_support-0.3.13 lib/tengine/support/config/definition/field.rb
tengine_support-0.3.12 lib/tengine/support/config/definition/field.rb
tengine_support-0.3.11 lib/tengine/support/config/definition/field.rb
tengine_support-0.3.10 lib/tengine/support/config/definition/field.rb
tengine_support-0.3.9 lib/tengine/support/config/definition/field.rb
tengine_support-0.3.8 lib/tengine/support/config/definition/field.rb
tengine_support-0.3.7 lib/tengine/support/config/definition/field.rb