Class: Euston::Command
- Inherits:
-
Object
- Object
- Euston::Command
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/euston/command.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
Instance Method Summary collapse
- #headers ⇒ Object
- #id ⇒ Object
- #id=(value) ⇒ Object
-
#initialize(body, dispatch_at = nil) ⇒ Command
constructor
A new instance of Command.
- #publishing_user_id ⇒ Object
- #publishing_user_id=(value) ⇒ Object
- #read_attribute_for_validation(key) ⇒ Object
- #to_hash ⇒ Object
- #type ⇒ Object
- #version ⇒ Object
- #version=(value) ⇒ Object
Constructor Details
#initialize(body, dispatch_at = nil) ⇒ Command
Returns a new instance of Command.
5 6 7 8 9 10 11 12 |
# File 'lib/euston/command.rb', line 5 def initialize body, dispatch_at = nil @headers = { :id => Uuid.generate, :type => self.class.to_s.split('::').pop.underscore.to_sym, :version => 1 } @body = body @headers[:dispatch_at] = dispatch_at unless dispatch_at.nil? end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
60 61 62 |
# File 'lib/euston/command.rb', line 60 def body @body end |
Instance Method Details
#headers ⇒ Object
14 15 16 |
# File 'lib/euston/command.rb', line 14 def headers @headers.merge :version => version end |
#id ⇒ Object
18 19 20 |
# File 'lib/euston/command.rb', line 18 def id @headers[:id] end |
#id=(value) ⇒ Object
22 23 24 |
# File 'lib/euston/command.rb', line 22 def id= value @headers[:id] = value end |
#publishing_user_id ⇒ Object
26 27 28 |
# File 'lib/euston/command.rb', line 26 def publishing_user_id @headers[:user_id] end |
#publishing_user_id=(value) ⇒ Object
30 31 32 |
# File 'lib/euston/command.rb', line 30 def publishing_user_id= value @headers[:user_id] = value end |
#read_attribute_for_validation(key) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/euston/command.rb', line 34 def read_attribute_for_validation key match = /^__(.*)/.match(key.to_s) if match.nil? @body[key] else headers[match[1].to_sym] end end |
#to_hash ⇒ Object
48 49 50 |
# File 'lib/euston/command.rb', line 48 def to_hash { :headers => headers, :body => @body } end |
#type ⇒ Object
44 45 46 |
# File 'lib/euston/command.rb', line 44 def type @headers[:type] end |
#version ⇒ Object
52 53 54 |
# File 'lib/euston/command.rb', line 52 def version @headers[:version] end |
#version=(value) ⇒ Object
56 57 58 |
# File 'lib/euston/command.rb', line 56 def version= value @headers[:version] = value end |