Class: Main::Program::ClassMethods::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/main/program/class_methods.rb

Instance Method Summary (collapse)

Constructor Details

- (Factory) initialize(&block)

Returns a new instance of Factory



43
44
45
# File 'lib/main/program/class_methods.rb', line 43

def initialize(&block)
  @block = block || lambda{}
end

Instance Method Details

- (Object) build(*args, &block)



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/main/program/class_methods.rb', line 51

def build(*args, &block)
  argv = (args.shift || ARGV).map{|arg| arg.dup}
  env = (args.shift || ENV).to_hash.dup
  opts = (args.shift || {}).to_hash.dup

  factory = self

  program = Class.new(Program)

  program.factory = factory
  program.argv = argv
  program.env = env
  program.opts = opts

  program.module_eval(&factory)

  program.module_eval do
    dynamically_extend_via_commandline_modes!
    program.set_default_options!
    define_method(:run, &block) if block
    wrap_run!
  end
  program
end

- (Object) to_proc



47
48
49
# File 'lib/main/program/class_methods.rb', line 47

def to_proc
  @block
end