lib/rflow/configuration/connection.rb in rflow-1.0.0a1 vs lib/rflow/configuration/connection.rb in rflow-1.0.0a2

- old
+ new

@@ -1,11 +1,11 @@ require 'active_record' require 'rflow/configuration/uuid_keyed' class RFlow class Configuration - class Connection < ConfigDB + class Connection < ConfigurationItem class ConnectionInvalid < StandardError; end include UUIDKeyed include ActiveModel::Validations @@ -17,64 +17,55 @@ before_create :merge_default_options! validates_uniqueness_of :uuid validates_presence_of :output_port_uuid, :input_port_uuid - validate :all_required_options_present + validate :all_required_options_present? - - def all_required_options_present + def all_required_options_present? self.class.required_options.each do |option_name| unless self.options.include? option_name.to_s errors.add(:options, "must include #{option_name} for #{self.class.to_s}") end end end - def merge_default_options! self.options ||= {} - self.class.default_options.each do |option_name, default_value_or_proc| - self.options[option_name.to_s] ||= default_value_or_proc.is_a?(Proc) ? default_value_or_proc.call(self) : default_value_or_proc + self.class.default_options.each do |name, default_value_or_proc| + self.options[name.to_s] ||= default_value_or_proc.is_a?(Proc) ? default_value_or_proc.call(self) : default_value_or_proc end end - # Should return a list of require option names which will be # used in validations. To be overridden. def self.required_options; []; end - # Should return a hash of default options, where the keys are # the option names and the values are either default option # values or Procs that take a single connection argument. This # allow defaults to use other parameters in the connection to # construct the appropriate default value. def self.default_options; {}; end - end - # STI Subclass for ZMQ connections and their required options class ZMQConnection < Connection - def self.default_options { 'output_socket_type' => 'PUSH', - 'output_address' => lambda{|conn| "ipc://rflow.#{conn.uuid}"}, + 'output_address' => lambda{|conn| "ipc://rflow.#{conn.uuid}"}, 'output_responsibility' => 'connect', 'input_socket_type' => 'PULL', - 'input_address' => lambda{|conn| "ipc://rflow.#{conn.uuid}"}, + 'input_address' => lambda{|conn| "ipc://rflow.#{conn.uuid}"}, 'input_responsibility' => 'bind', } end end - # STI Subclass for AMQP connections and their required options class AMQPConnection < Connection - def self.default_options { 'host' => 'localhost', 'port' => 5672, 'insist' => true, @@ -89,9 +80,13 @@ 'queue_exclusive' => false, 'queue_auto_delete' => false, 'queue_nowait' => true, } end + end + # for testing purposes + class NullConfiguration + attr_accessor :name, :uuid, :options end end end