Class: Layer::RelationProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/layer/relation_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, resource_type, operations = [], &block) ⇒ RelationProxy

Returns a new instance of RelationProxy



6
7
8
9
10
11
12
13
# File 'lib/layer/relation_proxy.rb', line 6

def initialize(base, resource_type, operations = [], &block)
  @resource_type = resource_type
  @base = base

  operations.each { |operation| singleton_class.send(:include, operation::ClassMethods) }

  instance_eval(&block) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



29
30
31
32
33
34
35
# File 'lib/layer/relation_proxy.rb', line 29

def method_missing(method, *args, &block)
  if resource_type.respond_to?(method)
    resource_type.public_send(method, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base



4
5
6
# File 'lib/layer/relation_proxy.rb', line 4

def base
  @base
end

#resource_typeObject (readonly)

Returns the value of attribute resource_type



4
5
6
# File 'lib/layer/relation_proxy.rb', line 4

def resource_type
  @resource_type
end

Instance Method Details

#clientObject



23
24
25
# File 'lib/layer/relation_proxy.rb', line 23

def client
  base.client
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/layer/relation_proxy.rb', line 19

def respond_to_missing?(method, include_private = false)
  resource_type.respond_to?(method, include_private) || super
end

#urlObject



15
16
17
# File 'lib/layer/relation_proxy.rb', line 15

def url
  "#{base.url}#{resource_type.url}"
end