snapshotar 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2572d8be4840c4e8e6e8562af33a7725280c148f
4
- data.tar.gz: 547cbb2cb62ba3eb0497d31631723be9dcdde907
3
+ metadata.gz: f8778bc5dd754e810d92bcdea757550ae15b9180
4
+ data.tar.gz: 7d388ff7f06648b609b37a3cc552699bafb636d9
5
5
  SHA512:
6
- metadata.gz: 8439da77855812445f380fd16ce78e56f3ea90e794cbaea53e21d759d96940e24ab6228fb9194fc5cb9d4fa7c065e4d3c19ae9b564a596fdc9b2b2e52acdaf07
7
- data.tar.gz: 807d97e73cf743e2f0edd9532420548127a9c4bf7a038829ddf29a68d7274c185cc69519400bb78a4e68f25d600b2210f0cea98d0006ba5c477ed58140a0060c
6
+ metadata.gz: 77cde58185033cbc91e8878e9ffcc2c15ec7a2d67d84e17209d674d8af4c650a440e401aeb6dc5bd5391bc07da9d347ee18cd2ca276be4c8bd06f4db6a669b3a
7
+ data.tar.gz: c666cd53eaf81bd4e08e7d9819ce156386c5de381aab3a0864a21922e2be1ced39f163b2e553170542191f009b03fbac0d0b45e818ee92d230a35fe9fd706ec1
data/README.md CHANGED
@@ -98,11 +98,24 @@ users create snapshots. A sample controller is provided below
98
98
 
99
99
  For **AWS S3**, you have to provide the following ENV variables provisioning your S3 bucket. For development environments look at this wonderful dot-env gem https://github.com/bkeepers/dotenv.
100
100
 
101
- config.storage_type = :s3
101
+ *config/initializers/snapshotar.rb*
102
+
103
+ Snapshotar.configure do |config|
104
+ config.storage_type = :s3
105
+
106
+ # serialization
107
+ config.models << [<ModelName>, <Attribute1 Symbol>, <Attribute2 Symbol>, :id, :name]
108
+
109
+ # shorter ...
110
+ config.models << ([User] + User.fields.keys.map { |x| x.to_sym })
111
+
112
+ end
113
+
102
114
 
103
115
  AWS_ACCESS_KEY_ID=<your id>
104
116
  AWS_SECRET_ACCESS_KEY=<your secret>
105
117
  AWS_SNAPSHOTAR_BUCKET=<a bucket name>
118
+ AWS_REGION=<e.g. eu-central-1>
106
119
 
107
120
  **Files**
108
121
 
@@ -120,6 +133,7 @@ in the projects root directory with the following keys:
120
133
  AWS_ACCESS_KEY_ID=<your id>
121
134
  AWS_SECRET_ACCESS_KEY=<your secret>
122
135
  AWS_SNAPSHOTAR_BUCKET=<a bucket name>
136
+ AWS_REGION=<e.g. eu-central-1>
123
137
 
124
138
  RACK_ENV=test
125
139
 
@@ -40,10 +40,13 @@ module Snapshotar
40
40
  model_name = m.first.name
41
41
  json.set! model_name do
42
42
 
43
- # support inherited classes
44
- json.set! :klass, itm.class.to_s unless (itm.class.to_s == model_name)
45
-
43
+ # iterate objects
46
44
  json.array! m.first.all do |itm|
45
+
46
+ # support inherited classes
47
+ json.set! :clazz, itm.class.to_s unless (itm.class.to_s == model_name)
48
+
49
+ # iterate attributes
47
50
  m[1..-1].each do |attr|
48
51
 
49
52
  next unless itm.respond_to?(attr.to_sym)
@@ -85,6 +88,12 @@ module Snapshotar
85
88
 
86
89
  next if itm_value.nil?
87
90
 
91
+ # handle inheritance
92
+ if (itm_key.to_s == "clazz")
93
+ clazz = itm_value.constantize
94
+ next
95
+ end
96
+
88
97
  # handle url paths separatley
89
98
  if itm_key.to_s.end_with?("_url")
90
99
  if File.exist?(itm_value)
@@ -12,6 +12,7 @@ module Snapshotar
12
12
  raise ArgumentError, "You should set ENV['AWS_ACCESS_KEY_ID'] to a valid value" unless ENV['AWS_ACCESS_KEY_ID']
13
13
  raise ArgumentError, "You should set ENV['AWS_SECRET_ACCESS_KEY'] to a valid value" unless ENV['AWS_SECRET_ACCESS_KEY']
14
14
  raise ArgumentError, "You should set ENV['AWS_SNAPSHOTAR_BUCKET'] to a aws bucket name used only for snapshotting" unless ENV['AWS_SNAPSHOTAR_BUCKET']
15
+ raise ArgumentError, "You should set ENV['AWS_REGION'] to the region of your s3 bucket" unless ENV['AWS_REGION']
15
16
 
16
17
  p "Running S3 with key: #{ENV['AWS_ACCESS_KEY_ID']}, secret: #{ENV['AWS_SECRET_ACCESS_KEY']}, bucket: #{ENV['AWS_SNAPSHOTAR_BUCKET']}"
17
18
 
@@ -1,3 +1,3 @@
1
1
  module Snapshotar
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -13,7 +13,7 @@ describe Snapshotar::Storage::FileStorage do
13
13
  config.storage_type = :file
14
14
 
15
15
  # serialization
16
- config.models << [Artist, :name, :avatar]
16
+ config.models << [Artist, :name, :avatar, :genre]
17
17
  end
18
18
 
19
19
  # create models with images attached
@@ -33,7 +33,6 @@ describe Snapshotar::Storage::FileStorage do
33
33
 
34
34
  it "should create image models" do
35
35
  expect(Artist.count).to eq 1
36
- p Artist.first.avatar.path
37
36
  end
38
37
 
39
38
  it "should export successfully" do
@@ -63,5 +62,32 @@ describe Snapshotar::Storage::FileStorage do
63
62
  # clean up
64
63
  @snapshotar.delete(filename)
65
64
  end
65
+
66
+ it "should encode inheritance" do
67
+
68
+ # remove sample artist
69
+ Artist.delete_all
70
+
71
+ # create band which inherits from artist
72
+ dreadvibes = Band.create({name: "Dreadvibes", genre: "Reggae'n'Roll"})
73
+
74
+ # export
75
+ filename = @snapshotar.export
76
+
77
+ # clear db
78
+ Mongoid.purge!
79
+
80
+ expect(Artist.count).to eq 0
81
+
82
+ # # reimport
83
+ @snapshotar.import(filename)
84
+
85
+ expect(Artist.count).to eq 1
86
+ expect(Artist.first.name).to eq "Dreadvibes"
87
+ expect(Artist.first.genre).to eq "Reggae'n'Roll"
88
+
89
+ # clean up
90
+ @snapshotar.delete(filename)
91
+ end
66
92
  end
67
93
  end
@@ -0,0 +1,7 @@
1
+ # this is a sample model for testing purpose
2
+
3
+ class Band < Artist #:nodoc:
4
+ include Mongoid::Document
5
+
6
+ field :genre, type: String
7
+ end
data/spec/spec_helper.rb CHANGED
@@ -18,7 +18,7 @@ end
18
18
 
19
19
  require 'models/event'
20
20
  require 'models/artist'
21
-
21
+ require 'models/band'
22
22
 
23
23
  RSpec.configure do |config|
24
24
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snapshotar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Müller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-10 00:00:00.000000000 Z
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -154,6 +154,7 @@ files:
154
154
  - spec/core_spec.rb
155
155
  - spec/file_storage_spec.rb
156
156
  - spec/models/artist.rb
157
+ - spec/models/band.rb
157
158
  - spec/models/event.rb
158
159
  - spec/models/image_uploader.rb
159
160
  - spec/s3_storage_spec.rb
@@ -192,6 +193,7 @@ test_files:
192
193
  - spec/core_spec.rb
193
194
  - spec/file_storage_spec.rb
194
195
  - spec/models/artist.rb
196
+ - spec/models/band.rb
195
197
  - spec/models/event.rb
196
198
  - spec/models/image_uploader.rb
197
199
  - spec/s3_storage_spec.rb