Class: Harold::Operation

Inherits:
Object
  • Object
show all
Defined in:
lib/operation.rb

Constant Summary collapse

VALID_TYPES =
%i[add update delete].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, type, payload = {}, attributes = {}) ⇒ Operation

Returns a new instance of Operation.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/operation.rb', line 6

def initialize(id, type, payload = {}, attributes = {})
  unless VALID_TYPES.include?(type)
    raise ArgumentError,
          "#{type} is not a valid type"
  end

  @id = id
  @type = type
  @payload = payload
  @attributes = attributes

  attributes.each_pair do |key, val|
    define_singleton_method(key) { val }
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



4
5
6
# File 'lib/operation.rb', line 4

def attributes
  @attributes
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/operation.rb', line 4

def id
  @id
end

#payloadObject (readonly)

Returns the value of attribute payload.



4
5
6
# File 'lib/operation.rb', line 4

def payload
  @payload
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/operation.rb', line 4

def type
  @type
end