Class: BabySqueel::Nodes::Proxy

Inherits:
ActiveSupport::ProxyObject
  • Object
show all
Defined in:
lib/baby_squeel/nodes.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

Generic

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arel) ⇒ Proxy

Returns a new instance of Proxy.



39
40
41
# File 'lib/baby_squeel/nodes.rb', line 39

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)



49
50
51
52
53
54
55
# File 'lib/baby_squeel/nodes.rb', line 49

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.



37
38
39
# File 'lib/baby_squeel/nodes.rb', line 37

def _arel
  @_arel
end

Class Method Details

.const_missing(name) ⇒ Object

Resolve constants the normal way



33
34
35
# File 'lib/baby_squeel/nodes.rb', line 33

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

Instance Method Details

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

Returns:

  • (Boolean)


43
44
45
# File 'lib/baby_squeel/nodes.rb', line 43

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