Class: Euston::Command

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/euston/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bodyObject (readonly)

Returns the value of attribute body.



60
61
62
# File 'lib/euston/command.rb', line 60

def body
  @body
end

Instance Method Details

#headersObject



14
15
16
# File 'lib/euston/command.rb', line 14

def headers
  @headers.merge :version => version
end

#idObject



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_idObject



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_hashObject



48
49
50
# File 'lib/euston/command.rb', line 48

def to_hash
  { :headers => headers, :body => @body }
end

#typeObject



44
45
46
# File 'lib/euston/command.rb', line 44

def type
  @headers[:type]
end

#versionObject



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