Class: Svnx::Base::Options

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ObjectUtil

#assign, #create_invalid_fields_message, included, #validate

Methods included from ObjectUtil::ClassMethods

#attr_readers, #xhas_fields

Constructor Details

#initialize(args) ⇒ Options

Returns a new instance of Options.



32
33
34
35
36
# File 'lib/svnx/base/options.rb', line 32

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

Class Method Details

.has_fields(*fields) ⇒ Object

Creates a reader method for each field



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

def has_fields(*fields)
  what = Array(fields).flatten
  attr_reader(*what)
end

Instance Method Details

#fieldsObject



44
45
46
# File 'lib/svnx/base/options.rb', line 44

def fields
  raise "not implemented for #{self.class}"
end

#get_args(field) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/svnx/base/options.rb', line 54

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



38
39
40
41
42
# File 'lib/svnx/base/options.rb', line 38

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

#to_argsObject



48
49
50
51
52
# File 'lib/svnx/base/options.rb', line 48

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