Class: ThreeScaleToolbox::Entities::ActiveDocs
- Inherits:
-
Object
- Object
- ThreeScaleToolbox::Entities::ActiveDocs
- Defined in:
- lib/3scale_toolbox/entities/activedocs.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
Class Method Summary collapse
- .create(remote:, attrs:) ⇒ Object
-
.find(remote:, ref:) ⇒ Object
ref can be system_name or activedocs_id.
- .find_by_system_name(remote:, system_name:) ⇒ Object
Instance Method Summary collapse
- #attrs ⇒ Object
- #delete ⇒ Object
-
#initialize(id:, remote:, attrs: nil) ⇒ ActiveDocs
constructor
A new instance of ActiveDocs.
- #update(a_attrs) ⇒ Object
Constructor Details
#initialize(id:, remote:, attrs: nil) ⇒ ActiveDocs
Returns a new instance of ActiveDocs.
44 45 46 47 48 |
# File 'lib/3scale_toolbox/entities/activedocs.rb', line 44 def initialize(id:, remote:, attrs: nil) @id = id.to_i @remote = remote @attrs = attrs end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
42 43 44 |
# File 'lib/3scale_toolbox/entities/activedocs.rb', line 42 def id @id end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
42 43 44 |
# File 'lib/3scale_toolbox/entities/activedocs.rb', line 42 def remote @remote end |
Class Method Details
.create(remote:, attrs:) ⇒ Object
5 6 7 8 |
# File 'lib/3scale_toolbox/entities/activedocs.rb', line 5 def create(remote:, attrs:) activedocs_res = create_activedocs(remote: remote, attrs: attrs) new(id: activedocs_res.fetch('id'), remote: remote, attrs: activedocs_res) end |
.find(remote:, ref:) ⇒ Object
ref can be system_name or activedocs_id
11 12 13 14 15 |
# File 'lib/3scale_toolbox/entities/activedocs.rb', line 11 def find(remote:, ref:) new(id: ref, remote: remote).tap(&:attrs) rescue ThreeScaleToolbox::ActiveDocsNotFoundError find_by_system_name(remote: remote, system_name: ref) end |
.find_by_system_name(remote:, system_name:) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/3scale_toolbox/entities/activedocs.rb', line 17 def find_by_system_name(remote:, system_name:) activedocs_list = remote.list_activedocs if activedocs_list.respond_to?(:has_key?) && (errors = activedocs_list['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('ActiveDocs list not read', errors) end res_attrs = activedocs_list.find { |svc| svc['system_name'] == system_name } return if res_attrs.nil? new(id: res_attrs.fetch('id'), remote: remote, attrs: res_attrs) end |
Instance Method Details
#attrs ⇒ Object
50 51 52 |
# File 'lib/3scale_toolbox/entities/activedocs.rb', line 50 def attrs @attrs ||= activedoc_attrs end |
#delete ⇒ Object
54 55 56 |
# File 'lib/3scale_toolbox/entities/activedocs.rb', line 54 def delete remote.delete_activedocs id end |
#update(a_attrs) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/3scale_toolbox/entities/activedocs.rb', line 58 def update(a_attrs) new_attrs = remote.update_activedocs(id, a_attrs) if (errors = new_attrs['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('ActiveDocs has not been updated', errors) end # update current attrs @attrs = new_attrs new_attrs end |