active_metadata 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/config/active_metadata.yml +0 -2
- data/db/development.sqlite3 +0 -0
- data/db/test.sqlite3 +0 -0
- data/lib/active_metadata/base.rb +1 -3
- data/lib/active_metadata/persistence/persistence.rb +2 -6
- data/lib/active_metadata/version.rb +1 -1
- data/spec/active_metadata_spec.rb +12 -182
- data/spec/spec_helper.rb +0 -21
- metadata +21 -48
- data/lib/active_metadata/persistence/mongoid/attachment.rb +0 -45
- data/lib/active_metadata/persistence/mongoid/history.rb +0 -26
- data/lib/active_metadata/persistence/mongoid/note.rb +0 -48
- data/lib/active_metadata/persistence/mongoid/watcher.rb +0 -43
- data/lib/active_metadata/persistence/mongoid.rb +0 -30
data/config/active_metadata.yml
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
development:
|
2
|
-
persists_with: "active_record"
|
3
2
|
history_skip_fields:
|
4
3
|
- 'id'
|
5
4
|
- 'created_at'
|
@@ -8,7 +7,6 @@ development:
|
|
8
7
|
attachment_base_url: "/system/metadata_attachments"
|
9
8
|
|
10
9
|
test:
|
11
|
-
persists_with: "active_record"
|
12
10
|
history_skip_fields:
|
13
11
|
- 'id'
|
14
12
|
- 'created_at'
|
data/db/development.sqlite3
CHANGED
Binary file
|
data/db/test.sqlite3
CHANGED
Binary file
|
data/lib/active_metadata/base.rb
CHANGED
@@ -5,9 +5,7 @@ module ActiveMetadata
|
|
5
5
|
## Define ModelMethods
|
6
6
|
module Base
|
7
7
|
|
8
|
-
require '
|
9
|
-
require 'mongoid_paperclip' if ActiveMetadata::CONFIG['persists_with'] == 'mongoid'
|
10
|
-
require 'paperclip' if ActiveMetadata::CONFIG['persists_with'] == 'active_record'
|
8
|
+
require 'paperclip'
|
11
9
|
require "active_metadata/persistence/persistence"
|
12
10
|
|
13
11
|
def self.included(klass)
|
@@ -1,13 +1,9 @@
|
|
1
1
|
module ActiveMetadata::Persistence
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require "active_metadata/persistence/mongoid" if PERSISTS_WITH == 'mongoid'
|
6
|
-
require "active_metadata/persistence/active_record" if PERSISTS_WITH == 'active_record'
|
3
|
+
require "active_metadata/persistence/active_record"
|
7
4
|
|
8
5
|
def self.included(receiver)
|
9
|
-
|
10
|
-
receiver.send :include, persister
|
6
|
+
receiver.send :include, ActiveMetadata::Persistence::ActiveRecord
|
11
7
|
end
|
12
8
|
|
13
9
|
end
|
@@ -62,14 +62,7 @@ describe ActiveMetadata do
|
|
62
62
|
|
63
63
|
end
|
64
64
|
|
65
|
-
it "should update a note using update_note_for_name"
|
66
|
-
@document.create_note_for(:name, "Very important note!")
|
67
|
-
id = @document.notes_for(:name).last._id
|
68
|
-
@document.update_note(id, "New note value!")
|
69
|
-
@document.notes_for(:name).last.note.should eq "New note value!"
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should update a note using update_note_for_name", :active_record => true do
|
65
|
+
it "should update a note using update_note_for_name" do
|
73
66
|
@document.create_note_for(:name, "Very important note!")
|
74
67
|
id = @document.notes_for(:name).last.id
|
75
68
|
@document.update_note(id, "New note value!")
|
@@ -107,16 +100,7 @@ describe ActiveMetadata do
|
|
107
100
|
@document.notes_for(:name).last.updated_at.should be_a_kind_of Time
|
108
101
|
end
|
109
102
|
|
110
|
-
it "should update the updated_at field when a note is updated"
|
111
|
-
@document.create_note_for(:name, "Very important note!")
|
112
|
-
id = @document.notes_for(:name).last._id
|
113
|
-
sleep 1.seconds
|
114
|
-
@document.update_note id, "new note value"
|
115
|
-
note = @document.notes_for(:name).last
|
116
|
-
note.updated_at.should > note.created_at
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should update the updated_at field when a note is updated", :active_record => true do
|
103
|
+
it "should update the updated_at field when a note is updated" do
|
120
104
|
@document.create_note_for(:name, "Very important note!")
|
121
105
|
id = @document.notes_for(:name).last.id
|
122
106
|
sleep 1.seconds
|
@@ -125,19 +109,7 @@ describe ActiveMetadata do
|
|
125
109
|
note.updated_at.should > note.created_at
|
126
110
|
end
|
127
111
|
|
128
|
-
it "should verify that note are saved with the correct model id if metadata_id_from is defined"
|
129
|
-
# fixtures
|
130
|
-
@document.create_note_for(:name, "Very important note!")
|
131
|
-
@section = @document.create_section :title => "new section"
|
132
|
-
@section.reload
|
133
|
-
@section.create_note_for(:title, "Very important note for section!")
|
134
|
-
|
135
|
-
# expectations
|
136
|
-
@document.notes_for(:name).last.label.active_meta.document_id.should eq @document.id
|
137
|
-
@section.notes_for(:title).last.label.active_meta.document_id.should eq @document.id
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should verify that note are saved with the correct model id if metadata_id_from is defined" , :active_record => true do
|
112
|
+
it "should verify that note are saved with the correct model id if metadata_id_from is defined" do
|
141
113
|
# fixtures
|
142
114
|
@document.create_note_for(:name, "Very important note!")
|
143
115
|
@section = @document.create_section :title => "new section"
|
@@ -149,45 +121,7 @@ describe ActiveMetadata do
|
|
149
121
|
@section.notes_for(:title).last.document_id.should eq @document.id
|
150
122
|
end
|
151
123
|
|
152
|
-
it "should delete a note
|
153
|
-
#fixtures
|
154
|
-
2.times do |i|
|
155
|
-
@document.create_note_for(:name, "Note number #{i}")
|
156
|
-
end
|
157
|
-
|
158
|
-
#expectations
|
159
|
-
notes = @document.notes_for(:name)
|
160
|
-
notes.count.should eq 2
|
161
|
-
note_to_be_deleted = notes[0].note
|
162
|
-
|
163
|
-
@document.delete_note_for(:name,notes[0]._id)
|
164
|
-
|
165
|
-
notes = @document.notes_for(:name)
|
166
|
-
notes.count.should eq 1
|
167
|
-
notes.first.note.should_not eq note_to_be_deleted
|
168
|
-
|
169
|
-
end
|
170
|
-
|
171
|
-
it "should delete a note passing a string as id", :mongoid => true do
|
172
|
-
#fixtures
|
173
|
-
2.times do |i|
|
174
|
-
@document.create_note_for(:name, "Note number #{i}")
|
175
|
-
end
|
176
|
-
|
177
|
-
#expectations
|
178
|
-
notes = @document.notes_for(:name)
|
179
|
-
notes.count.should eq 2
|
180
|
-
note_to_be_deleted = notes[0].note
|
181
|
-
|
182
|
-
@document.delete_note_for(:name,notes[0].id.to_s)
|
183
|
-
|
184
|
-
notes = @document.notes_for(:name)
|
185
|
-
notes.count.should eq 1
|
186
|
-
notes.first.note.should_not eq note_to_be_deleted
|
187
|
-
|
188
|
-
end
|
189
|
-
|
190
|
-
it "should delete a note id", :active_record => true do
|
124
|
+
it "should delete a note id" do
|
191
125
|
#fixtures
|
192
126
|
2.times do |i|
|
193
127
|
@document.create_note_for(:name, "Note number #{i}")
|
@@ -218,21 +152,7 @@ describe ActiveMetadata do
|
|
218
152
|
@document.notes_for(:name).last.note.should eq "Note number 0"
|
219
153
|
end
|
220
154
|
|
221
|
-
it "should find a note by id"
|
222
|
-
|
223
|
-
3.times do |i|
|
224
|
-
@document.create_note_for(:name, "Note number #{i}")
|
225
|
-
end
|
226
|
-
|
227
|
-
note = @document.notes_for(:name).last
|
228
|
-
id = note.id.to_s
|
229
|
-
|
230
|
-
match_note = @document.note_for :name,id
|
231
|
-
match_note.id.to_s.should eq id
|
232
|
-
|
233
|
-
end
|
234
|
-
|
235
|
-
it "should find a note by id", :active_record => true, do
|
155
|
+
it "should find a note by id" do
|
236
156
|
|
237
157
|
3.times do |i|
|
238
158
|
@document.create_note_for(:name, "Note number #{i}")
|
@@ -286,20 +206,7 @@ describe ActiveMetadata do
|
|
286
206
|
@another_doc.history_for(:name).last.value.should eq @another_doc.name
|
287
207
|
end
|
288
208
|
|
289
|
-
it "should verify that history is saved with the correct model id if metadata_id_from is defined"
|
290
|
-
# fixtures
|
291
|
-
@section = @document.create_section :title => "new section"
|
292
|
-
@section.reload
|
293
|
-
|
294
|
-
# expectations
|
295
|
-
@document.history_for(:name).count.should eq(1)
|
296
|
-
@document.history_for(:name).last.label.active_meta.document_id.should eq @document.id
|
297
|
-
|
298
|
-
@section.history_for(:title).count.should eq(1)
|
299
|
-
@section.history_for(:title).last.label.active_meta.document_id.should eq @document.id
|
300
|
-
end
|
301
|
-
|
302
|
-
it "should verify that history is saved with the correct model id if metadata_id_from is defined", :active_record => true, do
|
209
|
+
it "should verify that history is saved with the correct model id if metadata_id_from is defined" do
|
303
210
|
# fixtures
|
304
211
|
@section = @document.create_section :title => "new section"
|
305
212
|
@section.reload
|
@@ -354,12 +261,7 @@ describe ActiveMetadata do
|
|
354
261
|
@document.attachments_for(:name).should have(1).record
|
355
262
|
end
|
356
263
|
|
357
|
-
it "should verify that the attachment metadata id refers to the correct self id"
|
358
|
-
@document.save_attachment_for(:name,@attachment)
|
359
|
-
@document.attachments_for(:name).last.label.active_meta.document_id.should eq @document.id
|
360
|
-
end
|
361
|
-
|
362
|
-
it "should verify that the attachment metadata id refers to the correct self id", :active_record => true do
|
264
|
+
it "should verify that the attachment metadata id refers to the correct self id" do
|
363
265
|
@document.save_attachment_for(:name,@attachment)
|
364
266
|
@document.attachments_for(:name).last.document_id.should eq @document.id
|
365
267
|
end
|
@@ -379,68 +281,19 @@ describe ActiveMetadata do
|
|
379
281
|
@document.attachments_for(:name).last.attach.size.should eq @attachment.size
|
380
282
|
end
|
381
283
|
|
382
|
-
it "should verify that the attachment updated_at is correctly saved"
|
383
|
-
@document.save_attachment_for(:name,@attachment)
|
384
|
-
@document.attachments_for(:name).last.attach.instance_read(:updated_at).should be_a_kind_of DateTime
|
385
|
-
end
|
386
|
-
|
387
|
-
it "should verify that the attachment updated_at is correctly saved", :active_record => true do
|
284
|
+
it "should verify that the attachment updated_at is correctly saved" do
|
388
285
|
@document.save_attachment_for(:name,@attachment)
|
389
286
|
@document.attachments_for(:name).last.attach.instance_read(:updated_at).should be_a_kind_of Time
|
390
287
|
end
|
391
288
|
|
392
|
-
it "should verify that the document has been saved in the correct position on filesystem"
|
289
|
+
it "should verify that the document has been saved in the correct position on filesystem" do
|
393
290
|
@document.save_attachment_for(:name,@attachment)
|
394
291
|
att = @document.attachments_for(:name).first
|
395
292
|
expected_path = File.expand_path "#{ActiveMetadata::CONFIG['attachment_base_path']}/#{@document.id}/#{:name.to_s}/#{att.id}/#{@attachment.original_filename}"
|
396
293
|
File.exists?(expected_path).should be_true
|
397
294
|
end
|
398
295
|
|
399
|
-
it "should
|
400
|
-
@document.save_attachment_for(:name,@attachment)
|
401
|
-
att = @document.attachments_for(:name).first
|
402
|
-
expected_path = File.expand_path "#{ActiveMetadata::CONFIG['attachment_base_path']}/#{@document.id}/#{:name.to_s}/#{att.counter}/#{@attachment.original_filename}"
|
403
|
-
File.exists?(expected_path).should be_true
|
404
|
-
end
|
405
|
-
|
406
|
-
it "should delete an attachment passing a bson object as id", :mongoid => true do
|
407
|
-
|
408
|
-
#fixtures
|
409
|
-
2.times do |i|
|
410
|
-
@document.save_attachment_for(:name,@attachment)
|
411
|
-
end
|
412
|
-
|
413
|
-
#expectations
|
414
|
-
attachments = @document.attachments_for(:name)
|
415
|
-
attachments.count.should eq 2
|
416
|
-
attachment_path_to_be_deleted = attachments[0].attach.path
|
417
|
-
|
418
|
-
@document.delete_attachment_for(:name,attachments[0]._id)
|
419
|
-
|
420
|
-
attachments = @document.attachments_for(:name)
|
421
|
-
attachments.count.should eq 1
|
422
|
-
attachments.first.attach.path.should_not eq attachment_path_to_be_deleted
|
423
|
-
end
|
424
|
-
|
425
|
-
it "should delete an attachment passing a string as id", :mongoid => true do
|
426
|
-
#fixtures
|
427
|
-
2.times do |i|
|
428
|
-
@document.save_attachment_for(:name,@attachment)
|
429
|
-
end
|
430
|
-
|
431
|
-
#expectations
|
432
|
-
attachments = @document.attachments_for(:name)
|
433
|
-
attachments.count.should eq 2
|
434
|
-
attachment_path_to_be_deleted = attachments[0].attach.path
|
435
|
-
|
436
|
-
@document.delete_attachment_for(:name,attachments[0].id.to_s)
|
437
|
-
|
438
|
-
attachments = @document.attachments_for(:name)
|
439
|
-
attachments.count.should eq 1
|
440
|
-
attachments.first.attach.path.should_not eq attachment_path_to_be_deleted
|
441
|
-
end
|
442
|
-
|
443
|
-
it "should delete an attachment by id", :active_record => true do
|
296
|
+
it "should delete an attachment by id" do
|
444
297
|
#fixtures
|
445
298
|
2.times do |i|
|
446
299
|
@document.save_attachment_for(:name,@attachment)
|
@@ -458,18 +311,7 @@ describe ActiveMetadata do
|
|
458
311
|
attachments.first.attach.path.should_not eq attachment_path_to_be_deleted
|
459
312
|
end
|
460
313
|
|
461
|
-
it "should update an attachment"
|
462
|
-
@document.save_attachment_for(:name,@attachment)
|
463
|
-
att = @document.attachments_for(:name).last
|
464
|
-
|
465
|
-
@document.update_attachment_for :name,att._id,@attachment2
|
466
|
-
att2 = @document.attachments_for(:name).last
|
467
|
-
|
468
|
-
File.exists?(att.attach.path).should be_false
|
469
|
-
File.exists?(att2.attach.path).should be_true
|
470
|
-
end
|
471
|
-
|
472
|
-
it "should update an attachment", :active_record => true do
|
314
|
+
it "should update an attachment" do
|
473
315
|
@document.save_attachment_for(:name,@attachment)
|
474
316
|
att = @document.attachments_for(:name).last
|
475
317
|
|
@@ -480,19 +322,7 @@ describe ActiveMetadata do
|
|
480
322
|
File.exists?(att2.attach.path).should be_true
|
481
323
|
end
|
482
324
|
|
483
|
-
it "should verify that field attachment_updated_at is modified after an update"
|
484
|
-
@document.save_attachment_for(:name,@attachment)
|
485
|
-
att = @document.attachments_for(:name).last
|
486
|
-
|
487
|
-
sleep 1.seconds
|
488
|
-
|
489
|
-
@document.update_attachment_for :name,att._id,@attachment2
|
490
|
-
att2 = @document.attachments_for(:name).last
|
491
|
-
|
492
|
-
att2.attach.instance_read(:updated_at).should be > att.attach.instance_read(:updated_at)
|
493
|
-
end
|
494
|
-
|
495
|
-
it "should verify that field attachment_updated_at is modified after an update", :active_record => true do
|
325
|
+
it "should verify that field attachment_updated_at is modified after an update" do
|
496
326
|
@document.save_attachment_for(:name,@attachment)
|
497
327
|
att = @document.attachments_for(:name).last
|
498
328
|
|
data/spec/spec_helper.rb
CHANGED
@@ -4,7 +4,6 @@ require "rails/all"
|
|
4
4
|
require "logger"
|
5
5
|
require 'rspec/core'
|
6
6
|
require "sqlite3"
|
7
|
-
require "mongoid"
|
8
7
|
require "rack/test/uploaded_file"
|
9
8
|
|
10
9
|
$: << File.expand_path(File.dirname(__FILE__) + "/../app")
|
@@ -26,14 +25,6 @@ ENV["ACTIVE_METADATA_ENV"] ||= 'test'
|
|
26
25
|
ActiveRecord::Base.establish_connection YAML.load_file("config/database.yml")[ENV["RAILS_ENV"]]
|
27
26
|
ActiveRecord::Base.logger = Logger.new "log/test.log"
|
28
27
|
Rails.logger = ActiveRecord::Base.logger
|
29
|
-
|
30
|
-
#load the config
|
31
|
-
conf = YAML.load_file('config/active_metadata.yml')[Rails.env]
|
32
|
-
is_mongo = conf['persists_with'] == 'mongoid'
|
33
|
-
|
34
|
-
if is_mongo
|
35
|
-
Mongoid.load!("config/mongoid.yml")
|
36
|
-
end
|
37
28
|
|
38
29
|
# loading ruby files
|
39
30
|
require "#{File.dirname(__FILE__)}/../lib/engine.rb"
|
@@ -60,24 +51,12 @@ RSpec.configure do |config|
|
|
60
51
|
# config.use_transactional_fixtures = true
|
61
52
|
|
62
53
|
|
63
|
-
config.before(:suite) do
|
64
|
-
if is_mongo
|
65
|
-
ActiveMeta.create_indexes()
|
66
|
-
Label.create_indexes()
|
67
|
-
Note.create_indexes();
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
54
|
config.before(:each) do
|
72
55
|
Document.delete_all
|
73
56
|
Note.delete_all
|
74
57
|
Watcher.delete_all
|
75
58
|
Attachment.delete_all
|
76
59
|
History.delete_all
|
77
|
-
if is_mongo
|
78
|
-
ActiveMeta.delete_all
|
79
|
-
Label.delete_all
|
80
|
-
end
|
81
60
|
FileUtils.remove_dir File.expand_path('public/system/') if Dir.exist?(File.expand_path('public/system/'))
|
82
61
|
end
|
83
62
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_metadata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-10-
|
13
|
+
date: 2011-10-11 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec-rails
|
17
|
-
requirement: &
|
17
|
+
requirement: &2156180700 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2156180700
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: sqlite3
|
28
|
-
requirement: &
|
28
|
+
requirement: &2156178420 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2156178420
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: sqlite3-ruby
|
39
|
-
requirement: &
|
39
|
+
requirement: &2156154920 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2156154920
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: cucumber
|
50
|
-
requirement: &
|
50
|
+
requirement: &2156100000 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2156100000
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: ci_reporter
|
61
|
-
requirement: &
|
61
|
+
requirement: &2156079680 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *2156079680
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rails
|
72
|
-
requirement: &
|
72
|
+
requirement: &2156049960 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - =
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: 3.0.1
|
78
78
|
type: :runtime
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *2156049960
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: activerecord
|
83
|
-
requirement: &
|
83
|
+
requirement: &2156032700 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - =
|
@@ -88,32 +88,10 @@ dependencies:
|
|
88
88
|
version: 3.0.1
|
89
89
|
type: :runtime
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *2156032700
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
|
-
name:
|
94
|
-
requirement: &
|
95
|
-
none: false
|
96
|
-
requirements:
|
97
|
-
- - =
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
version: 2.1.4
|
100
|
-
type: :runtime
|
101
|
-
prerelease: false
|
102
|
-
version_requirements: *2157119280
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
name: mongoid-paperclip
|
105
|
-
requirement: &2157111740 !ruby/object:Gem::Requirement
|
106
|
-
none: false
|
107
|
-
requirements:
|
108
|
-
- - ! '>='
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
type: :runtime
|
112
|
-
prerelease: false
|
113
|
-
version_requirements: *2157111740
|
114
|
-
- !ruby/object:Gem::Dependency
|
115
|
-
name: bson_ext
|
116
|
-
requirement: &2157110820 !ruby/object:Gem::Requirement
|
93
|
+
name: paperclip
|
94
|
+
requirement: &2156029320 !ruby/object:Gem::Requirement
|
117
95
|
none: false
|
118
96
|
requirements:
|
119
97
|
- - ! '>='
|
@@ -121,10 +99,10 @@ dependencies:
|
|
121
99
|
version: '0'
|
122
100
|
type: :runtime
|
123
101
|
prerelease: false
|
124
|
-
version_requirements: *
|
102
|
+
version_requirements: *2156029320
|
125
103
|
- !ruby/object:Gem::Dependency
|
126
104
|
name: to_xls
|
127
|
-
requirement: &
|
105
|
+
requirement: &2156024620 !ruby/object:Gem::Requirement
|
128
106
|
none: false
|
129
107
|
requirements:
|
130
108
|
- - ! '>='
|
@@ -132,7 +110,7 @@ dependencies:
|
|
132
110
|
version: '0'
|
133
111
|
type: :runtime
|
134
112
|
prerelease: false
|
135
|
-
version_requirements: *
|
113
|
+
version_requirements: *2156024620
|
136
114
|
description: First implementation will write metadata on mongodb
|
137
115
|
email:
|
138
116
|
- acampolonghi@gmail.com
|
@@ -147,11 +125,6 @@ files:
|
|
147
125
|
- lib/active_metadata/persistence/active_record/note.rb
|
148
126
|
- lib/active_metadata/persistence/active_record/watcher.rb
|
149
127
|
- lib/active_metadata/persistence/active_record.rb
|
150
|
-
- lib/active_metadata/persistence/mongoid/attachment.rb
|
151
|
-
- lib/active_metadata/persistence/mongoid/history.rb
|
152
|
-
- lib/active_metadata/persistence/mongoid/note.rb
|
153
|
-
- lib/active_metadata/persistence/mongoid/watcher.rb
|
154
|
-
- lib/active_metadata/persistence/mongoid.rb
|
155
128
|
- lib/active_metadata/persistence/persistence.rb
|
156
129
|
- lib/active_metadata/railtie.rb
|
157
130
|
- lib/active_metadata/version.rb
|
@@ -1,45 +0,0 @@
|
|
1
|
-
module ActiveMetadata::Persistence::Mongoid::Attachment
|
2
|
-
|
3
|
-
def self.included(receiver)
|
4
|
-
receiver.send :include, InstanceMethods
|
5
|
-
end
|
6
|
-
|
7
|
-
module InstanceMethods
|
8
|
-
|
9
|
-
def save_attachment_for(field, file)
|
10
|
-
label = ActiveMeta.find_or_create_by(:document_id => metadata_id).labels.find_or_create_by(:name => field.to_s)
|
11
|
-
counter = label.attachments.count > 0 ? label.attachments.last.counter : 0
|
12
|
-
attachment = Attachment.new(:attach => file, :counter => (counter + 1))
|
13
|
-
label.attachments << attachment
|
14
|
-
label.save
|
15
|
-
|
16
|
-
self.send(:send_notification, field, "", attachment.attach.original_filename)
|
17
|
-
end
|
18
|
-
|
19
|
-
def attachments_for(field)
|
20
|
-
label = ActiveMeta.find_or_create_by(:document_id => metadata_id).labels.find_or_create_by(:name => field.to_s)
|
21
|
-
label.attachments.desc(:attach_updated_at).to_a
|
22
|
-
end
|
23
|
-
|
24
|
-
def delete_attachment_for(field,id)
|
25
|
-
a = ActiveMeta.find_or_create_by(:document_id => metadata_id).labels.find_or_create_by(:name => field.to_s).attachments.find(id)
|
26
|
-
filename = a.attach.original_filename
|
27
|
-
a.destroy
|
28
|
-
|
29
|
-
self.send(:send_notification, field, filename, "")
|
30
|
-
end
|
31
|
-
|
32
|
-
def update_attachment_for(field, id, newfile)
|
33
|
-
a = ActiveMeta.find_or_create_by(:document_id => metadata_id).labels.find_or_create_by(:name => field.to_s).attachments.find(id)
|
34
|
-
old_filename = a.attach.original_filename
|
35
|
-
a.attach = newfile
|
36
|
-
a.save
|
37
|
-
new_filename = a.attach.original_filename
|
38
|
-
|
39
|
-
self.send(:send_notification, field, old_filename, new_filename)
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module ActiveMetadata::Persistence::Mongoid::History
|
2
|
-
|
3
|
-
def self.included(receiver)
|
4
|
-
receiver.send :include, InstanceMethods
|
5
|
-
end
|
6
|
-
|
7
|
-
module InstanceMethods
|
8
|
-
|
9
|
-
def save_history
|
10
|
-
self.changes.each do |key, value|
|
11
|
-
next if ActiveMetadata::CONFIG['history_skip_fields'].include?(key)
|
12
|
-
|
13
|
-
label = ActiveMeta.find_or_create_by(:document_id => metadata_id).labels.find_or_create_by(:name => key.to_s)
|
14
|
-
label.histories.create!(:value => value[1], :created_at => Time.now.utc)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def history_for field
|
19
|
-
meta = ActiveMeta.find_or_create_by(:document_id => metadata_id)
|
20
|
-
|
21
|
-
label = meta.labels.find_or_create_by(:name => field.to_s)
|
22
|
-
label.histories.desc(:created_at).to_a
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module ActiveMetadata::Persistence::Mongoid::Note
|
2
|
-
|
3
|
-
def self.included(receiver)
|
4
|
-
receiver.send :include, InstanceMethods
|
5
|
-
end
|
6
|
-
|
7
|
-
module InstanceMethods
|
8
|
-
|
9
|
-
def create_note_for(field, note, created_by=nil)
|
10
|
-
raise RuntimeError, "The object id MUST be valued" unless self.id
|
11
|
-
label = ActiveMeta.find_or_create_by(:document_id => metadata_id).labels.find_or_create_by(:name => field.to_s)
|
12
|
-
label.notes.create!(:note => note, :created_by => created_by, :created_at => Time.now.utc, :updated_at => Time.now.utc)
|
13
|
-
|
14
|
-
# BEWARE: I'm not checking the send_notification method existence
|
15
|
-
# this notification should be asynch
|
16
|
-
self.send(:send_notification, field, "", note)
|
17
|
-
end
|
18
|
-
|
19
|
-
def update_note(id, note, updated_by=nil)
|
20
|
-
n = ActiveMeta.find_or_create_by(:document_id => metadata_id).labels.find_or_create_by(:name => 'name').notes.find id
|
21
|
-
old_value = n.note
|
22
|
-
n.update_attributes :note => note, :updated_by => updated_by, :updated_at => Time.now.utc
|
23
|
-
|
24
|
-
self.send(:send_notification, n.label, old_value, note)
|
25
|
-
end
|
26
|
-
|
27
|
-
def notes_for(field)
|
28
|
-
label = ActiveMeta.find_or_create_by(:document_id => metadata_id).labels.find_or_create_by(:name => field.to_s)
|
29
|
-
label.notes.desc(:updated_at).to_a
|
30
|
-
end
|
31
|
-
|
32
|
-
def note_for(field,id)
|
33
|
-
label = ActiveMeta.find_or_create_by(:document_id => metadata_id).labels.find_or_create_by(:name => field.to_s)
|
34
|
-
label.notes.find(id)
|
35
|
-
end
|
36
|
-
|
37
|
-
def create_notes_for(field,notes)
|
38
|
-
notes.each { |note| create_note_for field, note }
|
39
|
-
end
|
40
|
-
|
41
|
-
def delete_note_for(field,id)
|
42
|
-
n = ActiveMeta.find_or_create_by(:document_id => metadata_id).labels.find_or_create_by(:name => field.to_s).notes.find(id)
|
43
|
-
old_value = n.note
|
44
|
-
n.destroy
|
45
|
-
self.send(:send_notification, field, old_value, "")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module ActiveMetadata::Persistence::Mongoid::Watcher
|
2
|
-
|
3
|
-
def self.included(receiver)
|
4
|
-
receiver.send :include, InstanceMethods
|
5
|
-
end
|
6
|
-
|
7
|
-
module InstanceMethods
|
8
|
-
def create_watcher_for(field, owner)
|
9
|
-
raise RuntimeError, "The object id MUST be valued" unless self.id
|
10
|
-
|
11
|
-
label_path(field).watchers.create!(:owner_id => owner.id, :created_at => Time.now.utc, :updated_at => Time.now.utc)
|
12
|
-
|
13
|
-
owner.create_inbox unless owner.inbox # ensure that an inbox is present
|
14
|
-
end
|
15
|
-
|
16
|
-
def watchers_for(field)
|
17
|
-
label_path(field).watchers.asc(:created_at).to_a
|
18
|
-
end
|
19
|
-
|
20
|
-
def delete_watcher_for(field, owner)
|
21
|
-
#TODO
|
22
|
-
end
|
23
|
-
|
24
|
-
def is_watched_by(field,owner)
|
25
|
-
#TODO
|
26
|
-
end
|
27
|
-
|
28
|
-
# This is a callback method of the after_save of the ActiveRecord
|
29
|
-
# object.
|
30
|
-
# TODO: It should definetly be decoupled in time from the save of
|
31
|
-
# the alerting system
|
32
|
-
def on_save_watcher_callback
|
33
|
-
self.changes.each do |field, values|
|
34
|
-
send_notification(field, values.first, values.last)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def send_notification(field, old_value, new_value)
|
39
|
-
watchers_for(field).each { |watch| watch.notify_changes(field, old_value, new_value, self.class, self.id) }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module ActiveMetadata::Persistence::Mongoid
|
2
|
-
|
3
|
-
require "active_metadata/persistence/mongoid/attachment"
|
4
|
-
require "active_metadata/persistence/mongoid/note"
|
5
|
-
require "active_metadata/persistence/mongoid/history"
|
6
|
-
require "active_metadata/persistence/mongoid/watcher"
|
7
|
-
require "model/mongoid/active_meta"
|
8
|
-
require "model/mongoid/label"
|
9
|
-
require "model/mongoid/note"
|
10
|
-
require "model/mongoid/history"
|
11
|
-
require "model/mongoid/attachment"
|
12
|
-
require "model/mongoid/watcher"
|
13
|
-
|
14
|
-
def self.included(receiver)
|
15
|
-
receiver.send :include, InstanceMethods
|
16
|
-
end
|
17
|
-
|
18
|
-
module InstanceMethods
|
19
|
-
|
20
|
-
include ActiveMetadata::Persistence::Mongoid::Note
|
21
|
-
include ActiveMetadata::Persistence::Mongoid::History
|
22
|
-
include ActiveMetadata::Persistence::Mongoid::Attachment
|
23
|
-
include ActiveMetadata::Persistence::Mongoid::Watcher
|
24
|
-
|
25
|
-
def label_path(field_name)
|
26
|
-
ActiveMeta.find_or_create_by(:document_id => metadata_id).labels.find_or_create_by(:name => field_name.to_s)
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|