Class: Ruleby::Ferrari::AtomBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/dsl/ferrari.rb

Direct Known Subclasses

NotOperatorBuilder

Constant Summary collapse

EQ_PROC =
lambda {|x,y| x and x == y}
GT_PROC =
lambda {|x,y| x and x > y}
LT_PROC =
lambda {|x,y| x and x < y}
MATCH_PROC =
lambda {|x,y| x and x =~ y}
LTE_PROC =
lambda {|x,y| x and x <= y}
GTE_PROC =
lambda {|x,y| x and x >= y}
TRUE_PROC =
lambda {|x| true}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_id) ⇒ AtomBuilder

Returns a new instance of AtomBuilder.



373
374
375
376
377
378
379
380
# File 'lib/dsl/ferrari.rb', line 373

def initialize(method_id)
  @name = method_id
  @deftemplate = nil
  @tag = GeneratedTag.new
  @bindings = []
  @block = TRUE_PROC
  @child_atom_builders = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



382
383
384
385
386
# File 'lib/dsl/ferrari.rb', line 382

def method_missing(method_id, *args, &block)
  if method_id == :not
    NotOperatorBuilder.new(@name)
  end
end

Instance Attribute Details

#bindingsObject

Returns the value of attribute bindings.



363
364
365
# File 'lib/dsl/ferrari.rb', line 363

def bindings
  @bindings
end

#blockObject

Returns the value of attribute block.



363
364
365
# File 'lib/dsl/ferrari.rb', line 363

def block
  @block
end

#deftemplateObject

Returns the value of attribute deftemplate.



363
364
365
# File 'lib/dsl/ferrari.rb', line 363

def deftemplate
  @deftemplate
end

#nameObject

Returns the value of attribute name.



363
364
365
# File 'lib/dsl/ferrari.rb', line 363

def name
  @name
end

#tagObject

Returns the value of attribute tag.



363
364
365
# File 'lib/dsl/ferrari.rb', line 363

def tag
  @tag
end

Instance Method Details

#<(value) ⇒ Object



399
400
401
402
# File 'lib/dsl/ferrari.rb', line 399

def <(value)
  create_block value, LT_PROC
  self
end

#<=(value) ⇒ Object



409
410
411
412
# File 'lib/dsl/ferrari.rb', line 409

def <=(value)
  create_block value, LTE_PROC
  self
end

#==(value) ⇒ Object



388
389
390
391
392
# File 'lib/dsl/ferrari.rb', line 388

def ==(value)
  @atom_type = :equals
  create_block value, EQ_PROC
  self
end

#=~(value) ⇒ Object



404
405
406
407
# File 'lib/dsl/ferrari.rb', line 404

def =~(value)
  create_block value, MATCH_PROC
  self
end

#>(value) ⇒ Object



394
395
396
397
# File 'lib/dsl/ferrari.rb', line 394

def >(value)
  create_block value, GT_PROC
  self
end

#>=(value) ⇒ Object



414
415
416
417
# File 'lib/dsl/ferrari.rb', line 414

def >=(value)
  create_block value, GTE_PROC
  self
end

#build_atoms(tags, methods, when_id) ⇒ Object



419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
# File 'lib/dsl/ferrari.rb', line 419

def build_atoms(tags,methods,when_id)
  atoms = @child_atom_builders.map { |atom_builder|
    tags[atom_builder.tag] = when_id
    methods[atom_builder.tag] = atom_builder.name
    atom_builder.build_atoms(tags,methods,when_id)
  }.flatten || []

  if @bindings.empty?
    if @atom_type == :equals 
      return atoms << Core::EqualsAtom.new(@tag, @name, @deftemplate, @value)
    else
      return atoms << Core::PropertyAtom.new(@tag, @name, @deftemplate, @value, @block)
    end
  end
  
  if references_self?(tags,when_id)
    bind_methods = @bindings.collect{ |bb| methods[bb.tag] }
    atoms << Core::SelfReferenceAtom.new(@tag,@name,bind_methods,@deftemplate,@block)
  else
    bind_tags = @bindings.collect{ |bb| bb.tag }
    atoms << Core::ReferenceAtom.new(@tag,@name,bind_tags,@deftemplate,@block)
  end
end