Class: Switches::Update
- Inherits:
-
Object
- Object
- Switches::Update
- Includes:
- JSONSerializer
- Defined in:
- lib/switches/update.rb
Constant Summary
Constants included from JSONSerializer
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#node_id ⇒ Object
Returns the value of attribute node_id.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #from?(node_id) ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Update
constructor
A new instance of Update.
Methods included from JSONSerializer
deserialize, serialize, #to_json
Constructor Details
#initialize(attributes = {}) ⇒ Update
Returns a new instance of Update.
20 21 22 23 24 |
# File 'lib/switches/update.rb', line 20 def initialize(attributes = {}) @type = attributes["type"] @name = attributes["name"] @node_id = attributes["node_id"] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/switches/update.rb', line 5 def name @name end |
#node_id ⇒ Object
Returns the value of attribute node_id.
5 6 7 |
# File 'lib/switches/update.rb', line 5 def node_id @node_id end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/switches/update.rb', line 5 def type @type end |
Class Method Details
.build(item, node_id) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/switches/update.rb', line 7 def self.build(item, node_id) new.tap do |update| update.type = item.type update.name = item.name update.node_id = node_id end end |
.load(json) ⇒ Object
15 16 17 18 |
# File 'lib/switches/update.rb', line 15 def self.load(json) attributes = JSONSerializer.deserialize(json) new(attributes) end |
Instance Method Details
#as_json ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/switches/update.rb', line 30 def as_json { type: type, name: name, node_id: node_id } end |
#from?(node_id) ⇒ Boolean
26 27 28 |
# File 'lib/switches/update.rb', line 26 def from?(node_id) @node_id == node_id end |