Class: Harold::Operation
- Inherits:
-
Object
- Object
- Harold::Operation
- Defined in:
- lib/operation.rb
Constant Summary collapse
- VALID_TYPES =
%i[add update delete].freeze
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(id, type, payload = {}, attributes = {}) ⇒ Operation
constructor
A new instance of Operation.
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
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/operation.rb', line 4 def attributes @attributes end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/operation.rb', line 4 def id @id end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
4 5 6 |
# File 'lib/operation.rb', line 4 def payload @payload end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/operation.rb', line 4 def type @type end |