tdiary-io-mongodb 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/.travis.yml +8 -0
- data/Rakefile +5 -0
- data/bin/tdiary-mongodb-convert +88 -0
- data/lib/tdiary/io/mongodb.rb +63 -0
- data/spec/tdiary/io/mongodb_spec.rb +46 -2
- data/tdiary-io-mongodb.gemspec +2 -1
- metadata +21 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 114f562916eb47fba2815a72cb0a4aed1a028f5e
|
4
|
+
data.tar.gz: f41a5913047cf0c763f6831f6c64a2fbeb98476d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f64701eff4db012e0d29403ae3213a90e49168f25aca9ff8e619719f0b0e8f616afb6ebc8969b4a68c2b158e42d849717593bbda0e6c085ee55dc44370442f5a
|
7
|
+
data.tar.gz: 30e2ff164dee5657d62e0baceac33a53a98daa7df64894839cbf413d55edeffd42853021fb3bd85dbbcb352787563002e9bdc85b24c3acaf80de0e30a6f403e1
|
data/.travis.yml
ADDED
data/Rakefile
CHANGED
@@ -0,0 +1,88 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'erb'
|
5
|
+
require 'tdiary/view_helper'
|
6
|
+
require 'tdiary/base'
|
7
|
+
require 'tdiary/comment'
|
8
|
+
require 'tdiary/comment_manager'
|
9
|
+
require 'tdiary/referer_manager'
|
10
|
+
require 'tdiary/style'
|
11
|
+
require 'tdiary/cache/file'
|
12
|
+
require 'ostruct'
|
13
|
+
|
14
|
+
def load_diaries(data_path, style_path)
|
15
|
+
require 'tdiary/io/default'
|
16
|
+
|
17
|
+
options = {
|
18
|
+
'style.path' => style_path
|
19
|
+
}
|
20
|
+
conf = OpenStruct.new({
|
21
|
+
data_path: "#{data_path}/",
|
22
|
+
options: options
|
23
|
+
})
|
24
|
+
tdiary = OpenStruct.new({conf: conf})
|
25
|
+
default_io = TDiary::IO::Default.new(tdiary)
|
26
|
+
|
27
|
+
default_io.calendar.each do |y, ms|
|
28
|
+
ms.each do |m|
|
29
|
+
puts "loading #{y}-#{m}"
|
30
|
+
month = Time.local(y.to_i, m.to_i)
|
31
|
+
default_io.transaction(month) do |diaries|
|
32
|
+
yield month, diaries
|
33
|
+
TDiary::TDiaryBase::DIRTY_NONE
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def update_diaries(mongodb_io, month, new_diaries)
|
40
|
+
mongodb_io.transaction(month) do |diaries|
|
41
|
+
diaries.update(new_diaries)
|
42
|
+
TDiary::TDiaryBase::DIRTY_DIARY | TDiary::TDiaryBase::DIRTY_COMMENT
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def store_diaries(data_path, style_path, mongo_url = nil)
|
47
|
+
require 'tdiary/io/mongodb'
|
48
|
+
|
49
|
+
options = {'style.path' => [style_path]}
|
50
|
+
conf = OpenStruct.new({options: options, database_url: mongo_url})
|
51
|
+
tdiary = OpenStruct.new({conf: conf})
|
52
|
+
TDiary::IO::MongoDB.load_cgi_conf(conf)
|
53
|
+
mongodb_io = TDiary::IO::MongoDB.new(tdiary)
|
54
|
+
|
55
|
+
load_diaries(data_path, style_path) do |month, diaries|
|
56
|
+
update_diaries(mongodb_io, month, diaries)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def store_conf(conf_path, mongo_url = nil)
|
61
|
+
require 'tdiary/io/mongodb'
|
62
|
+
|
63
|
+
conf = OpenStruct.new({options: {}, database_url: mongo_url})
|
64
|
+
tdiary = OpenStruct.new({conf: conf})
|
65
|
+
|
66
|
+
TDiary::IO::MongoDB.save_cgi_conf(conf, open(conf_path, &:read))
|
67
|
+
end
|
68
|
+
|
69
|
+
args = {}
|
70
|
+
OptionParser.new do |opts|
|
71
|
+
opts.banner = 'Usage: tdiary-mongodb-convert [options] <data_path>'
|
72
|
+
opts.on('-c CONF', '--conf=CONF', 'store only tdiary.conf'){|v| args[:conf] = v}
|
73
|
+
opts.on('-s PATH', '--style=STYLE', 'style path'){|v| args[:style] = v}
|
74
|
+
opts.on('-m URL', '--mongo=URL', 'URL of mongoDB'){|v| args[:mongo] = v}
|
75
|
+
opts.parse!(ARGV)
|
76
|
+
|
77
|
+
args[:data] = ARGV.shift
|
78
|
+
unless args[:data] || args[:conf]
|
79
|
+
$stderr.print opts.help
|
80
|
+
exit 1
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
if args[:conf]
|
85
|
+
store_conf(args[:conf], args[:mongo])
|
86
|
+
else
|
87
|
+
store_diaries(args[:data], args[:style], args[:mongo])
|
88
|
+
end
|
data/lib/tdiary/io/mongodb.rb
CHANGED
@@ -58,12 +58,50 @@ module TDiary
|
|
58
58
|
field :body, type: String
|
59
59
|
field :style, type: String
|
60
60
|
field :last_modified, type: Integer
|
61
|
+
field :visible, type: Boolean
|
61
62
|
has_many :comments, autosave: true
|
62
63
|
has_many :referers, autosave: true
|
63
64
|
|
64
65
|
index({diary_id: 1}, {unique: true})
|
65
66
|
index('comments.no' => 1)
|
66
67
|
end
|
68
|
+
|
69
|
+
class Plugin
|
70
|
+
include Mongoid::Document
|
71
|
+
include Mongoid::Timestamps
|
72
|
+
store_in collection: "plugins"
|
73
|
+
|
74
|
+
field :plugin, type: String
|
75
|
+
field :key, type: String
|
76
|
+
field :value, type: String
|
77
|
+
|
78
|
+
def self.get(plugin_name, key)
|
79
|
+
record = where(plugin: plugin_name, key: key).first
|
80
|
+
return record ? record.value : nil
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.set(plugin_name, key, value)
|
84
|
+
record = where(plugin: plugin_name, key: key).first
|
85
|
+
if record
|
86
|
+
record.update_attributes(value: value)
|
87
|
+
else
|
88
|
+
record = self.new(plugin: plugin_name, key: key, value: value)
|
89
|
+
record.save!
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.delete(plugin_name, key)
|
94
|
+
record = where(plugin: plugin_name, key: key).first
|
95
|
+
if record
|
96
|
+
record.delete
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.keys(plugin_name)
|
101
|
+
records = where(plugin: plugin_name)
|
102
|
+
return records.map(&:key) rescue []
|
103
|
+
end
|
104
|
+
end
|
67
105
|
|
68
106
|
include Cache
|
69
107
|
|
@@ -92,6 +130,31 @@ module TDiary
|
|
92
130
|
{sessions:{default:{uri:(conf.database_url || 'mongodb://localhost:27017/tdiary')}}}
|
93
131
|
)
|
94
132
|
end
|
133
|
+
|
134
|
+
def plugin_open(conf)
|
135
|
+
return nil
|
136
|
+
end
|
137
|
+
|
138
|
+
def plugin_close(storage)
|
139
|
+
# do nothing
|
140
|
+
end
|
141
|
+
|
142
|
+
def plugin_transaction(storage, plugin_name)
|
143
|
+
db = plugin_name.dup
|
144
|
+
def db.get(key)
|
145
|
+
Plugin.get(self, key)
|
146
|
+
end
|
147
|
+
def db.set(key, value)
|
148
|
+
Plugin.set(self, key, value)
|
149
|
+
end
|
150
|
+
def db.delete(key)
|
151
|
+
Plugin.delete(self, key)
|
152
|
+
end
|
153
|
+
def db.keys
|
154
|
+
Plugin.keys(self)
|
155
|
+
end
|
156
|
+
yield db
|
157
|
+
end
|
95
158
|
end
|
96
159
|
|
97
160
|
#
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe TDiary::IO::MongoDB do
|
4
|
-
it '
|
5
|
-
expect
|
4
|
+
it 'is based on TDiary::IO::Base' do
|
5
|
+
expect(TDiary::IO::MongoDB < TDiary::IO::Base).to be true
|
6
6
|
end
|
7
7
|
|
8
8
|
describe "#save_cgi_conf and #load_cgi_conf" do
|
@@ -26,6 +26,50 @@ describe TDiary::IO::MongoDB do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
describe "plugin storage support" do
|
30
|
+
it ".plugin_open returns nil" do
|
31
|
+
expect(TDiary::IO::MongoDB.plugin_open(nil)).to be nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it ".plugin_close do nothing" do
|
35
|
+
# nothing
|
36
|
+
end
|
37
|
+
|
38
|
+
describe ".plugin_transaction" do
|
39
|
+
let(:storage){ TDiary::IO::MongoDB.plugin_open(nil) }
|
40
|
+
|
41
|
+
it "store/restore data" do
|
42
|
+
TDiary::IO::MongoDB.plugin_transaction(storage, 'test_plugin') do |db|
|
43
|
+
db.set('test_key', 'test_value')
|
44
|
+
expect(db.get('test_key')).to eq('test_value')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "update data" do
|
49
|
+
TDiary::IO::MongoDB.plugin_transaction(storage, 'test_plugin') do |db|
|
50
|
+
db.set('test_key', 'test_update')
|
51
|
+
expect(db.get('test_key')).to eq('test_update')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it "delete data" do
|
56
|
+
TDiary::IO::MongoDB.plugin_transaction(storage, 'test_plugin') do |db|
|
57
|
+
db.set('test_key', 'test_delete')
|
58
|
+
db.delete('test_key')
|
59
|
+
expect(db.get('test_key')).to eq(nil)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "keys" do
|
64
|
+
TDiary::IO::MongoDB.plugin_transaction(storage, 'test_plugin') do |db|
|
65
|
+
db.set('test_key1', 'test_value1')
|
66
|
+
db.set('test_key2', 'test_value2')
|
67
|
+
expect(db.keys).to match_array ['test_key1', 'test_key2']
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
29
73
|
describe "#transaction" do
|
30
74
|
let(:io) { TDiary::IO::MongoDB.new(DummyTDiary.new) }
|
31
75
|
let(:today) { Time.now.strftime( '%Y%m%d' ) }
|
data/tdiary-io-mongodb.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "tdiary-io-mongodb"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.2"
|
8
8
|
spec.authors = ["TADA Tadashi"]
|
9
9
|
spec.email = ["t@tdtds.jp"]
|
10
10
|
spec.description = %q{MongoDB adapter for tDiary}
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
20
|
spec.add_dependency "mongoid"
|
21
|
+
spec.add_dependency "hikidoc"
|
21
22
|
|
22
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
23
24
|
spec.add_development_dependency "rake"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tdiary-io-mongodb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TADA Tadashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hikidoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -83,15 +97,18 @@ dependencies:
|
|
83
97
|
description: MongoDB adapter for tDiary
|
84
98
|
email:
|
85
99
|
- t@tdtds.jp
|
86
|
-
executables:
|
100
|
+
executables:
|
101
|
+
- tdiary-mongodb-convert
|
87
102
|
extensions: []
|
88
103
|
extra_rdoc_files: []
|
89
104
|
files:
|
90
105
|
- ".gitignore"
|
106
|
+
- ".travis.yml"
|
91
107
|
- Gemfile
|
92
108
|
- LICENSE.txt
|
93
109
|
- README.md
|
94
110
|
- Rakefile
|
111
|
+
- bin/tdiary-mongodb-convert
|
95
112
|
- lib/tdiary/io/mongodb.rb
|
96
113
|
- spec/spec_helper.rb
|
97
114
|
- spec/tdiary/io/mongodb_spec.rb
|
@@ -116,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
133
|
version: '0'
|
117
134
|
requirements: []
|
118
135
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.
|
136
|
+
rubygems_version: 2.4.5
|
120
137
|
signing_key:
|
121
138
|
specification_version: 4
|
122
139
|
summary: MongoDB adapter for tDiary
|