class HammerCLI::Output::Dsl
Public Class Methods
new(options={})
click to toggle source
# File lib/hammer_cli/output/dsl.rb, line 5 def initialize(options={}) @current_path = options[:path] || [] end
Public Instance Methods
build(&block)
click to toggle source
# File lib/hammer_cli/output/dsl.rb, line 14 def build(&block) self.instance_eval &block end
fields()
click to toggle source
# File lib/hammer_cli/output/dsl.rb, line 9 def fields @fields ||= [] @fields end
Protected Instance Methods
collection(key, label, options={}, &block)
click to toggle source
# File lib/hammer_cli/output/dsl.rb, line 47 def collection(key, label, options={}, &block) field key, label, Fields::Collection, options, &block end
current_path()
click to toggle source
# File lib/hammer_cli/output/dsl.rb, line 52 def current_path @current_path ||= [] @current_path end
custom_field(type, options={}, &block)
click to toggle source
# File lib/hammer_cli/output/dsl.rb, line 31 def custom_field(type, options={}, &block) self.fields << type.new(options, &block) end
field(key, label, type=nil, options={}, &block)
click to toggle source
# File lib/hammer_cli/output/dsl.rb, line 20 def field(key, label, type=nil, options={}, &block) options[:path] = current_path.clone unless key.nil? options[:path] << key options[:key] = key end options[:label] = label type ||= Fields::Field custom_field type, options, &block end
from(key) { || ... }
click to toggle source
# File lib/hammer_cli/output/dsl.rb, line 41 def from(key) self.current_path.push key yield if block_given? self.current_path.pop end
label(label, options={}, &block)
click to toggle source
# File lib/hammer_cli/output/dsl.rb, line 35 def label(label, options={}, &block) options[:path] = current_path.clone options[:label] = label custom_field Fields::Label, options, &block end