Module: KongSchema::Resource::Plugin
Instance Method Summary collapse
- #all ⇒ Object
- #changed?(record, attributes) ⇒ Boolean
- #creatable?(attributes) ⇒ Boolean
- #create(attributes) ⇒ Object
- #delete(record) ⇒ Object
- #identify(record) ⇒ Object
- #update(record, partial_attributes) ⇒ Object
Methods included from Functional
Instance Method Details
#all ⇒ Object
30 31 32 |
# File 'lib/kong_schema/resource/plugin.rb', line 30 def all(*) Kong::Plugin.all end |
#changed?(record, attributes) ⇒ Boolean
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/kong_schema/resource/plugin.rb', line 42 def changed?(record, attributes) current = record.attributes.keys.each_with_object({}) do |key, map| value = record.attributes[key] map[key] = case key when 'api_id' record.api.name else value end end Adapter.for(Kong::Plugin).changed?(current, attributes) end |
#creatable?(attributes) ⇒ Boolean
38 39 40 |
# File 'lib/kong_schema/resource/plugin.rb', line 38 def creatable?(attributes) attributes['enabled'] != false end |
#create(attributes) ⇒ Object
34 35 36 |
# File 'lib/kong_schema/resource/plugin.rb', line 34 def create(attributes) Adapter.for(Kong::Plugin).create(attributes) end |
#delete(record) ⇒ Object
75 76 77 |
# File 'lib/kong_schema/resource/plugin.rb', line 75 def delete(record) Adapter.for(Kong::Plugin).delete(record) end |
#identify(record) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kong_schema/resource/plugin.rb', line 13 def identify(record) case record when Kong::Plugin [ record.name, api_bound?(record) ? record.api.name : nil, consumer_bound?(record) ? record.consumer_id : nil ] when Hash [ record['name'], record['api_id'] || nil, record['consumer_id'] || nil ] end end |
#update(record, partial_attributes) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/kong_schema/resource/plugin.rb', line 57 def update(record, partial_attributes) # a plugin may be removed implicitly by the API if its context has been # removed like an Api or Consumer, so we need to refresh before # attempting to update it if deleted_by_owner?(record) return nil elsif partial_attributes['enabled'] == false delete(record) else Adapter.for(Kong::Plugin).update( record, partial_attributes.merge( 'api_id' => api_bound?(record) ? record.api.id : nil ) ) end end |