Class: BabySqueel::Nodes::Proxy

Inherits:
ActiveSupport::ProxyObject
  • Object
show all
Defined in:
lib/baby_squeel/nodes/proxy.rb

Overview

This proxy class allows us to quack like any arel object. When a method missing is hit, we’ll instantiate a new proxy object.

Direct Known Subclasses

Node

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arel) ⇒ Proxy

Returns a new instance of Proxy.



13
14
15
# File 'lib/baby_squeel/nodes/proxy.rb', line 13

def initialize(arel)
  @_arel = Nodes.unwrap(arel)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



27
28
29
30
31
32
33
# File 'lib/baby_squeel/nodes/proxy.rb', line 27

def method_missing(meth, *args, &block)
  if _arel.respond_to?(meth)
    Nodes.wrap _arel.send(meth, *Nodes.unwrap(args), &block)
  else
    super
  end
end

Instance Attribute Details

#_arelObject (readonly)

Returns the value of attribute _arel.



11
12
13
# File 'lib/baby_squeel/nodes/proxy.rb', line 11

def _arel
  @_arel
end

Class Method Details

.const_missing(name) ⇒ Object

Resolve constants the normal way



7
8
9
# File 'lib/baby_squeel/nodes/proxy.rb', line 7

def self.const_missing(name)
  ::Object.const_get(name)
end

Instance Method Details

#inspectObject



17
18
19
# File 'lib/baby_squeel/nodes/proxy.rb', line 17

def inspect
  "BabySqueel{#{super}}"
end

#respond_to?(meth, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/baby_squeel/nodes/proxy.rb', line 21

def respond_to?(meth, include_private = false)
  meth.to_s == '_arel' || _arel.respond_to?(meth, include_private)
end