Class: Philtre::PlaceHolder

Inherits:
Sequel::SQL::Expression
  • Object
show all
Defined in:
lib/philtre/place_holder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, sql_field = nil, bt = caller) ⇒ PlaceHolder

name is what gets replaced by the operation and correspondingly named value in the filter sql_field is the name of the field that the operation will compare the named value to.



5
6
7
8
9
10
11
# File 'lib/philtre/place_holder.rb', line 5

def initialize( name, sql_field = nil, bt = caller )
  # backtrace
  @bt = bt

  @name = name
  @sql_field = sql_field
end

Instance Attribute Details

#btObject (readonly)

Returns the value of attribute bt.



13
14
15
# File 'lib/philtre/place_holder.rb', line 13

def bt
  @bt
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/philtre/place_holder.rb', line 14

def name
  @name
end

#sql_fieldObject (readonly)

Returns the value of attribute sql_field.



15
16
17
# File 'lib/philtre/place_holder.rb', line 15

def sql_field
  @sql_field
end

Instance Method Details

#inspectObject



33
34
35
# File 'lib/philtre/place_holder.rb', line 33

def inspect
  "#<#{self.class} #{name}:#{sql_field} @#{source}>"
end

#small_sourceObject



29
30
31
# File 'lib/philtre/place_holder.rb', line 29

def small_source
  source.split('/').last(2).join('/').split(':')[0..1].join(':')
end

#sourceObject



25
26
27
# File 'lib/philtre/place_holder.rb', line 25

def source
  bt[1]
end

#to_sObject



37
38
39
# File 'lib/philtre/place_holder.rb', line 37

def to_s
  "#{name}:#{sql_field} @#{small_source}"
end

#to_s_append(ds, s) ⇒ Object

this is inserted into the generated SQL from a dataset that contains PlaceHolder instances.



19
20
21
22
23
# File 'lib/philtre/place_holder.rb', line 19

def to_s_append( ds, s )
  s << '$' << name.to_s
  s << ':' << sql_field.to_s if sql_field
  s << '/*' << small_source  << '*/'
end