activegroonga 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS.ja.rdoc +17 -0
- data/NEWS.rdoc +17 -0
- data/Rakefile +9 -10
- data/lib/active_groonga/base.rb +26 -7
- data/lib/active_groonga/version.rb +1 -1
- data/lib/rails/generators/active_groonga/migration/migration_generator.rb +1 -1
- data/lib/rails/generators/active_groonga/model/model_generator.rb +56 -4
- data/lib/rails/generators/active_groonga/model/templates/migration.rb +4 -4
- data/test/test-base.rb +7 -0
- metadata +4 -4
data/NEWS.ja.rdoc
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
= お知らせ
|
2
2
|
|
3
|
+
== 1.0.1: 2010-11-29
|
4
|
+
|
5
|
+
=== 改良
|
6
|
+
|
7
|
+
* ジェネレータ: テーブルの種類の指定に対応。
|
8
|
+
* ActiveGroonga::Base.exists?を追加。
|
9
|
+
* ActiveGroonga::Base.allを追加。
|
10
|
+
|
11
|
+
=== 変更
|
12
|
+
|
13
|
+
* ハッシュテーブル・パトリシアトライを利用しているときはレコード識別子
|
14
|
+
としてIDではなくキーを使うように変更。
|
15
|
+
|
16
|
+
== 1.0.0: 2010-11-29
|
17
|
+
|
18
|
+
* Rails 3対応
|
19
|
+
|
3
20
|
== 0.0.7: 2009-10-02
|
4
21
|
|
5
22
|
* Ruby/groonga 0.0.7対応
|
data/NEWS.rdoc
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
= NEWS
|
2
2
|
|
3
|
+
== 1.0.1: 2010-11-29
|
4
|
+
|
5
|
+
=== Improvments
|
6
|
+
|
7
|
+
* generator: Supported table type customize.
|
8
|
+
* Added ActiveGroonga::Base.exists?.
|
9
|
+
* Added ActiveGroonga::Base.all.
|
10
|
+
|
11
|
+
=== Changes
|
12
|
+
|
13
|
+
* Changed to use record key instead of record ID for record
|
14
|
+
identifier for hash table and patricia trie.
|
15
|
+
|
16
|
+
== 1.0.0: 2010-11-29
|
17
|
+
|
18
|
+
* Support Rails 3.
|
19
|
+
|
3
20
|
== 0.0.7: 2009-10-02
|
4
21
|
|
5
22
|
* Support Ruby/groonga 0.0.7.
|
data/Rakefile
CHANGED
@@ -34,12 +34,12 @@ truncate_base_dir = Proc.new do |x|
|
|
34
34
|
x.gsub(/^#{Regexp.escape(base_dir + File::SEPARATOR)}/, '')
|
35
35
|
end
|
36
36
|
|
37
|
-
@
|
38
|
-
|
39
|
-
|
40
|
-
$LOAD_PATH.unshift(
|
41
|
-
$LOAD_PATH.unshift(
|
42
|
-
ENV["RUBYLIB"] = "#{
|
37
|
+
@rroonga_base_dir = File.expand_path(File.join(base_dir, '..', 'rroonga'))
|
38
|
+
rroonga_ext_dir = File.join(@rroonga_base_dir, 'ext', "groonga")
|
39
|
+
rroonga_lib_dir = File.join(@rroonga_base_dir, 'lib')
|
40
|
+
$LOAD_PATH.unshift(rroonga_ext_dir)
|
41
|
+
$LOAD_PATH.unshift(rroonga_lib_dir)
|
42
|
+
ENV["RUBYLIB"] = "#{rroonga_lib_dir}:#{rroonga_ext_dir}:#{ENV['RUBYLIB']}"
|
43
43
|
|
44
44
|
active_groonga_lib_dir = File.join(base_dir, "lib")
|
45
45
|
$LOAD_PATH.unshift(active_groonga_lib_dir)
|
@@ -164,7 +164,7 @@ def apply_template(file, head, header, footer)
|
|
164
164
|
end
|
165
165
|
|
166
166
|
def erb_template(name)
|
167
|
-
file = File.join(@
|
167
|
+
file = File.join(@rroonga_base_dir, "html", "#{name}.html.erb")
|
168
168
|
template = File.read(file)
|
169
169
|
erb = ERB.new(template, nil, "-")
|
170
170
|
erb.filename = file
|
@@ -182,10 +182,9 @@ task :prepare_docs_for_publishing do
|
|
182
182
|
end
|
183
183
|
end
|
184
184
|
|
185
|
+
desc "Tag the current revision."
|
185
186
|
task :tag do
|
186
|
-
|
187
|
-
sh("svn cp -m 'release #{version}!!!' " +
|
188
|
-
"#{repository}/trunk #{repository}/tags/#{version}")
|
187
|
+
sh("git tag -a #{version} -m 'release #{version}!!!'")
|
189
188
|
end
|
190
189
|
|
191
190
|
desc "generate activegroonga.gemspec"
|
data/lib/active_groonga/base.rb
CHANGED
@@ -79,17 +79,32 @@ module ActiveGroonga
|
|
79
79
|
instantiate(record)
|
80
80
|
end
|
81
81
|
|
82
|
-
def
|
83
|
-
if
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
ResultSet.new(records, self, :expression => records.expression)
|
82
|
+
def exists?(record_id)
|
83
|
+
record_id = record_id.record_id if record_id.respond_to?(:record_id)
|
84
|
+
if table.support_key?
|
85
|
+
not table[record_id].nil?
|
88
86
|
else
|
89
|
-
|
87
|
+
begin
|
88
|
+
record_id = Integer(record_id)
|
89
|
+
rescue ArgumentError
|
90
|
+
return false
|
91
|
+
end
|
92
|
+
table.exist?(record_id)
|
90
93
|
end
|
91
94
|
end
|
92
95
|
|
96
|
+
def select(options={})
|
97
|
+
return all(options) unless block_given?
|
98
|
+
records = table.select do |record|
|
99
|
+
yield(record)
|
100
|
+
end
|
101
|
+
ResultSet.new(records, self, :expression => records.expression)
|
102
|
+
end
|
103
|
+
|
104
|
+
def all(options={})
|
105
|
+
ResultSet.new(table, self)
|
106
|
+
end
|
107
|
+
|
93
108
|
def count
|
94
109
|
table.size
|
95
110
|
end
|
@@ -238,6 +253,10 @@ module ActiveGroonga
|
|
238
253
|
id
|
239
254
|
end
|
240
255
|
|
256
|
+
def to_key
|
257
|
+
persisted? ? [record_id] : nil
|
258
|
+
end
|
259
|
+
|
241
260
|
def attributes
|
242
261
|
@attributes
|
243
262
|
end
|
@@ -43,7 +43,7 @@ module ActiveGroonga
|
|
43
43
|
|
44
44
|
private
|
45
45
|
def parse_columns! #:nodoc:
|
46
|
-
self.columns = (columns || []).
|
46
|
+
self.columns = (columns || []).collect do |key_value|
|
47
47
|
name, type, *options = key_value.split(':')
|
48
48
|
Column.new(name, type, options)
|
49
49
|
end
|
@@ -14,14 +14,13 @@
|
|
14
14
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
15
15
|
|
16
16
|
require 'rails/generators/active_groonga'
|
17
|
+
require 'rails/generators/active_groonga/migration/column'
|
17
18
|
|
18
19
|
module ActiveGroonga
|
19
20
|
module Generators
|
20
21
|
class ModelGenerator < Base
|
21
|
-
argument(:
|
22
|
-
:
|
23
|
-
:default => [],
|
24
|
-
:banner => "field:type field:type")
|
22
|
+
argument(:columns, :type => :array, :default => [],
|
23
|
+
:banner => "name:type[:option:option] name:type[:option:option]")
|
25
24
|
|
26
25
|
check_class_collision
|
27
26
|
|
@@ -31,6 +30,15 @@ module ActiveGroonga
|
|
31
30
|
:type => :string,
|
32
31
|
:desc => "The parent class for the generated model")
|
33
32
|
|
33
|
+
def initialize(args, *options)
|
34
|
+
super
|
35
|
+
@key = nil
|
36
|
+
@table_type = nil
|
37
|
+
@key_normalize = false
|
38
|
+
@default_tokenizer = nil
|
39
|
+
parse_columns!
|
40
|
+
end
|
41
|
+
|
34
42
|
def create_migration_file
|
35
43
|
return unless options[:migration] && options[:parent].nil?
|
36
44
|
migration_template("migration.rb",
|
@@ -49,12 +57,56 @@ module ActiveGroonga
|
|
49
57
|
end
|
50
58
|
end
|
51
59
|
|
60
|
+
def create_table_code
|
61
|
+
code = "create_table(:#{table_name}"
|
62
|
+
options = []
|
63
|
+
options << ":type => :#{@table_type}" if @table_type
|
64
|
+
options << ":key_type => \"#{@key}\"" if @key
|
65
|
+
options << ":key_normalize => #{@key_normalize}" if @key_normalize
|
66
|
+
options << ":default_tokenizer => \"#{@tokenizer}\"" if @tokenizer
|
67
|
+
code << ", #{options.join(', ')}" unless options.empty?
|
68
|
+
code << ")"
|
69
|
+
code
|
70
|
+
end
|
71
|
+
|
72
|
+
def remove_table_code
|
73
|
+
"remove_table(:#{table_name})"
|
74
|
+
end
|
75
|
+
|
52
76
|
hook_for :test_framework
|
53
77
|
|
54
78
|
protected
|
55
79
|
def parent_class_name
|
56
80
|
options[:parent] || "ActiveGroonga::Base"
|
57
81
|
end
|
82
|
+
|
83
|
+
private
|
84
|
+
def parse_columns! #:nodoc:
|
85
|
+
parsed_columns = []
|
86
|
+
(columns || []).each do |key_value|
|
87
|
+
name, type, *options = key_value.split(':')
|
88
|
+
case name
|
89
|
+
when "key"
|
90
|
+
@key = Groonga::Schema.normalize_type(type)
|
91
|
+
@table_type = options.find do |option|
|
92
|
+
["hash", "patricia_trie"].include?(option)
|
93
|
+
end
|
94
|
+
key_normalize = options.include?("normalize")
|
95
|
+
@table_type ||= @key_normalize ? "patricia_trie" : "hash"
|
96
|
+
if @table_type == "patricia_trie"
|
97
|
+
@key_normalize = key_normalize
|
98
|
+
end
|
99
|
+
tokenizer_label_index = options.index("tokenizer")
|
100
|
+
if tokenizer_label_index
|
101
|
+
tokenizer = options[tokenizer_label_index + 1]
|
102
|
+
@tokenizer = Groonga::Schema.normalize_type(tokenizer)
|
103
|
+
end
|
104
|
+
else
|
105
|
+
parsed_columns << Column.new(name, type, options)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
self.columns = parsed_columns
|
109
|
+
end
|
58
110
|
end
|
59
111
|
end
|
60
112
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class <%= migration_class_name %> < ActiveGroonga::Migration
|
2
2
|
def up
|
3
|
-
|
4
|
-
<%
|
5
|
-
table.<%=
|
3
|
+
<%= create_table_code %> do |table|
|
4
|
+
<% columns.each do |column| -%>
|
5
|
+
table.<%= column.create_code %>
|
6
6
|
<% end -%>
|
7
7
|
<% if options[:timestamps] -%>
|
8
8
|
table.timestamps
|
@@ -11,6 +11,6 @@ class <%= migration_class_name %> < ActiveGroonga::Migration
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def down
|
14
|
-
|
14
|
+
<%= remove_table_code %>
|
15
15
|
end
|
16
16
|
end
|
data/test/test-base.rb
CHANGED
@@ -209,4 +209,11 @@ class TestBase < Test::Unit::TestCase
|
|
209
209
|
assert_equal([google],
|
210
210
|
Bookmark.select {|record| record.content =~ "Google"}.to_a)
|
211
211
|
end
|
212
|
+
|
213
|
+
def test_exists?
|
214
|
+
daijiro = @user_records[:daijiro]
|
215
|
+
assert_true(User.exists?(daijiro.record_id))
|
216
|
+
daijiro.delete
|
217
|
+
assert_false(User.exists?(daijiro.record_id))
|
218
|
+
end
|
212
219
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activegroonga
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kouhei Sutou
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-29 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|