duracloud-client 0.9.1 → 0.10.0

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: e4ecca7b686316d42167a375acad7de84fd8265e
4
- data.tar.gz: 2dcf12852efa3373af9c26140f0b09f93270a7d3
3
+ metadata.gz: ab3c4183dff4f6bcd2b40da7e2601cf0822407d0
4
+ data.tar.gz: 426c246ed3d48bbac47dc17972157147cd9dcf56
5
5
  SHA512:
6
- metadata.gz: eb132b96fd0f5664a60d150640c3bf271e1dd994b1167245a6008e2ec84a730baa381c4c408115e1a4679125c7c59baac7063750f172214b7d62b1ec37636a53
7
- data.tar.gz: baba50af951e1c79aae3fd1bc9981112443ebee392b222568531155b9ef87be0252e87eafb97b4a008fd6f86621824a580b103e5ab929d8ec8b0ee318a228e24
6
+ metadata.gz: 99041da397ad7d9cef8ff49cc0cf352bf254db576cc068e270133e0f3e247a38f954c3de7c1a8e5d636e3f3e508a5fcc1d7aa118fbeaeb97038ec06e7e72ca59
7
+ data.tar.gz: 5f377cbe3a4940613310bad558bf8761bcbcfbd4fee5352ab3a5ac41a08368ef28e0715d0ed219cd0b54441243bc19af4ddb894432ca9ec99a82fa6250e1fba2
data/.travis.yml CHANGED
@@ -2,5 +2,5 @@ language: ruby
2
2
  rvm:
3
3
  - 2.2
4
4
  - 2.3.1
5
- gemfile:
6
- - gemfiles/Gemfile.activemodel-4.2
5
+ - 2.4
6
+
data/Gemfile CHANGED
@@ -1,6 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in duracloud.gemspec
4
3
  gemspec
5
4
 
6
- gem 'activemodel', '~> 4.2.7'
5
+ gem 'byebug'
data/README.md CHANGED
@@ -31,36 +31,21 @@ Option 1. Environment variables
31
31
 
32
32
  Option 2. Manual configuration
33
33
 
34
- ```ruby
35
- Duracloud::Client.configure do |config|
36
- config.host = "foo.duracloud.org"
37
- config.user = "bob@example.com"
38
- config.password = "s3cret"
39
- end
40
- ```
34
+ *Changed in v0.10.0* Set attributes on `Duracloud` module instead of using `Duracloud::Client.configure {|config| ...}` block.
41
35
 
42
- ```
43
- > c = Duracloud::Client.new
44
- => #<Duracloud::Client:0x007fe953a1c630 @config=#<Duracloud::Configuration host="foo.duracloud.org", port=nil, user="bob@example.com">>
45
- ```
36
+ Duracloud.host = "foo.duracloud.org"
37
+ Duracloud.user = "bob@example.com"
38
+ Duracloud.password = "s3cret"
46
39
 
47
40
  #### Logging
48
41
 
49
- By default, `Duracloud::Client` logs to `STDERR`. Use the `logger` config setting to change:
42
+ By default duracloud-client logs to `STDERR`. Use the `logger` config setting to change:
50
43
 
51
- ```ruby
52
- Duracloud::Client.configure do |config|
53
- config.logger = Rails.logger
54
- end
55
- ```
44
+ Duracloud.logger = Rails.logger
56
45
 
57
46
  You can also silence logging:
58
47
 
59
- ```ruby
60
- Duracloud::Client.configure do |config|
61
- config.silence_logging! # sets logger device to null device
62
- end
63
- ```
48
+ Duracloud.silence_logging! # sets logger device to null device
64
49
 
65
50
  ### List Storage Providers
66
51
 
@@ -81,7 +66,7 @@ end
81
66
 
82
67
  ```
83
68
  >> space = Duracloud::Space.create("rest-api-testing2")
84
- D, [2016-04-29T12:12:32.641574 #28275] DEBUG -- : Duracloud::Client PUT https://foo.duracloud.org/durastore/rest-api-testing2 201 Created
69
+ D, [2016-04-29T12:12:32.641574 #28275] DEBUG -- : Duracloud::Request PUT https://foo.duracloud.org/durastore/rest-api-testing2 201 Created
85
70
  => #<Duracloud::Space space_id="rest-api-testing2", store_id="(default)">
86
71
  ```
87
72
 
@@ -91,7 +76,7 @@ A `Duracloud::BadRequestError` exception is raised if the space ID is invalid (i
91
76
 
92
77
  ```
93
78
  >> space = Duracloud::Space.find("rest-api-testing")
94
- D, [2016-04-29T12:15:12.593075 #28275] DEBUG -- : Duracloud::Client HEAD https://foo.duracloud.org/durastore/rest-api-testing 200 OK
79
+ D, [2016-04-29T12:15:12.593075 #28275] DEBUG -- : Duracloud::Request HEAD https://foo.duracloud.org/durastore/rest-api-testing 200 OK
95
80
  => #<Duracloud::Space space_id="rest-api-testing", store_id="(default)">
96
81
 
97
82
  >> space.count
@@ -103,11 +88,11 @@ D, [2016-04-29T12:15:12.593075 #28275] DEBUG -- : Duracloud::Client HEAD https:/
103
88
 
104
89
  A `Duracloud::NotFoundError` exception is raised if the space does not exist.
105
90
 
106
- NOTE: When the object count in a space exceeds 1000, Duracloud returns "1000+" as the count. Ruby's integer coercion `to_i`
91
+ **Note:** When the object count in a space exceeds 1000, Duracloud returns `1000+` as the count. Ruby's integer coercion `to_i`
107
92
  turns that string into the integer 1000. Getting an exact count above 1000 requires (on the client side) enumerating the content_ids
108
- (below, fixed in v0.7.2 when count is >= 1000) which can take a long time for a space with a lot of content items,
109
- since a maxiumum of 1000 ids can be retrived at one time. If an up-to-the-minute
110
- count is not required, the storage report for the space (not yet implemented in this library) shows an exact count on a daily basis.
93
+ (below, fixed in v0.7.2 when count is >= 1000) which can take a long time for a space with a lot of content items
94
+ (a maxiumum of 1000 ids can be retrived at one time). If an up-to-the-minute
95
+ count is not required, the storage report for the space shows an exact count on a daily basis.
111
96
 
112
97
  #### Enumerate the content IDs of the space
113
98
 
@@ -152,10 +137,11 @@ Duracloud::SyncValidation.call(space_id: 'foo', content_dir: '/var/foo/bar')
152
137
  create a temporary directory which is deleted on completion of the process. If `:work_dir` is specified, no cleanup is performed.
153
138
 
154
139
  Files created in work directory:
155
- - `{SPACE_ID}-manifest.tsv` (DuraCloud manifest as downloaded)
156
- - `{SPACE_ID}-md5.txt` (Munged manifest for md5deep)
157
- - `{SPACE_ID}-audit.txt` (Output of md5deep, empty if all files match)
158
- - `{SPACE_ID}-recheck.txt` (Out of audit recheck, if necessary)
140
+
141
+ {SPACE_ID}-manifest.tsv DuraCloud manifest as downloaded
142
+ {SPACE_ID}-md5.txt Munged manifest for md5deep
143
+ {SPACE_ID}-audit.txt Output of md5deep, empty if all files match
144
+ {SPACE_ID}-recheck.txt Output of audit recheck, if necessary
159
145
 
160
146
  *Added in version 0.9.0* - `Duracloud::FastSyncValidation`. This variant of sync validation does not compute local hashes but instead compares the local file list (generated with `find`) to the list of content IDs in the space manifest. Local misses are rechecked as in `SyncValidation` (but without MD5 comparison).
161
147
 
@@ -181,6 +167,8 @@ When storing content a `Duracloud::NotFoundError` is raised if the space does no
181
167
  A `Duracloud::BadRequestError` is raised if the content ID is invalid.
182
168
  A `Duracloud::ConflictError` is raised if the provided MD5 digest does not match the stored digest.
183
169
 
170
+ **Note:** duracloud-client does not currently provide for chunking of large files as, for example, the DuraCloud Sync Tool does.
171
+
184
172
  #### Retrieve an existing content item from DuraCloud
185
173
 
186
174
  ```
@@ -196,7 +184,7 @@ raised if the content ID exists and the stored digest does not match.
196
184
 
197
185
  If a content item is not found at the content ID, `Duracloud::Content.find` will look for a "content manifest"
198
186
  by appending ".dura-manifest" to the content ID. If the manifest is found, the content item is marked as
199
- "chunked". **Caution: Working with chunked files should be considered EXPERIMENTAL.**
187
+ "chunked". **Caution: Working with chunked files should be considered EXPERIMENTAL and unsupported.**
200
188
 
201
189
  #### Update the properties for a content item
202
190
 
@@ -205,7 +193,7 @@ by appending ".dura-manifest" to the content ID. If the manifest is found, the c
205
193
  => #<Duracloud::Space space_id="rest-api-testing", store_id="(default)">
206
194
 
207
195
  >> content = space.find_content("foo3")
208
- D, [2016-04-29T18:31:16.975749 #32379] DEBUG -- : Duracloud::Client HEAD https://foo.duracloud.org/durastore/rest-api-testing/foo3 200 OK
196
+ D, [2016-04-29T18:31:16.975749 #32379] DEBUG -- : Duracloud::Request HEAD https://foo.duracloud.org/durastore/rest-api-testing/foo3 200 OK
209
197
  => #<Duracloud::Content space_id="rest-api-testing", content_id="foo3", store_id=(default)>
210
198
 
211
199
  >> content.properties
@@ -213,12 +201,12 @@ D, [2016-04-29T18:31:16.975749 #32379] DEBUG -- : Duracloud::Client HEAD https:/
213
201
 
214
202
  >> content.properties["x-dura-meta-creator"] = "bob@example.com"
215
203
  >> content.save
216
- D, [2016-04-29T18:31:52.770195 #32379] DEBUG -- : Duracloud::Client POST https://foo.duracloud.org/durastore/rest-api-testing/foo3 200 OK
204
+ D, [2016-04-29T18:31:52.770195 #32379] DEBUG -- : Duracloud::Request POST https://foo.duracloud.org/durastore/rest-api-testing/foo3 200 OK
217
205
  I, [2016-04-29T18:31:52.770293 #32379] INFO -- : Content foo3 updated successfully
218
206
  => true
219
207
 
220
208
  >> content.properties["x-dura-meta-creator"]
221
- D, [2016-04-29T18:32:06.465928 #32379] DEBUG -- : Duracloud::Client HEAD https://foo.duracloud.org/durastore/rest-api-testing/foo3 200 OK
209
+ D, [2016-04-29T18:32:06.465928 #32379] DEBUG -- : Duracloud::Request HEAD https://foo.duracloud.org/durastore/rest-api-testing/foo3 200 OK
222
210
  => "bob@example.com"
223
211
  ```
224
212
 
@@ -234,11 +222,11 @@ Also, `:space_id` and `:content_id` arguments are not required, but default to t
234
222
 
235
223
  ```
236
224
  >> content = Duracloud::Content.find(space_id: 'rest-api-testing', content_id: 'contentItem.txt')
237
- D, [2017-01-27T17:16:45.846459 #93283] DEBUG -- : Duracloud::Client HEAD https://duke.duracloud.org/durastore/rest-api-testing/contentItem.txt 200 OK
225
+ D, [2017-01-27T17:16:45.846459 #93283] DEBUG -- : Duracloud::Request HEAD https://duke.duracloud.org/durastore/rest-api-testing/contentItem.txt 200 OK
238
226
  => #<Duracloud::Content space_id="rest-api-testing", content_id="contentItem.txt", store_id=(default)>
239
227
 
240
228
  >> content.copy(space_id: 'rest-api-testing2')
241
- D, [2017-01-27T17:17:59.848741 #93283] DEBUG -- : Duracloud::Client PUT https://duke.duracloud.org/durastore/rest-api-testing2/contentItem.txt 201 Created
229
+ D, [2017-01-27T17:17:59.848741 #93283] DEBUG -- : Duracloud::Request PUT https://duke.duracloud.org/durastore/rest-api-testing2/contentItem.txt 201 Created
242
230
  => #<Duracloud::Content space_id="rest-api-testing2", content_id="contentItem.txt", store_id=(default)>
243
231
  ```
244
232
 
@@ -246,18 +234,18 @@ D, [2017-01-27T17:17:59.848741 #93283] DEBUG -- : Duracloud::Client PUT https://
246
234
 
247
235
  *Added in v0.3.0; Changed in v0.4.0.*
248
236
 
249
- See also *Copy a content item, above.
237
+ See also *Copy a content item*, above.
250
238
 
251
239
  ```
252
240
  This is a convenience operation -- copy and delete -- not directly supported by the DuraCloud REST API.
253
241
 
254
242
  >> content = Duracloud::Content.find(space_id: 'rest-api-testing', content_id: 'contentItem.txt')
255
- D, [2017-01-27T17:19:41.926994 #93286] DEBUG -- : Duracloud::Client HEAD https://duke.duracloud.org/durastore/rest-api-testing/contentItem.txt 200 OK
243
+ D, [2017-01-27T17:19:41.926994 #93286] DEBUG -- : Duracloud::Request HEAD https://duke.duracloud.org/durastore/rest-api-testing/contentItem.txt 200 OK
256
244
  => #<Duracloud::Content space_id="rest-api-testing", content_id="contentItem.txt", store_id=(default)>
257
245
 
258
246
  >> content.move(space_id: 'rest-api-testing2')
259
- D, [2017-01-27T17:20:07.542468 #93286] DEBUG -- : Duracloud::Client PUT https://duke.duracloud.org/durastore/rest-api-testing2/contentItem.txt 201 Created
260
- D, [2017-01-27T17:20:08.442504 #93286] DEBUG -- : Duracloud::Client DELETE https://duke.duracloud.org/durastore/rest-api-testing/contentItem.txt 200 OK
247
+ D, [2017-01-27T17:20:07.542468 #93286] DEBUG -- : Duracloud::Request PUT https://duke.duracloud.org/durastore/rest-api-testing2/contentItem.txt 201 Created
248
+ D, [2017-01-27T17:20:08.442504 #93286] DEBUG -- : Duracloud::Request DELETE https://duke.duracloud.org/durastore/rest-api-testing/contentItem.txt 200 OK
261
249
  => #<Duracloud::Content space_id="rest-api-testing2", content_id="contentItem.txt", store_id=(default)>
262
250
 
263
251
  >> content.deleted?
@@ -274,15 +262,17 @@ D, [2017-01-27T17:20:08.442504 #93286] DEBUG -- : Duracloud::Client DELETE https
274
262
  => #<Duracloud::Content space_id="rest-api-testing", content_id="foo2", store_id=(default)>
275
263
 
276
264
  >> content.delete
277
- D, [2016-04-29T18:28:31.459962 #32379] DEBUG -- : Duracloud::Client DELETE https://foo.duracloud.org/durastore/rest-api-testing/foo2 200 OK
265
+ D, [2016-04-29T18:28:31.459962 #32379] DEBUG -- : Duracloud::Request DELETE https://foo.duracloud.org/durastore/rest-api-testing/foo2 200 OK
278
266
  I, [2016-04-29T18:28:31.460069 #32379] INFO -- : Content foo2 deleted successfully
279
267
  => #<Duracloud::Content space_id="rest-api-testing", content_id="foo2", store_id=(default)>
280
268
 
281
269
  >> Duracloud::Content.exist?(space_id: "rest-api-testing", content_id: "foo2")
282
- D, [2016-04-29T18:29:03.935451 #32379] DEBUG -- : Duracloud::Client HEAD https://foo.duracloud.org/durastore/rest-api-testing/foo2 404 Not Found
270
+ D, [2016-04-29T18:29:03.935451 #32379] DEBUG -- : Duracloud::Request HEAD https://foo.duracloud.org/durastore/rest-api-testing/foo2 404 Not Found
283
271
  => false
284
272
  ```
285
273
 
274
+ *Added in v0.10.0.pre* `Duracloud::Content.delete` class method.
275
+
286
276
  ### Reports
287
277
 
288
278
  The audit logs, bit integrity reports and manifests are accessible in their original TSV format and in normalized CSV tables.
@@ -295,7 +285,7 @@ The audit logs, bit integrity reports and manifests are accessible in their orig
295
285
  => #<Duracloud::AuditLog:0x007fd44c077f38 @space_id="rest-api-testing", @store_id=nil, @response=nil>
296
286
 
297
287
  >> audit_log.csv
298
- D, [2016-05-19T13:36:49.107520 #28754] DEBUG -- : Duracloud::Client GET https://duke.duracloud.org/durastore/audit/rest-api-testing 200 OK
288
+ D, [2016-05-19T13:36:49.107520 #28754] DEBUG -- : Duracloud::Request GET https://duke.duracloud.org/durastore/audit/rest-api-testing 200 OK
299
289
  => #<CSV::Table mode:col_or_row row_count:168>
300
290
  ```
301
291
 
@@ -307,20 +297,20 @@ D, [2016-05-19T13:36:49.107520 #28754] DEBUG -- : Duracloud::Client GET https://
307
297
  => #<Duracloud::Manifest:0x007fd44d3c7048 @space_id="rest-api-testing", @store_id=nil, @tsv_response=nil, @bagit_response=nil>
308
298
 
309
299
  >> manifest.csv
310
- D, [2016-05-19T13:37:39.831013 #28754] DEBUG -- : Duracloud::Client GET https://duke.duracloud.org/durastore/manifest/rest-api-testing 200 OK
300
+ D, [2016-05-19T13:37:39.831013 #28754] DEBUG -- : Duracloud::Request GET https://duke.duracloud.org/durastore/manifest/rest-api-testing 200 OK
311
301
  => #<CSV::Table mode:col_or_row row_count:10>
312
302
 
313
303
  >> manifest.csv.headers
314
304
  => ["space_id", "content_id", "md5"]
315
305
  ```
316
306
 
317
- *Added in v0.5.0: Support for asynchronous generation of manifest (Generate Manifest API)*
307
+ *Added in v0.5.0* Support for asynchronous generation of manifest (Generate Manifest API)
318
308
 
319
309
  ```
320
310
  >> manifest = Duracloud::Manifest.new('ddr-validation')
321
311
  => #<Duracloud::Manifest:0x007f8fd82fe328 @space_id="ddr-validation", @store_id=nil>
322
312
  >> manifest.generate
323
- D, [2017-06-06T20:49:50.191301 #92029] DEBUG -- : Duracloud::Client POST https://duke.duracloud.org/durastore/manifest/ddr-validation 202 Accepted
313
+ D, [2017-06-06T20:49:50.191301 #92029] DEBUG -- : Duracloud::Request POST https://duke.duracloud.org/durastore/manifest/ddr-validation 202 Accepted
324
314
  I, [2017-06-06T20:49:50.191414 #92029] INFO -- : We are processing your manifest generation request. To retrieve your file, please poll the URI in the Location header of this response: (https://duke.duracloud.org/durastore/x-duracloud-admin/generated-manifests/manifest-ddr-validation_amazon_s3_2017-06-07-00-49-50.txt.gz).
325
315
  => "https://duke.duracloud.org/durastore/x-duracloud-admin/generated-manifests/manifest-ddr-validation_amazon_s3_2017-06-07-00-49-50.txt.gz"
326
316
  ```
@@ -333,7 +323,7 @@ D, [2016-05-19T13:37:39.831013 #28754] DEBUG -- : Duracloud::Client GET https://
333
323
  => #<Duracloud::BitIntegrityReport:0x007f88e39a2950 @space_id="rest-api-testing", @store_id=nil, @report=nil, @properties=nil>
334
324
 
335
325
  >> bit_integrity_report.csv
336
- D, [2016-05-19T15:39:33.538448 #29974] DEBUG -- : Duracloud::Client GET https://duke.duracloud.org/durastore/bit-integrity/rest-api-testing 200 OK
326
+ D, [2016-05-19T15:39:33.538448 #29974] DEBUG -- : Duracloud::Request GET https://duke.duracloud.org/durastore/bit-integrity/rest-api-testing 200 OK
337
327
  => #<CSV::Table mode:col_or_row row_count:8>
338
328
  ```
339
329
 
data/duracloud.gemspec CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency "addressable", "~> 2.5"
24
24
  spec.add_dependency "hashie", "~> 3.4"
25
25
  spec.add_dependency "httpclient", "~> 2.7"
26
- spec.add_dependency "activemodel", ">= 4.2", "< 6"
27
26
  spec.add_dependency "nokogiri", "~> 1.6"
28
27
 
29
28
  spec.add_development_dependency "webmock", "~> 2.0"
data/lib/duracloud.rb CHANGED
@@ -1,7 +1,10 @@
1
- require "duracloud/version"
2
- require "duracloud/error"
1
+ require 'logger'
2
+ require 'uri'
3
+ require 'duracloud/version'
4
+ require 'duracloud/error'
3
5
 
4
6
  module Duracloud
7
+
5
8
  autoload :AbstractEntity, "duracloud/abstract_entity"
6
9
  autoload :AuditLog, "duracloud/audit_log"
7
10
  autoload :BitIntegrityReport, "duracloud/bit_integrity_report"
@@ -10,24 +13,47 @@ module Duracloud
10
13
  autoload :CLI, "duracloud/cli"
11
14
  autoload :CommandOptions, "duracloud/command_options"
12
15
  autoload :Commands, "duracloud/commands"
13
- autoload :Configuration, "duracloud/configuration"
14
- autoload :Connection, "duracloud/connection"
15
16
  autoload :Content, "duracloud/content"
16
17
  autoload :ContentManifest, "duracloud/content_manifest"
17
- autoload :DurastoreRequest, "duracloud/durastore_request"
18
- autoload :ErrorHandler, "duracloud/error_handler"
19
18
  autoload :FastSyncValidation, "duracloud/fast_sync_validation"
20
19
  autoload :Manifest, "duracloud/manifest"
21
- autoload :Persistence, "duracloud/persistence"
22
20
  autoload :Properties, "duracloud/properties"
23
21
  autoload :Request, "duracloud/request"
24
22
  autoload :Response, "duracloud/response"
23
+ autoload :ResponseHandler, "duracloud/response_handler"
25
24
  autoload :RestMethods, "duracloud/rest_methods"
26
25
  autoload :Space, "duracloud/space"
27
26
  autoload :SpaceAcls, "duracloud/space_acls"
28
- autoload :Store, "duracloud/store"
29
27
  autoload :StorageReport, "duracloud/storage_report"
30
28
  autoload :StorageReports, "duracloud/storage_reports"
29
+ autoload :Store, "duracloud/store"
31
30
  autoload :SyncValidation, "duracloud/sync_validation"
32
31
  autoload :TSV, "duracloud/tsv"
32
+
33
+ class << self
34
+ attr_accessor :host, :port, :user, :password
35
+ attr_writer :logger
36
+
37
+ def logger
38
+ @logger ||= Logger.new(STDERR)
39
+ end
40
+
41
+ def silence_logging!
42
+ self.logger = Logger.new(File::NULL)
43
+ end
44
+
45
+ def base_url
46
+ URI::HTTPS.build(host: host, port: port, path: '/')
47
+ end
48
+
49
+ def auth?
50
+ !!user
51
+ end
52
+ end
53
+
54
+ self.host = ENV["DURACLOUD_HOST"]
55
+ self.port = ENV["DURACLOUD_PORT"]
56
+ self.user = ENV["DURACLOUD_USER"]
57
+ self.password = ENV["DURACLOUD_PASSWORD"]
58
+
33
59
  end
@@ -1,30 +1,21 @@
1
- require "active_model"
1
+ require 'hashie'
2
2
 
3
3
  module Duracloud
4
- class AbstractEntity
5
- include ActiveModel::Model
6
- extend ActiveModel::Callbacks
7
-
8
- define_model_callbacks :save, :delete, :load_properties
9
- after_save :persisted!
10
- after_save :reset_properties
11
- after_load_properties :persisted!
12
- before_delete :reset_properties
13
- after_delete :deleted!
14
- after_delete :freeze
4
+ class AbstractEntity < Hashie::Dash
15
5
 
16
6
  def save
17
7
  raise Error, "Cannot save deleted #{self.class}." if deleted?
18
- run_callbacks :save do
19
- do_save
20
- end
8
+ do_save
9
+ persisted!
10
+ reset_properties
21
11
  end
22
12
 
23
13
  def delete
24
14
  raise Error, "Cannot delete, already deleted." if deleted?
25
- run_callbacks :delete do
26
- do_delete
27
- end
15
+ reset_properties
16
+ do_delete
17
+ deleted!
18
+ freeze
28
19
  end
29
20
 
30
21
  def persisted?
@@ -45,11 +36,9 @@ module Duracloud
45
36
  @properties ||= Properties.new
46
37
  end
47
38
 
48
-
49
39
  def load_properties
50
- run_callbacks :load_properties do
51
- do_load_properties
52
- end
40
+ do_load_properties
41
+ persisted!
53
42
  end
54
43
 
55
44
  private
data/lib/duracloud/cli.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  require 'optparse'
2
- require 'active_model'
2
+ require 'hashie'
3
3
 
4
4
  module Duracloud
5
- class CLI
6
- include ActiveModel::Model
5
+ class CLI < Hashie::Dash
7
6
  include Commands
8
7
 
9
8
  COMMANDS = Commands.public_instance_methods.map(&:to_s)
@@ -18,50 +17,48 @@ Options:
18
17
  EOS
19
18
  HELP = "Type 'duracloud -h/--help' for usage."
20
19
 
21
- attr_accessor :all_spaces,
22
- :command,
23
- :content_dir,
24
- :content_id,
25
- :content_type,
26
- :fast,
27
- :format,
28
- :host,
29
- :infile,
30
- :logging,
31
- :md5,
32
- :missing,
33
- :password,
34
- :port,
35
- :prefix,
36
- :space_id,
37
- :store_id,
38
- :user,
39
- :work_dir
40
-
41
- validates_presence_of :space_id, message: "-s/--space-id option is required.", unless: "command == 'get_storage_report'"
42
- validates_inclusion_of :command, in: COMMANDS
20
+ property :all_spaces
21
+ property :command, required: true
22
+ property :content_dir
23
+ property :content_id
24
+ property :content_type
25
+ property :fast
26
+ property :format
27
+ property :host
28
+ property :infile
29
+ property :logging
30
+ property :md5
31
+ property :missing
32
+ property :password
33
+ property :port
34
+ property :prefix
35
+ property :space_id, required: -> { command != "get_storage_report" }, message: "-s/--space-id option is required."
36
+ property :store_id
37
+ property :user
38
+ property :work_dir
43
39
 
44
40
  def self.error!(exception)
45
41
  $stderr.puts exception.message
46
- if [ CommandError, OptionParser::ParseError ].include?(exception.class)
42
+ if [ ArgumentError, CommandError, OptionParser::ParseError ].include?(exception.class)
47
43
  $stderr.puts HELP
48
44
  end
49
45
  exit(false)
50
46
  end
51
47
 
52
48
  def self.call(*args)
53
- options = CommandOptions.new(*args)
54
- cli = new(options) # .merge(command: command))
55
- if cli.invalid?
56
- message = cli.errors.map { |k, v| "ERROR: #{v}" }.join("\n")
57
- raise CommandError, message
58
- end
59
- cli.execute
49
+ new(*args).execute
60
50
  rescue => e
61
51
  error!(e)
62
52
  end
63
53
 
54
+ def initialize(*args)
55
+ super CommandOptions.parse(*args)
56
+ end
57
+
64
58
  def execute
59
+ unless COMMANDS.include?(command)
60
+ raise CommandError, "Invalid command: #{command.inspect}."
61
+ end
65
62
  configure_client
66
63
  send(command, self)
67
64
  end
@@ -69,14 +66,12 @@ EOS
69
66
  private
70
67
 
71
68
  def configure_client
72
- Client.configure do |config|
73
- config.user = user if user
74
- config.password = password if password
75
- config.host = host if host
76
- config.port = port if port
69
+ Duracloud.user = user if user
70
+ Duracloud.password = password if password
71
+ Duracloud.host = host if host
72
+ Duracloud.port = port if port
77
73
 
78
- config.silence_logging! unless logging
79
- end
74
+ Duracloud.silence_logging! unless logging
80
75
  end
81
76
 
82
77
  end