Module: KongSchema::Resource::Api
Instance Method Summary collapse
- #all ⇒ Object
- #changed?(record, attributes) ⇒ Boolean
- #creatable? ⇒ Boolean
- #create(attributes) ⇒ Object
- #delete(record) ⇒ Object
- #identify(record) ⇒ Object
- #serialize_outbound(attributes) ⇒ Object
- #update(record, partial_attributes) ⇒ Object
Methods included from Functional
Instance Method Details
#all ⇒ Object
22 23 24 |
# File 'lib/kong_schema/resource/api.rb', line 22 def all(*) Kong::Api.all end |
#changed?(record, attributes) ⇒ Boolean
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/kong_schema/resource/api.rb', line 34 def changed?(record, attributes) current = record.attributes.keys.reduce({}) do |map, key| value = record.attributes[key] case key when 'hosts', 'methods', 'uris' map[key] = blank?(value) ? nil : Array(value) else map[key] = value end map end Adapter.for(Kong::Api).changed?(current, attributes) end |
#creatable? ⇒ Boolean
30 31 32 |
# File 'lib/kong_schema/resource/api.rb', line 30 def creatable?(*) true end |
#create(attributes) ⇒ Object
26 27 28 |
# File 'lib/kong_schema/resource/api.rb', line 26 def create(attributes) Adapter.for(Kong::Api).create(serialize_outbound(attributes)) end |
#delete(record) ⇒ Object
58 59 60 |
# File 'lib/kong_schema/resource/api.rb', line 58 def delete(record) Adapter.for(Kong::Api).delete(record) end |
#identify(record) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/kong_schema/resource/api.rb', line 13 def identify(record) case record when Kong::Api record.name when Hash record['name'] end end |
#serialize_outbound(attributes) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/kong_schema/resource/api.rb', line 62 def serialize_outbound(attributes) attributes.keys.reduce({}) do |map, key| case key when 'hosts', 'methods', 'uris' map[key] = Array(attributes[key]).join(',') else map[key] = attributes[key] end map end end |