Class: PagerJudy::API::Item
- Inherits:
-
Object
- Object
- PagerJudy::API::Item
- Defined in:
- lib/pager_judy/api/item.rb
Overview
Represents an item, e.g. a service, a user, …
Instance Attribute Summary collapse
-
#criteria ⇒ Object
readonly
Returns the value of attribute criteria.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(resource, type, id, criteria = {}) ⇒ Item
constructor
A new instance of Item.
- #read ⇒ Object
- #to_h ⇒ Object
- #update(data) ⇒ Object
- #with(more_criteria) ⇒ Object
Constructor Details
#initialize(resource, type, id, criteria = {}) ⇒ Item
Returns a new instance of Item.
8 9 10 11 12 13 |
# File 'lib/pager_judy/api/item.rb', line 8 def initialize(resource, type, id, criteria = {}) @resource = resource @type = type @id = id @criteria = criteria end |
Instance Attribute Details
#criteria ⇒ Object (readonly)
Returns the value of attribute criteria.
18 19 20 |
# File 'lib/pager_judy/api/item.rb', line 18 def criteria @criteria end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
17 18 19 |
# File 'lib/pager_judy/api/item.rb', line 17 def id @id end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
15 16 17 |
# File 'lib/pager_judy/api/item.rb', line 15 def resource @resource end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
16 17 18 |
# File 'lib/pager_judy/api/item.rb', line 16 def type @type end |
Instance Method Details
#read ⇒ Object
25 26 27 |
# File 'lib/pager_judy/api/item.rb', line 25 def read resource.get(criteria).fetch(type) end |
#to_h ⇒ Object
39 40 41 |
# File 'lib/pager_judy/api/item.rb', line 39 def to_h read end |
#update(data) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/pager_judy/api/item.rb', line 29 def update(data) if dry_run? result = data else result = resource.put(type => data).fetch(type) end name = result.fetch("name") logger.info { "updated #{type} #{name.inspect} [#{id}]" } end |
#with(more_criteria) ⇒ Object
20 21 22 23 |
# File 'lib/pager_judy/api/item.rb', line 20 def with(more_criteria) more_criteria = Hash[more_criteria.select { |_, v| v }] self.class.new(resource, type, id, criteria.merge(more_criteria)) end |