Class: RFlow::Configuration::RubyDSL
- Inherits:
-
Object
- Object
- RFlow::Configuration::RubyDSL
- Defined in:
- lib/rflow/configuration/ruby_dsl.rb
Overview
Ruby DSL config file controller. TODO: more docs and examples
Class Method Summary collapse
-
.configure {|config_file| ... } ⇒ Object
Method called within the config file itself.
Instance Method Summary collapse
-
#component(name, specification, options = {}) ⇒ Object
DSL method to specify a component.
-
#connect(hash) ⇒ Object
DSL method to specify a connection between a component/output_port and another component/input_port.
-
#initialize ⇒ RubyDSL
constructor
A new instance of RubyDSL.
-
#process(name, options = {}, &block) ⇒ Object
shortcut.
-
#process_objects ⇒ Object
Method to process the ‘DSL’ objects into the config database via ActiveRecord.
-
#setting(name, value) ⇒ Object
DSL method to specify a name/value pair.
-
#shard(name, options = {}) {|_self| ... } ⇒ Object
DSL method to specify a shard block for either a process or thread.
-
#thread(name, options = {}, &block) ⇒ Object
shortcut.
Constructor Details
#initialize ⇒ RubyDSL
Returns a new instance of RubyDSL.
12 13 14 15 16 17 18 19 |
# File 'lib/rflow/configuration/ruby_dsl.rb', line 12 def initialize @default_shard = {:name => 'DEFAULT', :type => :process, :count => 1, :components => []} @current_shard = default_shard @setting_specs = [] @shard_specs = [default_shard] @connection_specs = [] end |
Class Method Details
.configure {|config_file| ... } ⇒ Object
Method called within the config file itself
97 98 99 100 101 |
# File 'lib/rflow/configuration/ruby_dsl.rb', line 97 def self.configure config_file = self.new yield config_file config_file.process_objects end |
Instance Method Details
#component(name, specification, options = {}) ⇒ Object
DSL method to specify a component. Expects a name, specification, and set of component specific options, that must be marshallable into the database (i.e. should all be strings)
58 59 60 61 62 63 64 |
# File 'lib/rflow/configuration/ruby_dsl.rb', line 58 def component(name, specification, = {}) @current_shard[:components] << { :name => name, :specification => specification.to_s, :options => , :config_line => get_config_line(caller) } end |
#connect(hash) ⇒ Object
DSL method to specify a connection between a component/output_port and another component/input_port. The component/port specification is a string where the names of the two elements are separated by ‘#’, and the ‘connection’ is specified by a Ruby Hash, i.e.:
connect 'componentA#output' => 'componentB#input'
Array ports are specified with an key suffix in standard progamming syntax, i.e.
connect 'componentA#arrayport[2]' => 'componentB#in[1]'
Uses the model to assign random UUIDs
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rflow/configuration/ruby_dsl.rb', line 76 def connect(hash) delivery = hash[:delivery] || 'round-robin' hash.except(:delivery).each do |output_string, input_string| output_component_name, output_port_name, output_port_key = parse_connection_string(output_string) input_component_name, input_port_name, input_port_key = parse_connection_string(input_string) connection_specs << { :name => output_string + '=>' + input_string, :delivery => delivery, :output_component_name => output_component_name, :output_port_name => output_port_name, :output_port_key => output_port_key, :output_string => output_string, :input_component_name => input_component_name, :input_port_name => input_port_name, :input_port_key => input_port_key, :input_string => input_string, :config_line => get_config_line(caller) } end end |
#process(name, options = {}, &block) ⇒ Object
shortcut
46 47 48 |
# File 'lib/rflow/configuration/ruby_dsl.rb', line 46 def process(name, = {}, &block) shard(name, .merge(:type => :process), &block) end |
#process_objects ⇒ Object
Method to process the ‘DSL’ objects into the config database via ActiveRecord
105 106 107 108 109 |
# File 'lib/rflow/configuration/ruby_dsl.rb', line 105 def process_objects process_setting_specs process_shard_specs process_connection_specs end |
#setting(name, value) ⇒ Object
DSL method to specify a name/value pair. RFlow core uses the ‘rflow.’ prefix on all of its settings. Custom settings should use a custom (unique) prefix
24 25 26 |
# File 'lib/rflow/configuration/ruby_dsl.rb', line 24 def setting(name, value) setting_specs << {:name => name.to_s, :value => value.to_s, :config_line => get_config_line(caller)} end |
#shard(name, options = {}) {|_self| ... } ⇒ Object
DSL method to specify a shard block for either a process or thread
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rflow/configuration/ruby_dsl.rb', line 29 def shard(name, = {}) raise ArgumentError, 'Cannot use DEFAULT as a shard name' if name == 'DEFAULT' raise ArgumentError, 'Cannot nest shards' if @current_shard != default_shard type = if [:thread] || [:type] == :thread; :thread else :process end count = [type] || [:count] || 1 @current_shard = {:name => name, :type => type, :count => count, :components => [], :config_line => get_config_line(caller)} shard_specs << @current_shard yield self @current_shard = default_shard end |
#thread(name, options = {}, &block) ⇒ Object
shortcut
51 52 53 |
# File 'lib/rflow/configuration/ruby_dsl.rb', line 51 def thread(name, = {}, &block) shard(name, .merge(:type => :thread), &block) end |