Class: Squeel::DSL
- Inherits:
-
Object
- Object
- Squeel::DSL
- Defined in:
- lib/squeel/dsl.rb
Overview
Interprets DSL blocks, generating various Squeel nodes as appropriate.
Class Method Summary collapse
-
.eval {|dsl| ... } ⇒ Object
Called from an adapter, not directly.
Instance Method Summary collapse
-
#initialize(caller_binding) ⇒ DSL
constructor
private
This isn’t normally called directly, but via DSL.eval, which will pass the block’s binding to the new instance, for use with #my.
-
#method_missing(method_id, *args) ⇒ Object
private
Node generation inside DSL blocks.
-
#my(&block) ⇒ Object
private
If you really need to get at an instance variable or method inside a DSL block, this method will let you do it.
Constructor Details
#initialize(caller_binding) ⇒ DSL (private)
This isn’t normally called directly, but via DSL.eval, which will pass the block’s binding to the new instance, for use with #my.
41 42 43 |
# File 'lib/squeel/dsl.rb', line 41 def initialize(caller_binding) @caller = caller_binding.eval 'self' end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#node_name ⇒ Nodes::Stub (private) #node_name(klass) ⇒ Nodes::Join (private) #node_name(first_arg, *other_args) ⇒ Nodes::Function (private)
Node generation inside DSL blocks.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/squeel/dsl.rb', line 73 def method_missing(method_id, *args) super if method_id == :to_ary if args.empty? Nodes::Stub.new method_id elsif (args.size == 1) && (Class === args[0]) Nodes::Join.new(method_id, Arel::InnerJoin, args[0]) else Nodes::Function.new method_id, args end end |
Class Method Details
.eval {|dsl| ... } ⇒ Object
Called from an adapter, not directly. Evaluates a block of Squeel DSL code.
27 28 29 30 31 32 33 |
# File 'lib/squeel/dsl.rb', line 27 def self.eval(&block) if block.arity > 0 yield self.new(block.binding) else self.new(block.binding).instance_eval(&block) end end |
Instance Method Details
#my(&block) ⇒ Object (private)
If you really need to get at an instance variable or method inside a DSL block, this method will let you do it. It passes a block back to the DSL’s caller for instance_eval.
It’s also pretty evil, so I hope you enjoy using it while I’m burning in programmer hell.
54 55 56 |
# File 'lib/squeel/dsl.rb', line 54 def my(&block) @caller.instance_eval &block end |