Module: KongSchema::Resource::Target
Instance Method Summary collapse
- #all ⇒ Object
- #changed?(record, directive) ⇒ Boolean
- #creatable? ⇒ Boolean
- #create(attributes) ⇒ Object
- #delete(target) ⇒ Object
- #identify(record) ⇒ Object
- #update(record, partial_attributes) ⇒ Object
Instance Method Details
#all ⇒ Object
20 21 22 |
# File 'lib/kong_schema/resource/target.rb', line 20 def all(*) Kong::Upstream.all.map(&:targets).flatten end |
#changed?(record, directive) ⇒ Boolean
36 37 38 39 40 41 42 |
# File 'lib/kong_schema/resource/target.rb', line 36 def changed?(record, directive) ( record.target != directive['target'] || record.weight != directive.fetch('weight', 100) || record.upstream.name != directive['upstream_id'] ) end |
#creatable? ⇒ Boolean
32 33 34 |
# File 'lib/kong_schema/resource/target.rb', line 32 def creatable?(*) true end |
#create(attributes) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/kong_schema/resource/target.rb', line 24 def create(attributes) with_upstream(attributes) do |upstream| Adapter.for(Kong::Target).create( attributes.merge('upstream_id' => upstream.id) ) end end |
#delete(target) ⇒ Object
49 50 51 |
# File 'lib/kong_schema/resource/target.rb', line 49 def delete(target) Adapter.for(Kong::Target).delete(target) end |
#identify(record) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/kong_schema/resource/target.rb', line 11 def identify(record) case record when Kong::Target [record.upstream.name, record.target].to_json when Hash [record['upstream_id'], record['target']].to_json end end |
#update(record, partial_attributes) ⇒ Object
44 45 46 47 |
# File 'lib/kong_schema/resource/target.rb', line 44 def update(record, partial_attributes) delete(record) create(partial_attributes) end |