Class: Flounder::Expression::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/flounder/expression.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain) ⇒ Builder

Returns a new instance of Builder.



130
131
132
# File 'lib/flounder/expression.rb', line 130

def initialize domain
  @domain = domain
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

Raises:

  • (ArgumentError)


159
160
161
162
163
# File 'lib/flounder/expression.rb', line 159

def method_missing sym, *args, &block
  raise ArgumentError, "No blocks in sql execution context." if block

  FunCall.new(domain, sym, args)
end

Instance Attribute Details

#domainObject

Returns the value of attribute domain.



134
135
136
# File 'lib/flounder/expression.rb', line 134

def domain
  @domain
end

Instance Method Details

#call(&block) ⇒ Object



136
137
138
# File 'lib/flounder/expression.rb', line 136

def call &block
  instance_eval(&block)
end

#interpret_conditions(entity, conditions) ⇒ Object

Conditions are interpreted relative to an entity.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/flounder/expression.rb', line 141

def interpret_conditions entity, conditions
  # The method we need is in there...
  query = Flounder::Query::Select.new(domain, entity)
  engine = Flounder::Engine.new(domain.connection_pool)

  and_expr = BinaryOp.new(domain, 'AND')

  # TODO parse_conditions and its call tree is not really something that
  # belongs into the query object - we should create a new abstraction here.
  query.parse_conditions(*conditions) { |bit| 
    and_expr.concat(ConditionBit.new(domain, engine, bit)) }

  and_expr
end

#respond_to?(sym, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/flounder/expression.rb', line 156

def respond_to? sym, include_all=false
  true
end