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 13 14 15 16 17 |
# 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 = {} self.class._validators.keys.reject { |k| k.to_s.start_with? '__' }.each do |key| @body[key] = body[key] end @headers[:dispatch_at] = dispatch_at unless dispatch_at.nil? end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
65 66 67 |
# File 'lib/euston/command.rb', line 65 def body @body end |
Instance Method Details
#headers ⇒ Object
19 20 21 |
# File 'lib/euston/command.rb', line 19 def headers @headers.merge :version => version end |
#id ⇒ Object
23 24 25 |
# File 'lib/euston/command.rb', line 23 def id @headers[:id] end |
#id=(value) ⇒ Object
27 28 29 |
# File 'lib/euston/command.rb', line 27 def id= value @headers[:id] = value end |
#publishing_user_id ⇒ Object
31 32 33 |
# File 'lib/euston/command.rb', line 31 def publishing_user_id @headers[:user_id] end |
#publishing_user_id=(value) ⇒ Object
35 36 37 |
# File 'lib/euston/command.rb', line 35 def publishing_user_id= value @headers[:user_id] = value end |
#read_attribute_for_validation(key) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/euston/command.rb', line 39 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
53 54 55 |
# File 'lib/euston/command.rb', line 53 def to_hash { :headers => headers, :body => @body } end |
#type ⇒ Object
49 50 51 |
# File 'lib/euston/command.rb', line 49 def type @headers[:type] end |
#version ⇒ Object
57 58 59 |
# File 'lib/euston/command.rb', line 57 def version @headers[:version] end |
#version=(value) ⇒ Object
61 62 63 |
# File 'lib/euston/command.rb', line 61 def version= value @headers[:version] = value end |