summaryrefslogtreecommitdiff
path: root/vendor/plugins/thinking-sphinx/lib/thinking_sphinx/rails_additions.rb
diff options
context:
space:
mode:
authorUser <hukl@cccms.ccc.de>2011-02-10 14:23:36 +0100
committerUser <hukl@cccms.ccc.de>2011-02-10 14:23:36 +0100
commit384b187e9e067ddf2bb4d5fad0c2deaf96f69c89 (patch)
treecf743f377d3e2e28a31ae0359d95f37beba82cc3 /vendor/plugins/thinking-sphinx/lib/thinking_sphinx/rails_additions.rb
parent3d0de09cf94cee6233b36a7f5ce20d5059854acc (diff)
parentcec2b1e2881db0000b2a09029154bea0fc62ade3 (diff)
Merge branch 'master' of ssh://svn.medienhaus.udk-berlin.de/usr/local/git/cccms
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.rb136
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 @@
1module 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
14end
15
16Hash.send(
17 :include, ThinkingSphinx::HashExcept
18) unless Hash.instance_methods.include?("except")
19
20module ThinkingSphinx
21 module ArrayExtractOptions
22 def extract_options!
23 last.is_a?(::Hash) ? pop : {}
24 end
25 end
26end
27
28Array.send(
29 :include, ThinkingSphinx::ArrayExtractOptions
30) unless Array.instance_methods.include?("extract_options!")
31
32module ThinkingSphinx
33 module AbstractQuotedTableName
34 def quote_table_name(name)
35 quote_column_name(name)
36 end
37 end
38end
39
40ActiveRecord::ConnectionAdapters::AbstractAdapter.send(
41 :include, ThinkingSphinx::AbstractQuotedTableName
42) unless ActiveRecord::ConnectionAdapters::AbstractAdapter.instance_methods.include?("quote_table_name")
43
44module ThinkingSphinx
45 module MysqlQuotedTableName
46 def quote_table_name(name) #:nodoc:
47 quote_column_name(name).gsub('.', '`.`')
48 end
49 end
50end
51
52if 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
59end
60
61module ThinkingSphinx
62 module ActiveRecordQuotedName
63 def quoted_table_name
64 self.connection.quote_table_name(self.table_name)
65 end
66 end
67end
68
69ActiveRecord::Base.extend(
70 ThinkingSphinx::ActiveRecordQuotedName
71) unless ActiveRecord::Base.respond_to?("quoted_table_name")
72
73module ThinkingSphinx
74 module ActiveRecordStoreFullSTIClass
75 def store_full_sti_class
76 false
77 end
78 end
79end
80
81ActiveRecord::Base.extend(
82 ThinkingSphinx::ActiveRecordStoreFullSTIClass
83) unless ActiveRecord::Base.respond_to?(:store_full_sti_class)
84
85module 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
132end
133
134Class.extend(
135 ThinkingSphinx::ClassAttributeMethods
136) unless Class.respond_to?(:cattr_reader)