Class: Svnx::Base::Options

Inherits:
Object
  • Object
show all
Includes:
Fields, Tags
Defined in:
lib/svnx/base/options.rb

Instance Method Summary collapse

Methods included from Fields

#assign, #create_invalid_fields_message, #fields, included, #validate

Methods included from Fields::ClassMethods

#attr_readers, #has_field, #has_fields

Methods included from Tags

included

Methods included from Tags::ClassMethods

#has, #has_tag_argument, #has_tag_field, #has_tags, #mapping, #to_tag

Constructor Details

#initialize(args) ⇒ Options

Returns a new instance of Options.



17
18
19
20
21
22
# File 'lib/svnx/base/options.rb', line 17

def initialize args
  fkeys = fields.keys
  
  assign args, fkeys
  validate args, fkeys
end

Instance Method Details

#get_args(field) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/svnx/base/options.rb', line 36

def get_args field
  val = fields[field]
  case val
  when Proc
    val.call self
  when nil
    send field
  else
    val
  end
end

#options_to_argsObject



24
25
26
27
28
# File 'lib/svnx/base/options.rb', line 24

def options_to_args
  fields.keys.collect do |fld|
    [ fld, get_args(fld) ]
  end
end

#to_argsObject



30
31
32
33
34
# File 'lib/svnx/base/options.rb', line 30

def to_args
  options_to_args.collect do |opt|
    send(opt.first) ? opt[1] : nil
  end.compact.flatten
end