Class: SearchCopGrammar::Attributes::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/search_cop_grammar/attributes.rb

Direct Known Subclasses

String, WithoutMatches

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, table_alias, column_name, options = {}) ⇒ Base

Returns a new instance of Base.



115
116
117
118
119
120
121
# File 'lib/search_cop_grammar/attributes.rb', line 115

def initialize(klass, table_alias, column_name, options = {})
  @attribute = klass.arel_table.alias(table_alias)[column_name]
  @klass = klass
  @table_alias = table_alias
  @column_name = column_name
  @options = (options || {})
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



147
148
149
150
151
152
153
# File 'lib/search_cop_grammar/attributes.rb', line 147

def method_missing(name, *args, &block)
  if @attribute.respond_to?(name)
    @attribute.send(name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



113
114
115
# File 'lib/search_cop_grammar/attributes.rb', line 113

def attribute
  @attribute
end

#column_nameObject (readonly)

Returns the value of attribute column_name.



113
114
115
# File 'lib/search_cop_grammar/attributes.rb', line 113

def column_name
  @column_name
end

#optionsObject (readonly)

Returns the value of attribute options.



113
114
115
# File 'lib/search_cop_grammar/attributes.rb', line 113

def options
  @options
end

#table_aliasObject (readonly)

Returns the value of attribute table_alias.



113
114
115
# File 'lib/search_cop_grammar/attributes.rb', line 113

def table_alias
  @table_alias
end

Instance Method Details

#compatible?(value) ⇒ Boolean

Returns:



127
128
129
130
131
132
133
# File 'lib/search_cop_grammar/attributes.rb', line 127

def compatible?(value)
  map value

  true
rescue SearchCop::IncompatibleDatatype
  false
end

#fulltext?Boolean

Returns:



135
136
137
# File 'lib/search_cop_grammar/attributes.rb', line 135

def fulltext?
  false
end

#map(value) ⇒ Object



123
124
125
# File 'lib/search_cop_grammar/attributes.rb', line 123

def map(value)
  value
end

#respond_to_missing?(*args) ⇒ Boolean

Returns:



155
156
157
# File 'lib/search_cop_grammar/attributes.rb', line 155

def respond_to_missing?(*args)
  @attribute.respond_to?(*args) || super
end