module KongSchema::Resource::Api
Public Instance Methods
all(*)
click to toggle source
# File lib/kong_schema/resource/api.rb, line 22 def all(*) Kong::Api.all end
changed?(record, attributes)
click to toggle source
# 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 normal_attributes = attributes.keys.reduce({}) do |map, key| value = attributes[key] case key # sometimes the API reports it an array, sometimes a string, sometimes # nil... when 'methods' map[key] = Array(value).join(',').split(',') else map[key] = value end map end Adapter.for(Kong::Api).changed?(current, normal_attributes) end
creatable?(*)
click to toggle source
# File lib/kong_schema/resource/api.rb, line 30 def creatable?(*) true end
create(attributes)
click to toggle source
# File lib/kong_schema/resource/api.rb, line 26 def create(attributes) Adapter.for(Kong::Api).create(serialize_outbound(attributes)) end
delete(record)
click to toggle source
# File lib/kong_schema/resource/api.rb, line 73 def delete(record) Adapter.for(Kong::Api).delete(record) end
identify(record)
click to toggle source
# 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)
click to toggle source
# File lib/kong_schema/resource/api.rb, line 77 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
update(record, partial_attributes)
click to toggle source
# File lib/kong_schema/resource/api.rb, line 66 def update(record, partial_attributes) Adapter.for(Kong::Api).update( record, serialize_outbound(partial_attributes) ) end