module LazyAnt::DSL::Endpoint::ClassMethods
Public Instance Methods
api(name, options = {}, &block)
click to toggle source
# File lib/lazy_ant/dsl/endpoint.rb, line 12 def api(name, options = {}, &block) method, path = endpoint(options) klazz = Class.new(LazyAnt::Endpoint) do send(method, path) if method && path instance_eval(&block) if block end converter = entity_converter(options) define_method name do |*args| response = klazz.new(*args).execute(connection) converter.call(response.body) end end
Protected Instance Methods
endpoint(options)
click to toggle source
# File lib/lazy_ant/dsl/endpoint.rb, line 27 def endpoint(options) method = [:get, :post, :put, :delete].find { |k| options[k] } return unless method path = options.delete(method) [method, path] end
entity_converter(entity: nil, multi: false)
click to toggle source
# File lib/lazy_ant/dsl/endpoint.rb, line 34 def entity_converter(entity: nil, multi: false) conv = entity ? ->(x) { entity.new(x) } : ->(x) { x } multi ? -> (x) { x.map(&conv) } : -> (x) { conv.call(x) } end