Class: LinqrExp
Instance Attribute Summary collapse
-
#binding ⇒ Object
readonly
Returns the value of attribute binding.
Instance Method Summary collapse
- #evaluate ⇒ Object
- #fcall(exp, fname) ⇒ Object
- #fexp(exp, fname) ⇒ Object
- #group_by ⇒ Object
- #group_by? ⇒ Boolean
-
#initialize(proc_exp) ⇒ LinqrExp
constructor
A new instance of LinqrExp.
- #order_by ⇒ Object
- #order_by? ⇒ Boolean
- #set_variable(var, val) ⇒ Object
- #source ⇒ Object
- #variable ⇒ Object
- #variable_val(var_name) ⇒ Object
- #variables ⇒ Object
- #with_vars ⇒ Object
Constructor Details
#initialize(proc_exp) ⇒ LinqrExp
Returns a new instance of LinqrExp.
53 54 55 56 |
# File 'lib/linqr_exp.rb', line 53 def initialize(proc_exp) @exp = Ripper::RubyBuilder.build(proc_exp.to_source) @binding = proc_exp.binding end |
Instance Attribute Details
#binding ⇒ Object (readonly)
Returns the value of attribute binding.
52 53 54 |
# File 'lib/linqr_exp.rb', line 52 def binding @binding end |
Instance Method Details
#evaluate ⇒ Object
58 59 60 |
# File 'lib/linqr_exp.rb', line 58 def evaluate source.linqr_provider.evaluate(self) end |
#fcall(exp, fname) ⇒ Object
68 69 70 |
# File 'lib/linqr_exp.rb', line 68 def fcall(exp, fname) exp.select(Ruby::Call).select {|call|call.identifier && call.token == fname}.first end |
#fexp(exp, fname) ⇒ Object
73 74 75 76 |
# File 'lib/linqr_exp.rb', line 73 def fexp(exp, fname) f_arg = fcall(exp,fname).arguments.first f_arg # make this less confusing end |
#group_by ⇒ Object
35 36 37 |
# File 'lib/linqr_exp.rb', line 35 def group_by GroupBy.new(fexp(@exp,"group_by")) end |
#group_by? ⇒ Boolean
39 40 41 |
# File 'lib/linqr_exp.rb', line 39 def group_by? !fcall(@exp,"group_by").nil? end |
#order_by ⇒ Object
43 44 45 |
# File 'lib/linqr_exp.rb', line 43 def order_by OrderBy.new(fcall(@exp,"order_by")) end |
#order_by? ⇒ Boolean
47 48 49 |
# File 'lib/linqr_exp.rb', line 47 def order_by? !fcall(@exp,"order_by").nil? end |
#set_variable(var, val) ⇒ Object
22 23 24 25 |
# File 'lib/linqr_exp.rb', line 22 def set_variable(var,val) @variables ||= {} @variables[var] = val end |
#source ⇒ Object
77 78 79 80 81 |
# File 'lib/linqr_exp.rb', line 77 def source token =fcall(@exp,"in_").arguments.first source_name = token.evaluate_source_name(SourceNameEvaluator.new) @binding.eval(source_name) end |
#variable ⇒ Object
62 63 64 |
# File 'lib/linqr_exp.rb', line 62 def variable variables.first end |
#variable_val(var_name) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/linqr_exp.rb', line 27 def variable_val(var_name) if (@variables && var = @variables[var_name]) var else @binding.eval(var_name) end end |
#variables ⇒ Object
65 66 67 |
# File 'lib/linqr_exp.rb', line 65 def variables fcall(@exp,"from").arguments.collect(&:name) end |
#with_vars ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/linqr_exp.rb', line 11 def with_vars @variables ||= {} Proc.new do |args| args= [args] unless args.is_a? Array args.each_with_index do |param, idx| @variables[variables[idx].to_s]= param end yield *args end end |