Class: Ilike::ArelTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/ilike/arel_template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arr) ⇒ ArelTemplate

Returns a new instance of ArelTemplate.



5
6
7
# File 'lib/ilike/arel_template.rb', line 5

def initialize(arr)
  @field, @values = arr
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



3
4
5
# File 'lib/ilike/arel_template.rb', line 3

def field
  @field
end

#valuesObject (readonly)

Returns the value of attribute values.



3
4
5
# File 'lib/ilike/arel_template.rb', line 3

def values
  @values
end

Instance Method Details

#buildObject



9
10
11
12
13
14
15
# File 'lib/ilike/arel_template.rb', line 9

def build
  if Array === values
    values.map {|value| template(value)}
  else
    template(values)
  end
end

#template(value) ⇒ Object



17
18
19
# File 'lib/ilike/arel_template.rb', line 17

def template(value)
  "(arel_table[:#{field}].matches('#{value}'))"
end