Class: Subroutine::Factory::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/subroutine/factory/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Config

Returns a new instance of Config.



11
12
13
14
15
16
17
# File 'lib/subroutine/factory/config.rb', line 11

def initialize(options)
  @options = options || {}

  parent(@options.delete(:parent)) if @options[:parent]

  sanitize!
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/subroutine/factory/config.rb', line 9

def options
  @options
end

Instance Method Details

#after(&block) ⇒ Object



42
43
44
# File 'lib/subroutine/factory/config.rb', line 42

def after(&block)
  @options[:afters].push(block)
end

#before(&block) ⇒ Object



38
39
40
# File 'lib/subroutine/factory/config.rb', line 38

def before(&block)
  @options[:befores].push(block)
end

#input(name, value) ⇒ Object



46
47
48
# File 'lib/subroutine/factory/config.rb', line 46

def input(name, value)
  @options[:inputs][name.to_sym] = value
end

#op(op_class) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/subroutine/factory/config.rb', line 27

def op(op_class)
  @options[:op] = case op_class
  when String
    op_class
  when Class
    op_class.name
  else
    op_class.to_s
  end
end

#output(name) ⇒ Object



50
51
52
53
# File 'lib/subroutine/factory/config.rb', line 50

def output(name)
  @options.delete(:outputs)
  @options[:output] = name
end

#outputs(*names) ⇒ Object



55
56
57
58
# File 'lib/subroutine/factory/config.rb', line 55

def outputs(*names)
  @options.delete(:output)
  @options[:outputs] = names
end

#parent(parent) ⇒ Object



19
20
21
# File 'lib/subroutine/factory/config.rb', line 19

def parent(parent)
  inherit_from(parent)
end

#validate!Object



23
24
25
# File 'lib/subroutine/factory/config.rb', line 23

def validate!
  raise "Missing op configuration" unless @options[:op]
end