activegroonga 0.0.7 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. data/README.ja.rdoc +4 -1
  2. data/README.rdoc +4 -1
  3. data/Rakefile +18 -4
  4. data/lib/active_groonga.rb +25 -52
  5. data/lib/active_groonga/base.rb +164 -1480
  6. data/lib/active_groonga/callbacks.rb +26 -7
  7. data/lib/active_groonga/database.rb +55 -0
  8. data/lib/active_groonga/{dirty.rb → error.rb} +20 -10
  9. data/lib/active_groonga/locale/en.yml +5 -0
  10. data/lib/active_groonga/migration.rb +44 -113
  11. data/lib/active_groonga/migrator.rb +172 -0
  12. data/lib/active_groonga/persistence.rb +172 -0
  13. data/lib/active_groonga/railtie.rb +66 -0
  14. data/lib/active_groonga/railties/configurable.rb +47 -0
  15. data/lib/active_groonga/railties/groonga.rake +167 -0
  16. data/lib/active_groonga/result_set.rb +89 -0
  17. data/lib/active_groonga/schema.rb +54 -188
  18. data/lib/active_groonga/validations.rb +54 -5
  19. data/lib/active_groonga/vector.rb +64 -0
  20. data/lib/active_groonga/version.rb +3 -3
  21. data/lib/{active_groonga/aggregations.rb → rails/generators/active_groonga.rb} +17 -10
  22. data/lib/rails/generators/active_groonga/migration/column.rb +101 -0
  23. data/lib/rails/generators/active_groonga/migration/migration_generator.rb +53 -0
  24. data/lib/rails/generators/active_groonga/migration/templates/migration.rb +29 -0
  25. data/lib/rails/generators/active_groonga/model/model_generator.rb +60 -0
  26. data/lib/rails/generators/active_groonga/model/templates/migration.rb +16 -0
  27. data/lib/rails/generators/active_groonga/model/templates/model.rb +2 -0
  28. data/lib/rails/generators/active_groonga/model/templates/module.rb +5 -0
  29. data/test-unit-notify/COPYING +502 -0
  30. data/test-unit-notify/Rakefile +47 -0
  31. data/test-unit-notify/lib/test/unit/notify.rb +127 -0
  32. data/test-unit/COPYING +56 -0
  33. data/test-unit/GPL +340 -0
  34. data/test-unit/PSFL +271 -0
  35. data/test-unit/Rakefile +18 -5
  36. data/test-unit/html/bar.svg +153 -0
  37. data/test-unit/html/developer.svg +469 -0
  38. data/test-unit/html/favicon.ico +0 -0
  39. data/test-unit/html/favicon.svg +82 -0
  40. data/test-unit/html/heading-mark.svg +393 -0
  41. data/test-unit/html/index.html +235 -13
  42. data/test-unit/html/index.html.ja +258 -15
  43. data/test-unit/html/install.svg +636 -0
  44. data/test-unit/html/logo.svg +483 -0
  45. data/test-unit/html/test-unit.css +339 -0
  46. data/test-unit/html/tutorial.svg +559 -0
  47. data/test-unit/lib/test/unit.rb +29 -43
  48. data/test-unit/lib/test/unit/assertionfailederror.rb +11 -0
  49. data/test-unit/lib/test/unit/assertions.rb +202 -20
  50. data/test-unit/lib/test/unit/autorunner.rb +51 -20
  51. data/test-unit/lib/test/unit/collector.rb +1 -8
  52. data/test-unit/lib/test/unit/collector/dir.rb +1 -1
  53. data/test-unit/lib/test/unit/collector/load.rb +16 -9
  54. data/test-unit/lib/test/unit/color-scheme.rb +19 -3
  55. data/test-unit/lib/test/unit/diff.rb +240 -38
  56. data/test-unit/lib/test/unit/error.rb +4 -0
  57. data/test-unit/lib/test/unit/failure.rb +31 -5
  58. data/test-unit/lib/test/unit/notification.rb +8 -4
  59. data/test-unit/lib/test/unit/omission.rb +51 -3
  60. data/test-unit/lib/test/unit/pending.rb +4 -0
  61. data/test-unit/lib/test/unit/priority.rb +2 -3
  62. data/test-unit/lib/test/unit/testcase.rb +65 -7
  63. data/test-unit/lib/test/unit/testresult.rb +34 -2
  64. data/test-unit/lib/test/unit/ui/console/testrunner.rb +197 -45
  65. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +14 -0
  66. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +2 -12
  67. data/test-unit/lib/test/unit/ui/testrunner.rb +33 -0
  68. data/test-unit/lib/test/unit/util/backtracefilter.rb +1 -0
  69. data/test-unit/lib/test/unit/util/output.rb +31 -0
  70. data/test-unit/lib/test/unit/version.rb +1 -1
  71. data/test-unit/sample/{tc_adder.rb → test_adder.rb} +3 -1
  72. data/test-unit/sample/{tc_subtracter.rb → test_subtracter.rb} +3 -1
  73. data/test-unit/sample/test_user.rb +1 -0
  74. data/test-unit/test/collector/test-descendant.rb +2 -4
  75. data/test-unit/test/collector/test-load.rb +121 -8
  76. data/test-unit/test/collector/test_objectspace.rb +7 -5
  77. data/test-unit/test/run-test.rb +2 -0
  78. data/test-unit/test/test-color-scheme.rb +11 -2
  79. data/test-unit/test/test-diff.rb +48 -7
  80. data/test-unit/test/test-omission.rb +1 -1
  81. data/test-unit/test/test-testcase.rb +57 -20
  82. data/test-unit/test/test_assertions.rb +128 -13
  83. data/test-unit/test/ui/test_tap.rb +33 -0
  84. data/test-unit/test/util/test-output.rb +11 -0
  85. data/test/active-groonga-test-utils.rb +50 -36
  86. data/test/fixtures/site.rb +2 -0
  87. data/test/run-test.rb +36 -9
  88. data/test/test-associations.rb +5 -2
  89. data/test/test-base.rb +39 -31
  90. data/test/test-callbacks.rb +13 -3
  91. data/test/test-persistence.rb +53 -0
  92. data/{lib/active_groonga/observer.rb → test/test-result-set.rb} +14 -12
  93. data/test/test-schema.rb +85 -22
  94. data/{lib/active_groonga/rails_support.rb → test/test-validations.rb} +15 -13
  95. metadata +85 -52
  96. data/lib/active_groonga/associations.rb +0 -93
  97. data/lib/active_groonga/associations/belongs_to_association.rb +0 -25
  98. data/lib/active_groonga/attribute_methods.rb +0 -36
  99. data/lib/active_groonga/column.rb +0 -137
  100. data/lib/active_groonga/dynamic_record_expression_builder.rb +0 -40
  101. data/lib/active_groonga/reflection.rb +0 -30
  102. data/lib/active_groonga/schema_dumper.rb +0 -163
  103. data/lib/active_groonga/tasks.rb +0 -16
  104. data/lib/active_groonga/tasks/groonga.rake +0 -164
  105. data/lib/active_groonga/timestamp.rb +0 -30
  106. data/rails/README +0 -28
  107. data/rails/init.rb +0 -70
  108. data/rails_generators/index_table_groonga/USAGE +0 -23
  109. data/rails_generators/index_table_groonga/index_table_groonga_generator.rb +0 -44
  110. data/rails_generators/index_table_groonga/templates/migration.rb +0 -12
  111. data/rails_generators/migration_groonga/USAGE +0 -29
  112. data/rails_generators/migration_groonga/migration_groonga_generator.rb +0 -19
  113. data/rails_generators/migration_groonga/templates/migration.rb +0 -11
  114. data/rails_generators/model_groonga/USAGE +0 -28
  115. data/rails_generators/model_groonga/model_groonga_generator.rb +0 -45
  116. data/rails_generators/model_groonga/templates/fixtures.yml +0 -17
  117. data/rails_generators/model_groonga/templates/migration.rb +0 -16
  118. data/rails_generators/model_groonga/templates/model.rb +0 -2
  119. data/rails_generators/model_groonga/templates/unit_test.rb +0 -8
  120. data/test-unit/html/classic.html +0 -15
  121. data/test-unit/sample/ts_examples.rb +0 -7
  122. data/test/test-schema-dumper.rb +0 -48
@@ -1,8 +1,9 @@
1
- # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2010 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
5
- # License version 2.1 as published by the Free Software Foundation.
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License.
6
7
  #
7
8
  # This library is distributed in the hope that it will be useful,
8
9
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,19 +14,20 @@
13
14
  # License along with this library; if not, write to the Free Software
14
15
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
16
 
16
- class Rails::Configuration
17
- attr_writer :active_groonga, :groonga_configuration_file
17
+ class TestValidations < Test::Unit::TestCase
18
+ include ActiveGroongaTestUtils
18
19
 
19
- def active_groonga
20
- @active_groonga ||= Rails::OrderedOptions.new
20
+ def test_missing_key
21
+ empty_site = Site.new
22
+ assert_false(empty_site.save)
23
+ assert_equal([message(:key, :blank)],
24
+ empty_site.errors.to_a)
21
25
  end
22
26
 
23
- def groonga_configuration_file
24
- File.join(root_path, 'config', 'groonga.yml')
25
- end
26
-
27
- def groonga_configuration
28
- require 'erb'
29
- YAML::load(ERB.new(IO.read(groonga_configuration_file)).result)
27
+ private
28
+ def message(key, type)
29
+ I18n.t(:"errors.format",
30
+ :attribute => Site.human_attribute_name(key),
31
+ :message => I18n.t(:"errors.messages.#{type}"))
30
32
  end
31
33
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activegroonga
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Kouhei Sutou
@@ -9,29 +15,41 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-10-02 00:00:00 +09:00
18
+ date: 2010-11-26 00:00:00 +09:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
- name: groonga
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ name: rroonga
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
- - - "="
27
+ - - ">="
22
28
  - !ruby/object:Gem::Version
23
- version: 0.0.7
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: activerecord
29
+ hash: 31
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 4
34
+ version: 1.0.4
27
35
  type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: activemodel
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
30
42
  requirements:
31
- - - "="
43
+ - - ">="
32
44
  - !ruby/object:Gem::Version
33
- version: 2.3.4
34
- version:
45
+ hash: 5
46
+ segments:
47
+ - 3
48
+ - 0
49
+ - 1
50
+ version: 3.0.1
51
+ type: :runtime
52
+ version_requirements: *id002
35
53
  description: |-
36
54
  groonga provides both of full text search and column store
37
55
  features. ActiveGroonga + groonga can be used as an
@@ -56,50 +74,54 @@ files:
56
74
  - README.rdoc
57
75
  - Rakefile
58
76
  - lib/active_groonga.rb
59
- - lib/active_groonga/aggregations.rb
60
- - lib/active_groonga/associations.rb
61
- - lib/active_groonga/associations/belongs_to_association.rb
62
- - lib/active_groonga/attribute_methods.rb
63
77
  - lib/active_groonga/base.rb
64
78
  - lib/active_groonga/callbacks.rb
65
- - lib/active_groonga/column.rb
66
- - lib/active_groonga/dirty.rb
67
- - lib/active_groonga/dynamic_record_expression_builder.rb
79
+ - lib/active_groonga/database.rb
80
+ - lib/active_groonga/error.rb
68
81
  - lib/active_groonga/fixtures.rb
82
+ - lib/active_groonga/locale/en.yml
69
83
  - lib/active_groonga/migration.rb
70
- - lib/active_groonga/observer.rb
71
- - lib/active_groonga/rails_support.rb
72
- - lib/active_groonga/reflection.rb
84
+ - lib/active_groonga/migrator.rb
85
+ - lib/active_groonga/persistence.rb
86
+ - lib/active_groonga/railtie.rb
87
+ - lib/active_groonga/railties/configurable.rb
88
+ - lib/active_groonga/railties/groonga.rake
89
+ - lib/active_groonga/result_set.rb
73
90
  - lib/active_groonga/schema.rb
74
- - lib/active_groonga/schema_dumper.rb
75
- - lib/active_groonga/tasks.rb
76
- - lib/active_groonga/tasks/groonga.rake
77
91
  - lib/active_groonga/test_case.rb
78
92
  - lib/active_groonga/test_help.rb
79
- - lib/active_groonga/timestamp.rb
80
93
  - lib/active_groonga/validations.rb
94
+ - lib/active_groonga/vector.rb
81
95
  - lib/active_groonga/version.rb
96
+ - lib/rails/generators/active_groonga.rb
97
+ - lib/rails/generators/active_groonga/migration/column.rb
98
+ - lib/rails/generators/active_groonga/migration/migration_generator.rb
99
+ - lib/rails/generators/active_groonga/migration/templates/migration.rb
100
+ - lib/rails/generators/active_groonga/model/model_generator.rb
101
+ - lib/rails/generators/active_groonga/model/templates/migration.rb
102
+ - lib/rails/generators/active_groonga/model/templates/model.rb
103
+ - lib/rails/generators/active_groonga/model/templates/module.rb
82
104
  - license/LGPL
83
- - rails/README
84
- - rails/init.rb
85
- - rails_generators/index_table_groonga/USAGE
86
- - rails_generators/index_table_groonga/index_table_groonga_generator.rb
87
- - rails_generators/index_table_groonga/templates/migration.rb
88
- - rails_generators/migration_groonga/USAGE
89
- - rails_generators/migration_groonga/migration_groonga_generator.rb
90
- - rails_generators/migration_groonga/templates/migration.rb
91
- - rails_generators/model_groonga/USAGE
92
- - rails_generators/model_groonga/model_groonga_generator.rb
93
- - rails_generators/model_groonga/templates/fixtures.yml
94
- - rails_generators/model_groonga/templates/migration.rb
95
- - rails_generators/model_groonga/templates/model.rb
96
- - rails_generators/model_groonga/templates/unit_test.rb
105
+ - test-unit-notify/COPYING
106
+ - test-unit-notify/Rakefile
107
+ - test-unit-notify/lib/test/unit/notify.rb
108
+ - test-unit/COPYING
109
+ - test-unit/GPL
110
+ - test-unit/PSFL
97
111
  - test-unit/Rakefile
98
112
  - test-unit/TODO
99
113
  - test-unit/bin/testrb
100
- - test-unit/html/classic.html
114
+ - test-unit/html/bar.svg
115
+ - test-unit/html/developer.svg
116
+ - test-unit/html/favicon.ico
117
+ - test-unit/html/favicon.svg
118
+ - test-unit/html/heading-mark.svg
101
119
  - test-unit/html/index.html
102
120
  - test-unit/html/index.html.ja
121
+ - test-unit/html/install.svg
122
+ - test-unit/html/logo.svg
123
+ - test-unit/html/test-unit.css
124
+ - test-unit/html/tutorial.svg
103
125
  - test-unit/lib/test/unit.rb
104
126
  - test-unit/lib/test/unit/assertionfailederror.rb
105
127
  - test-unit/lib/test/unit/assertions.rb
@@ -137,14 +159,14 @@ files:
137
159
  - test-unit/lib/test/unit/util/backtracefilter.rb
138
160
  - test-unit/lib/test/unit/util/method-owner-finder.rb
139
161
  - test-unit/lib/test/unit/util/observable.rb
162
+ - test-unit/lib/test/unit/util/output.rb
140
163
  - test-unit/lib/test/unit/util/procwrapper.rb
141
164
  - test-unit/lib/test/unit/version.rb
142
165
  - test-unit/sample/adder.rb
143
166
  - test-unit/sample/subtracter.rb
144
- - test-unit/sample/tc_adder.rb
145
- - test-unit/sample/tc_subtracter.rb
167
+ - test-unit/sample/test_adder.rb
168
+ - test-unit/sample/test_subtracter.rb
146
169
  - test-unit/sample/test_user.rb
147
- - test-unit/sample/ts_examples.rb
148
170
  - test-unit/test/collector/test-descendant.rb
149
171
  - test-unit/test/collector/test-load.rb
150
172
  - test-unit/test/collector/test_dir.rb
@@ -167,21 +189,26 @@ files:
167
189
  - test-unit/test/test_testresult.rb
168
190
  - test-unit/test/test_testsuite.rb
169
191
  - test-unit/test/testunit-test-util.rb
192
+ - test-unit/test/ui/test_tap.rb
170
193
  - test-unit/test/ui/test_testrunmediator.rb
171
194
  - test-unit/test/util/test-method-owner-finder.rb
195
+ - test-unit/test/util/test-output.rb
172
196
  - test-unit/test/util/test_backtracefilter.rb
173
197
  - test-unit/test/util/test_observable.rb
174
198
  - test-unit/test/util/test_procwrapper.rb
175
199
  - test/active-groonga-test-utils.rb
176
200
  - test/fixtures/bookmark.rb
201
+ - test/fixtures/site.rb
177
202
  - test/fixtures/task.rb
178
203
  - test/fixtures/user.rb
179
204
  - test/run-test.rb
180
205
  - test/test-associations.rb
181
206
  - test/test-base.rb
182
207
  - test/test-callbacks.rb
183
- - test/test-schema-dumper.rb
208
+ - test/test-persistence.rb
209
+ - test/test-result-set.rb
184
210
  - test/test-schema.rb
211
+ - test/test-validations.rb
185
212
  has_rdoc: true
186
213
  homepage: http://groonga.rubyforge.org/
187
214
  licenses: []
@@ -193,21 +220,27 @@ rdoc_options:
193
220
  require_paths:
194
221
  - lib
195
222
  required_ruby_version: !ruby/object:Gem::Requirement
223
+ none: false
196
224
  requirements:
197
225
  - - ">="
198
226
  - !ruby/object:Gem::Version
227
+ hash: 3
228
+ segments:
229
+ - 0
199
230
  version: "0"
200
- version:
201
231
  required_rubygems_version: !ruby/object:Gem::Requirement
232
+ none: false
202
233
  requirements:
203
234
  - - ">="
204
235
  - !ruby/object:Gem::Version
236
+ hash: 3
237
+ segments:
238
+ - 0
205
239
  version: "0"
206
- version:
207
240
  requirements: []
208
241
 
209
242
  rubyforge_project: groonga
210
- rubygems_version: 1.3.5
243
+ rubygems_version: 1.3.7
211
244
  signing_key:
212
245
  specification_version: 3
213
246
  summary: A library to use groonga with ActiveRecord like API.
@@ -1,93 +0,0 @@
1
- # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
2
- #
3
- # This library is free software; you can redistribute it and/or
4
- # modify it under the terms of the GNU Lesser General Public
5
- # License version 2.1 as published by the Free Software Foundation.
6
- #
7
- # This library is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
- # Lesser General Public License for more details.
11
- #
12
- # You should have received a copy of the GNU Lesser General Public
13
- # License along with this library; if not, write to the Free Software
14
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
-
16
- # This library includes ActiveRecord based codes temporary.
17
- # Here is their copyright and license:
18
- #
19
- # Copyright (c) 2004-2009 David Heinemeier Hansson
20
- #
21
- # Permission is hereby granted, free of charge, to any person obtaining
22
- # a copy of this software and associated documentation files (the
23
- # "Software"), to deal in the Software without restriction, including
24
- # without limitation the rights to use, copy, modify, merge, publish,
25
- # distribute, sublicense, and/or sell copies of the Software, and to
26
- # permit persons to whom the Software is furnished to do so, subject to
27
- # the following conditions:
28
- #
29
- # The above copyright notice and this permission notice shall be
30
- # included in all copies or substantial portions of the Software.
31
- #
32
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39
-
40
- module ActiveGroonga
41
- module Associations
42
- class << self
43
- def included(base)
44
- base.class_eval do
45
- include(ActiveRecord::Associations)
46
- extend(ClassMethods)
47
- end
48
- end
49
- end
50
-
51
- autoload :BelongsToAssociation, 'active_groonga/associations/belongs_to_association'
52
-
53
- module ClassMethods
54
- # from ActiveRecord
55
- def belongs_to(association_id, options = {})
56
- reflection = create_belongs_to_reflection(association_id, options)
57
-
58
- if reflection.options[:polymorphic]
59
- association_accessor_methods(reflection, BelongsToPolymorphicAssociation)
60
- else
61
- association_accessor_methods(reflection, BelongsToAssociation)
62
- association_constructor_method(:build, reflection, BelongsToAssociation)
63
- association_constructor_method(:create, reflection, BelongsToAssociation)
64
- end
65
-
66
- # Create the callbacks to update counter cache
67
- if options[:counter_cache]
68
- cache_column = reflection.counter_cache_column
69
-
70
- method_name = "belongs_to_counter_cache_after_create_for_#{reflection.name}".to_sym
71
- define_method(method_name) do
72
- association = send(reflection.name)
73
- association.class.increment_counter(cache_column, send(reflection.primary_key_name)) unless association.nil?
74
- end
75
- after_create method_name
76
-
77
- method_name = "belongs_to_counter_cache_before_destroy_for_#{reflection.name}".to_sym
78
- define_method(method_name) do
79
- association = send(reflection.name)
80
- association.class.decrement_counter(cache_column, send(reflection.primary_key_name)) unless association.nil?
81
- end
82
- before_destroy method_name
83
-
84
- module_eval(
85
- "#{reflection.class_name}.send(:attr_readonly,\"#{cache_column}\".intern) if defined?(#{reflection.class_name}) && #{reflection.class_name}.respond_to?(:attr_readonly)"
86
- )
87
- end
88
-
89
- configure_dependency_for_belongs_to(reflection)
90
- end
91
- end
92
- end
93
- end
@@ -1,25 +0,0 @@
1
- # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
2
- #
3
- # This library is free software; you can redistribute it and/or
4
- # modify it under the terms of the GNU Lesser General Public
5
- # License version 2.1 as published by the Free Software Foundation.
6
- #
7
- # This library is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
- # Lesser General Public License for more details.
11
- #
12
- # You should have received a copy of the GNU Lesser General Public
13
- # License along with this library; if not, write to the Free Software
14
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
-
16
- module ActiveGroonga
17
- module Associations
18
- class BelongsToAssociation < ActiveRecord::Associations::BelongsToAssociation
19
- def find_target
20
- @reflection.klass.find(@owner.id,
21
- :readonly => @reflection.options[:readonly])
22
- end
23
- end
24
- end
25
- end
@@ -1,36 +0,0 @@
1
- # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
2
- #
3
- # This library is free software; you can redistribute it and/or
4
- # modify it under the terms of the GNU Lesser General Public
5
- # License version 2.1 as published by the Free Software Foundation.
6
- #
7
- # This library is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
- # Lesser General Public License for more details.
11
- #
12
- # You should have received a copy of the GNU Lesser General Public
13
- # License along with this library; if not, write to the Free Software
14
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
-
16
- module ActiveGroonga
17
- module AttributeMethods
18
- def self.included(base)
19
- base.module_eval do
20
- include ActiveRecord::AttributeMethods
21
- extend AttributeMethods::ClassMethods
22
- end
23
- end
24
-
25
- module ClassMethods
26
- def instance_method_already_implemented?(method_name)
27
- method_name = method_name.to_s
28
- return true if method_name =~ /^id(=$|\?$|$)/
29
- @_defined_class_methods ||= ancestors.first(ancestors.index(ActiveGroonga::Base)).sum([]) { |m| m.public_instance_methods(false) | m.private_instance_methods(false) | m.protected_instance_methods(false) }.map(&:to_s).to_set
30
- @@_defined_activegroonga_methods ||= (ActiveGroonga::Base.public_instance_methods(false) | ActiveGroonga::Base.private_instance_methods(false) | ActiveGroonga::Base.protected_instance_methods(false)).map(&:to_s).to_set
31
- raise DangerousAttributeError, "#{method_name} is defined by ActiveGroonga" if @@_defined_activegroonga_methods.include?(method_name)
32
- @_defined_class_methods.include?(method_name)
33
- end
34
- end
35
- end
36
- end
@@ -1,137 +0,0 @@
1
- # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
2
- #
3
- # This library is free software; you can redistribute it and/or
4
- # modify it under the terms of the GNU Lesser General Public
5
- # License version 2.1 as published by the Free Software Foundation.
6
- #
7
- # This library is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
- # Lesser General Public License for more details.
11
- #
12
- # You should have received a copy of the GNU Lesser General Public
13
- # License along with this library; if not, write to the Free Software
14
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
-
16
- module ActiveGroonga
17
- class Column < ActiveRecord::ConnectionAdapters::Column
18
- # Instantiates a new column in the table.
19
- #
20
- # +column+ is the Groonga::Column.
21
- def initialize(column)
22
- @column = column
23
- @name = column.name.split(/\./, 2)[1]
24
- @type = detect_type
25
- end
26
-
27
- def id?
28
- false
29
- end
30
-
31
- def type_cast(value)
32
- return nil if value.nil?
33
- case type
34
- when :references
35
- if value.is_a?(ActiveGroonga::Base)
36
- value
37
- else
38
- reference_object_class.find(value)
39
- end
40
- else
41
- super
42
- end
43
- end
44
-
45
- def type_cast_code(var_name)
46
- case type
47
- when :references
48
- "#{reference_object_class.name}.find(#{var_name})"
49
- else
50
- super
51
- end
52
- end
53
-
54
- def number?
55
- super or type == :unsigned_integer
56
- end
57
-
58
- def quote(value)
59
- case value
60
- when ActiveGroonga::Base
61
- Groonga::Record.new(value.class.table, value.id)
62
- else
63
- value
64
- end
65
- end
66
-
67
- def index?
68
- @type == :index
69
- end
70
-
71
- def index_sources
72
- if @column
73
- @column.sources
74
- else
75
- []
76
- end
77
- end
78
-
79
- def reference_type?
80
- @type == :references
81
- end
82
-
83
- def reference_object_name
84
- return nil unless reference_type?
85
- @column.range.name.gsub(/(?:\A<table:|>\z)/, '')
86
- end
87
-
88
- def reference_object_class
89
- table_name = reference_object_name
90
- return nil if table_name.nil?
91
- table_name.camelcase.singularize.constantize
92
- end
93
-
94
- private
95
- def detect_type
96
- return :index if @column.is_a?(Groonga::IndexColumn)
97
- case @column.range
98
- when Groonga::Type
99
- case @column.range.id
100
- when Groonga::Type::INT32
101
- :integer
102
- when Groonga::Type::UINT32, Groonga::Type::UINT64
103
- :unsigned_integer
104
- when Groonga::Type::INT64
105
- :decimal
106
- when Groonga::Type::FLOAT
107
- :float
108
- when Groonga::Type::TIME
109
- :time
110
- when Groonga::Type::SHORT_TEXT
111
- :string
112
- when Groonga::Type::TEXT, Groonga::Type::LONG_TEXT
113
- :text
114
- else
115
- :string
116
- end
117
- when Groonga::Table
118
- :references
119
- else
120
- :string
121
- end
122
- end
123
- end
124
-
125
- class IdColumn < Column
126
- def initialize(table)
127
- @column = nil
128
- @table = table
129
- @name = "id"
130
- @type = :unsigned_integer
131
- end
132
-
133
- def id?
134
- true
135
- end
136
- end
137
- end