Class: ZeroRailsAdapter::Mutation
- Inherits:
-
Object
- Object
- ZeroRailsAdapter::Mutation
- Defined in:
- lib/zero_rails_adapter/mutation.rb
Constant Summary collapse
- REQUIRED_KEYS =
%w[type id clientID name args timestamp].freeze
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #argument ⇒ Object
- #identifier ⇒ Object
-
#initialize(type:, id:, client_id:, name:, args:, timestamp:) ⇒ Mutation
constructor
A new instance of Mutation.
Constructor Details
#initialize(type:, id:, client_id:, name:, args:, timestamp:) ⇒ Mutation
Returns a new instance of Mutation.
33 34 35 36 37 38 39 40 |
# File 'lib/zero_rails_adapter/mutation.rb', line 33 def initialize(type:, id:, client_id:, name:, args:, timestamp:) @type = type @id = id @client_id = client_id @name = name @args = args @timestamp = end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
7 8 9 |
# File 'lib/zero_rails_adapter/mutation.rb', line 7 def args @args end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
7 8 9 |
# File 'lib/zero_rails_adapter/mutation.rb', line 7 def client_id @client_id end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/zero_rails_adapter/mutation.rb', line 7 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/zero_rails_adapter/mutation.rb', line 7 def name @name end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
7 8 9 |
# File 'lib/zero_rails_adapter/mutation.rb', line 7 def @timestamp end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/zero_rails_adapter/mutation.rb', line 7 def type @type end |
Class Method Details
.parse(value) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/zero_rails_adapter/mutation.rb', line 9 def self.parse(value) unless value.is_a?(Hash) raise ParseError, "Mutation must be an object" end missing = REQUIRED_KEYS.reject { |key| value.key?(key) } raise ParseError, "Mutation is missing #{missing.join(', ')}" if missing.any? raise ParseError, "Mutation type must be custom" unless value["type"] == "custom" raise ParseError, "Mutation id must be a number" unless value["id"].is_a?(Numeric) raise ParseError, "Mutation clientID must be a string" unless value["clientID"].is_a?(String) raise ParseError, "Mutation name must be a string" unless value["name"].is_a?(String) raise ParseError, "Mutation args must be an array" unless value["args"].is_a?(Array) raise ParseError, "Mutation timestamp must be a number" unless value["timestamp"].is_a?(Numeric) new( type: value["type"], id: value["id"], client_id: value["clientID"], name: value["name"], args: value["args"], timestamp: value["timestamp"] ) end |
Instance Method Details
#argument ⇒ Object
42 43 44 |
# File 'lib/zero_rails_adapter/mutation.rb', line 42 def argument args.first end |
#identifier ⇒ Object
46 47 48 |
# File 'lib/zero_rails_adapter/mutation.rb', line 46 def identifier {"clientID" => client_id, "id" => id} end |