Sha256: 5a4896088d25e0a7abe851c330077a9c0c93b1455161d6b0ad4306b392e89719

Contents?: true

Size: 969 Bytes

Versions: 4

Compression:

Stored size: 969 Bytes

Contents

class URL
  class Service
    module AcceptsEndpoint

      # creates the endpoint for which ever object it's imported into
      def endpoint arg, &blk
        endpoint = if arg.is_a?(Hash)
          f = arg.first
          name = f.shift
          f.shift
        else
          name = arg
        end

        eigenclass.send :attr_reader, "#{name}_endpoint"
        instance_eval <<-RUBY, __FILE__, __LINE__
          def #{name} params=nil, args={}
            if params.nil?
              @#{name}_endpoint
            else
              @#{name}_endpoint.find(params,args)
            end
          end
        RUBY

        builder = EndpointBuilder.new(@base_url,endpoint,&blk)
        e = builder._endpoint
        
        e.inflate_into ||= @inflate_into if @inflate_into
        instance_variable_set "@#{name}_endpoint",e
      end

      # allows access to the eigenclass
      def eigenclass
        class << self; self; end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/url-0.3.2/lib/url/accepts_endpoint.rb
url-0.3.2 lib/url/accepts_endpoint.rb
url-0.3.1 lib/url/accepts_endpoint.rb
url-0.3.0 lib/url/accepts_endpoint.rb