Method: ThinkingSphinx::Index::FauxColumn#method_missing
- Defined in:
- lib/thinking_sphinx/index/faux_column.rb
#method_missing(method, *args) ⇒ Object
This handles any ‘invalid’ method calls and sets them as the name, and pushing the previous name into the stack. The object returns itself.
If there’s a single argument, it becomes the name, and the method symbol goes into the stack as well. Multiple arguments means new columns with the original stack and new names (from each argument) gets returned.
Easier to explain with examples:
col = FauxColumn.new :a, :b, :c
col.__name #=> :c
col.__stack #=> [:a, :b]
col.whatever #=> col
col.__name #=> :whatever
col.__stack #=> [:a, :b, :c]
col.something(:id) #=> col
col.__name #=> :id
col.__stack #=> [:a, :b, :c, :whatever, :something]
cols = col.short(:x, :y, :z)
cols[0].__name #=> :x
cols[0].__stack #=> [:a, :b, :c, :whatever, :something, :short]
cols[1].__name #=> :y
cols[1].__stack #=> [:a, :b, :c, :whatever, :something, :short]
cols[2].__name #=> :z
cols[2].__stack #=> [:a, :b, :c, :whatever, :something, :short]
Also, this allows method chaining to build up a relevant stack:
col = FauxColumn.new :a, :b
col.__name #=> :b
col.__stack #=> [:a]
col.one.two.three #=> col
col.__name #=> :three
col.__stack #=> [:a, :b, :one, :two]
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/thinking_sphinx/index/faux_column.rb', line 102 def method_missing(method, *args) @stack << @name @name = method if (args.empty?) self elsif (args.length == 1) method_missing(args.first) else args.collect { |arg| FauxColumn.new(@stack + [@name, arg]) } end end |