Class: URL::Service::Endpoint

Inherits:
Object
  • Object
show all
Includes:
AcceptsEndpoint
Defined in:
lib/url/endpoint.rb

Defined Under Namespace

Classes: EndpointNotResponding, RequiredParameter

Constant Summary collapse

BUILT_IN_MAP =

Define the built in methods and their fetcher aliases

{
  :get => %w{find},
  :post => %w{create},
  :put => %w{update},
  :delete => %w{destroy}
}.each do |method,aliases|
  class_eval "    def \#{method} params = {}, opts = {}\n      u = @url.dup\n      u.params.merge! params\n\n      u.\#{method} opts\n    end\n  RUBY\n  aliases.each do |al|\n    class_eval <<-RUBY, __FILE__, __LINE__\n      def \#{al} params={}, opts={}\n        transform_response \#{method}(params, opts)\n      end\n    RUBY\n  end\nend.freeze\n", __FILE__, __LINE__
BUILT_IN_METHODS =
BUILT_IN_MAP.collect do |k,v|
  v.collect{|vv| vv.to_sym}+[k.to_sym]
end.flatten.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AcceptsEndpoint

#endpoint

Constructor Details

#initialize(url) ⇒ Endpoint



40
41
42
# File 'lib/url/endpoint.rb', line 40

def initialize url
  @base_url = @url = url
end

Instance Attribute Details

#inflate_intoObject

Returns the value of attribute inflate_into.



4
5
6
# File 'lib/url/endpoint.rb', line 4

def inflate_into
  @inflate_into
end

Instance Method Details

#class_eval(*args, &blk) ⇒ Object

Expose class eval externally



45
46
47
# File 'lib/url/endpoint.rb', line 45

def class_eval *args,&blk
  eigenclass.class_eval *args,&blk
end

#eigenclassObject



49
50
51
# File 'lib/url/endpoint.rb', line 49

def eigenclass
  class << self; self; end
end

#inspectObject



53
54
55
# File 'lib/url/endpoint.rb', line 53

def inspect
  %Q{#<#{self.class} #{@url.to_s}>}
end

#method_inflate_intoObject

Storage for what each endpoint should inflate into



8
9
10
# File 'lib/url/endpoint.rb', line 8

def method_inflate_into
  @method_inflate_into ||= {}
end