Class: ORQ::Impulse
- Inherits:
-
Object
- Object
- ORQ::Impulse
- Defined in:
- lib/orq/impulse.rb
Overview
Base class inherited by domain objects describing a message that can be sent
Class Method Summary collapse
-
.configure(path, environment) ⇒ Object
Configures the ORQ infrastructure using the file on the given path.
-
.field(name) ⇒ Object
Declares a field that should be available on an impulse.
-
.load(text) ⇒ Object
Loading Methods.
-
.start ⇒ Object
Requests that the ORQ infrastructure start any connections.
-
.subscribe(&block) ⇒ Object
Control Methods.
-
.target_name(target_name = nil) ⇒ Object
Sets the target name for this Impulse if a uri is provided; returns the value for the target name (or 'default' if not overriden).
-
.uri(uri = nil) ⇒ Object
Sets the uri for this Impulse if a uri is provided; returns the value for the uri (or the class name if not overriden).
Instance Method Summary collapse
-
#apply_hash!(props) ⇒ Object
Instructs the impulse to apply the properties in the given hash.
-
#fire! ⇒ Object
Instructs the impulse to send itself to the message queue.
-
#initialize(config = {}) ⇒ Impulse
constructor
A new instance of Impulse.
Constructor Details
#initialize(config = {}) ⇒ Impulse
Returns a new instance of Impulse.
8 9 10 |
# File 'lib/orq/impulse.rb', line 8 def initialize(config = {}) apply_hash!(config) end |
Class Method Details
.configure(path, environment) ⇒ Object
Configures the ORQ infrastructure using the file on the given path.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/orq/impulse.rb', line 74 def self.configure(path, environment) # Load the given YAML file config = YAML::load_file(path) # Get the configuration for the profile env_config = config[environment.to_s] raise "No configuration for environment #{environment} in #{path}" unless env_config # Clear the list of targets, and then process each @@targets = {} if env_config.is_a? Hash env_config.each do |target_name, target_config| @@targets[target_name] = load_target target_name, target_config end end end |
.field(name) ⇒ Object
Declares a field that should be available on an impulse.
49 50 51 |
# File 'lib/orq/impulse.rb', line 49 def field(name) attr_accessor name end |
.load(text) ⇒ Object
Loading Methods
64 65 66 67 68 |
# File 'lib/orq/impulse.rb', line 64 def load(text) vals = ActiveSupport::JSON.decode(text) result = new(vals) result end |
.start ⇒ Object
Requests that the ORQ infrastructure start any connections
93 94 95 96 97 |
# File 'lib/orq/impulse.rb', line 93 def self.start @@targets.each do |name, target| target.start end end |
.subscribe(&block) ⇒ Object
Control Methods
56 57 58 59 |
# File 'lib/orq/impulse.rb', line 56 def subscribe(&block) target = get_target self.target_name target.subscribe self, &block end |
.target_name(target_name = nil) ⇒ Object
Sets the target name for this Impulse if a uri is provided; returns the value for the target name (or 'default' if not overriden)
41 42 43 44 45 46 |
# File 'lib/orq/impulse.rb', line 41 def target_name(target_name = nil) @target_name = target_name unless target_name.nil? return 'default' if @target_name.nil? @target_name end |
.uri(uri = nil) ⇒ Object
Sets the uri for this Impulse if a uri is provided; returns the value for the uri (or the class name if not overriden)
32 33 34 35 36 37 |
# File 'lib/orq/impulse.rb', line 32 def uri(uri = nil) @uri = uri unless uri.nil? return self.name if @uri.nil? @uri end |
Instance Method Details
#apply_hash!(props) ⇒ Object
Instructs the impulse to apply the properties in the given hash
18 19 20 21 22 |
# File 'lib/orq/impulse.rb', line 18 def apply_hash!(props) props.each do |k, v| send("#{k}=", v) if respond_to? "#{k}=" end end |
#fire! ⇒ Object
Instructs the impulse to send itself to the message queue
13 14 15 |
# File 'lib/orq/impulse.rb', line 13 def fire! self.class.get_target(self.class.target_name).fire self.class.uri, ActiveSupport::JSON.encode(self) end |