diff options
Diffstat (limited to 'vendor/plugins/thinking-sphinx/lib/thinking_sphinx/rails_additions.rb')
| -rw-r--r-- | vendor/plugins/thinking-sphinx/lib/thinking_sphinx/rails_additions.rb | 136 |
1 files changed, 0 insertions, 136 deletions
diff --git a/vendor/plugins/thinking-sphinx/lib/thinking_sphinx/rails_additions.rb b/vendor/plugins/thinking-sphinx/lib/thinking_sphinx/rails_additions.rb deleted file mode 100644 index c7db0a1..0000000 --- a/vendor/plugins/thinking-sphinx/lib/thinking_sphinx/rails_additions.rb +++ /dev/null | |||
| @@ -1,136 +0,0 @@ | |||
| 1 | module ThinkingSphinx | ||
| 2 | module HashExcept | ||
| 3 | # Returns a new hash without the given keys. | ||
| 4 | def except(*keys) | ||
| 5 | rejected = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys) | ||
| 6 | reject { |key,| rejected.include?(key) } | ||
| 7 | end | ||
| 8 | |||
| 9 | # Replaces the hash without only the given keys. | ||
| 10 | def except!(*keys) | ||
| 11 | replace(except(*keys)) | ||
| 12 | end | ||
| 13 | end | ||
| 14 | end | ||
| 15 | |||
| 16 | Hash.send( | ||
| 17 | :include, ThinkingSphinx::HashExcept | ||
| 18 | ) unless Hash.instance_methods.include?("except") | ||
| 19 | |||
| 20 | module ThinkingSphinx | ||
| 21 | module ArrayExtractOptions | ||
| 22 | def extract_options! | ||
| 23 | last.is_a?(::Hash) ? pop : {} | ||
| 24 | end | ||
| 25 | end | ||
| 26 | end | ||
| 27 | |||
| 28 | Array.send( | ||
| 29 | :include, ThinkingSphinx::ArrayExtractOptions | ||
| 30 | ) unless Array.instance_methods.include?("extract_options!") | ||
| 31 | |||
| 32 | module ThinkingSphinx | ||
| 33 | module AbstractQuotedTableName | ||
| 34 | def quote_table_name(name) | ||
| 35 | quote_column_name(name) | ||
| 36 | end | ||
| 37 | end | ||
| 38 | end | ||
| 39 | |||
| 40 | ActiveRecord::ConnectionAdapters::AbstractAdapter.send( | ||
| 41 | :include, ThinkingSphinx::AbstractQuotedTableName | ||
| 42 | ) unless ActiveRecord::ConnectionAdapters::AbstractAdapter.instance_methods.include?("quote_table_name") | ||
| 43 | |||
| 44 | module ThinkingSphinx | ||
| 45 | module MysqlQuotedTableName | ||
| 46 | def quote_table_name(name) #:nodoc: | ||
| 47 | quote_column_name(name).gsub('.', '`.`') | ||
| 48 | end | ||
| 49 | end | ||
| 50 | end | ||
| 51 | |||
| 52 | if ActiveRecord::ConnectionAdapters.constants.include?("MysqlAdapter") or ActiveRecord::Base.respond_to?(:jdbcmysql_connection) | ||
| 53 | adapter = ActiveRecord::ConnectionAdapters.const_get( | ||
| 54 | defined?(JRUBY_VERSION) ? :JdbcAdapter : :MysqlAdapter | ||
| 55 | ) | ||
| 56 | unless adapter.instance_methods.include?("quote_table_name") | ||
| 57 | adapter.send(:include, ThinkingSphinx::MysqlQuotedTableName) | ||
| 58 | end | ||
| 59 | end | ||
| 60 | |||
| 61 | module ThinkingSphinx | ||
| 62 | module ActiveRecordQuotedName | ||
| 63 | def quoted_table_name | ||
| 64 | self.connection.quote_table_name(self.table_name) | ||
| 65 | end | ||
| 66 | end | ||
| 67 | end | ||
| 68 | |||
| 69 | ActiveRecord::Base.extend( | ||
| 70 | ThinkingSphinx::ActiveRecordQuotedName | ||
| 71 | ) unless ActiveRecord::Base.respond_to?("quoted_table_name") | ||
| 72 | |||
| 73 | module ThinkingSphinx | ||
| 74 | module ActiveRecordStoreFullSTIClass | ||
| 75 | def store_full_sti_class | ||
| 76 | false | ||
| 77 | end | ||
| 78 | end | ||
| 79 | end | ||
| 80 | |||
| 81 | ActiveRecord::Base.extend( | ||
| 82 | ThinkingSphinx::ActiveRecordStoreFullSTIClass | ||
| 83 | ) unless ActiveRecord::Base.respond_to?(:store_full_sti_class) | ||
| 84 | |||
| 85 | module ThinkingSphinx | ||
| 86 | module ClassAttributeMethods | ||
| 87 | def cattr_reader(*syms) | ||
| 88 | syms.flatten.each do |sym| | ||
| 89 | next if sym.is_a?(Hash) | ||
| 90 | class_eval(<<-EOS, __FILE__, __LINE__) | ||
| 91 | unless defined? @@#{sym} | ||
| 92 | @@#{sym} = nil | ||
| 93 | end | ||
| 94 | |||
| 95 | def self.#{sym} | ||
| 96 | @@#{sym} | ||
| 97 | end | ||
| 98 | |||
| 99 | def #{sym} | ||
| 100 | @@#{sym} | ||
| 101 | end | ||
| 102 | EOS | ||
| 103 | end | ||
| 104 | end | ||
| 105 | |||
| 106 | def cattr_writer(*syms) | ||
| 107 | options = syms.extract_options! | ||
| 108 | syms.flatten.each do |sym| | ||
| 109 | class_eval(<<-EOS, __FILE__, __LINE__) | ||
| 110 | unless defined? @@#{sym} | ||
| 111 | @@#{sym} = nil | ||
| 112 | end | ||
| 113 | |||
| 114 | def self.#{sym}=(obj) | ||
| 115 | @@#{sym} = obj | ||
| 116 | end | ||
| 117 | |||
| 118 | #{" | ||
| 119 | def #{sym}=(obj) | ||
| 120 | @@#{sym} = obj | ||
| 121 | end | ||
| 122 | " unless options[:instance_writer] == false } | ||
| 123 | EOS | ||
| 124 | end | ||
| 125 | end | ||
| 126 | |||
| 127 | def cattr_accessor(*syms) | ||
| 128 | cattr_reader(*syms) | ||
| 129 | cattr_writer(*syms) | ||
| 130 | end | ||
| 131 | end | ||
| 132 | end | ||
| 133 | |||
| 134 | Class.extend( | ||
| 135 | ThinkingSphinx::ClassAttributeMethods | ||
| 136 | ) unless Class.respond_to?(:cattr_reader) | ||
