quandl 0.2.27 → 0.3.0
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 +8 -8
- data/README.md +70 -17
- data/Rakefile +7 -86
- data/UPGRADE.md +23 -0
- data/VERSION +1 -0
- data/lib/quandl/command.rb +11 -3
- data/lib/quandl/command/config.rb +88 -0
- data/lib/quandl/command/presenter.rb +74 -0
- data/lib/quandl/command/presenter/record.rb +121 -0
- data/lib/quandl/command/presenters/dataset_presenter.rb +19 -0
- data/lib/quandl/command/presenters/error_presenter.rb +31 -0
- data/lib/quandl/command/presenters/nil_class_presenter.rb +10 -0
- data/lib/quandl/command/presenters/scraper_presenter.rb +25 -0
- data/lib/quandl/command/presenters/superset_presenter.rb +10 -0
- data/lib/quandl/command/task.rb +40 -0
- data/lib/quandl/command/task/callbacks.rb +47 -0
- data/lib/quandl/command/task/clientable.rb +65 -0
- data/lib/quandl/command/task/commandable.rb +104 -0
- data/lib/quandl/command/task/configurable.rb +79 -0
- data/lib/quandl/command/task/inputable.rb +37 -0
- data/lib/quandl/command/task/logging.rb +83 -0
- data/lib/quandl/command/task/presentation.rb +37 -0
- data/lib/quandl/command/task/reportable.rb +35 -0
- data/lib/quandl/command/task/threading.rb +117 -0
- data/lib/quandl/command/task/translations.rb +37 -0
- data/lib/quandl/command/task/updatable.rb +77 -0
- data/lib/quandl/command/tasks.rb +6 -5
- data/lib/quandl/command/tasks/delete.rb +10 -67
- data/lib/quandl/command/tasks/download.rb +11 -78
- data/lib/quandl/command/tasks/info.rb +2 -2
- data/lib/quandl/command/tasks/list.rb +12 -24
- data/lib/quandl/command/tasks/login.rb +4 -4
- data/lib/quandl/command/tasks/replace.rb +58 -0
- data/lib/quandl/command/tasks/schedule.rb +106 -0
- data/lib/quandl/command/tasks/search.rb +39 -0
- data/lib/quandl/command/tasks/superset.rb +59 -0
- data/lib/quandl/command/tasks/uninstall.rb +1 -1
- data/lib/quandl/command/tasks/update.rb +2 -2
- data/lib/quandl/command/tasks/upload.rb +13 -26
- data/lib/quandl/command/version.rb +1 -1
- data/quandl.gemspec +5 -3
- data/spec/fixtures/scraper.rb +6 -0
- data/spec/lib/quandl/command/delete_spec.rb +19 -11
- data/spec/lib/quandl/command/download_spec.rb +11 -4
- data/spec/lib/quandl/command/replace_spec.rb +23 -0
- data/spec/lib/quandl/command/schedule_spec.rb +53 -0
- data/spec/lib/quandl/command/superset_spec.rb +28 -0
- data/spec/lib/quandl/command/upload_spec.rb +71 -24
- data/spec/lib/quandl/command_spec.rb +1 -9
- data/spec/spec_helper.rb +36 -1
- data/tasks/toolbelt/build/tarball.rb +2 -2
- metadata +55 -10
- data/lib/quandl/command/qconfig.rb +0 -86
- data/lib/quandl/command/tasks/base.rb +0 -314
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'open3'
|
4
|
+
require 'quandl/client'
|
5
|
+
require 'quandl/format'
|
6
|
+
|
7
|
+
describe "./bin/quandl superset" do
|
8
|
+
|
9
|
+
let(:command){ self.class.superclass.description }
|
10
|
+
subject{ quandl("superset #{command}") }
|
11
|
+
|
12
|
+
context "new" do
|
13
|
+
its(:stdout){ should match Quandl::Client::Superset.example.to_qdf }
|
14
|
+
end
|
15
|
+
|
16
|
+
context "upload spec/fixtures/superset.qdf" do
|
17
|
+
its(:stdout){ should match /Created|OK/ }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "download SUPERSET_EXAMPLE" do
|
21
|
+
its(:stdout){ should match /SUPERSET_EXAMPLE/ }
|
22
|
+
end
|
23
|
+
|
24
|
+
context "delete SUPERSET_EXAMPLE" do
|
25
|
+
its(:stdout){ should match /OK/ }
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -1,39 +1,86 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe "./bin/quandl upload" do
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
let(:prefix){ "upload" }
|
7
|
+
let(:command){ self.class.superclass.description }
|
8
|
+
subject{ quandl( [prefix, command].flatten.join(" ") ) }
|
9
|
+
|
10
|
+
context data_path("datasets.qdf") do
|
11
|
+
its(:stdout){ should match /OK|Created/ }
|
12
|
+
its(:stderr){ should be_blank }
|
9
13
|
end
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
context data_path("metadata.qdf") do
|
16
|
+
its(:stdout){ should match /OK|Created/ }
|
17
|
+
its(:stderr){ should be_blank }
|
14
18
|
end
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
20
|
+
context data_path("QUGC-42.qdf") do
|
21
|
+
its(:stdout){ should match /OK|Created/ }
|
22
|
+
its(:stderr){ should be_blank }
|
19
23
|
end
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
context error_path("invalid_code.qdf") do
|
26
|
+
its(:stdout){ should match /Unprocessable Entity/ }
|
27
|
+
end
|
28
|
+
|
29
|
+
context error_path("column_count_mismatch.qdf") do
|
30
|
+
its(:stdout){ should match /Found 4 but expected 3 based on/ }
|
31
|
+
end
|
32
|
+
|
33
|
+
context error_path("date_parse_error.qdf") do
|
34
|
+
its(:stdout){ should match /Invalid date segments/ }
|
35
|
+
end
|
36
|
+
|
37
|
+
context error_path("invalid_date.qdf") do
|
38
|
+
its(:stdout){ should match /Invalid date/ }
|
39
|
+
end
|
40
|
+
|
41
|
+
context error_path("invalid_dash.qdf") do
|
42
|
+
its(:stdout){ should match /Unprocessable Entity | Error | Psych::SyntaxError | Error parsing metadata. Could not find expected ':' on line 3./ }
|
26
43
|
end
|
27
44
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
45
|
+
context error_path("psych.qdf") do
|
46
|
+
its(:stdout){ should match /Could not find expected ':'/ }
|
47
|
+
end
|
48
|
+
|
49
|
+
context error_path("unknown_attribute.qdf") do
|
50
|
+
its(:stdout){ should match /UnknownAttribute/ }
|
51
|
+
end
|
52
|
+
|
53
|
+
context "json" do
|
54
|
+
|
55
|
+
let(:prefix){ "upload" }
|
56
|
+
let(:command){ self.class.superclass.description }
|
57
|
+
subject{
|
58
|
+
result = quandl( [prefix, command, "-F json"].flatten.join(" ") )
|
59
|
+
OpenStruct.new(
|
60
|
+
stdout: result.stdout,
|
61
|
+
stderr: result.stderr,
|
62
|
+
stdout_json: result.stdout.split("\n").collect{|l| JSON.parse(l) },
|
63
|
+
)
|
64
|
+
}
|
34
65
|
|
35
|
-
|
36
|
-
|
37
|
-
|
66
|
+
context data_path("metadata.qdf") do
|
67
|
+
its(:stderr){ should be_blank }
|
68
|
+
its(:stdout_json){ should be_a Array }
|
69
|
+
its('stdout_json.first'){ should have_key 'status' }
|
70
|
+
its('stdout_json.first'){ should have_key 'id' }
|
71
|
+
its('stdout_json.first'){ should have_key 'detail' }
|
72
|
+
its('stdout_json.first'){ should have_key 'message' }
|
73
|
+
its('stdout_json.first'){ should have_key 'attributes' }
|
74
|
+
end
|
75
|
+
|
76
|
+
context error_path("unknown_attribute.qdf") do
|
77
|
+
its('stdout_json.first'){ should have_key 'status' }
|
78
|
+
its('stdout_json.first'){ should have_key 'id' }
|
79
|
+
its('stdout_json.first'){ should have_key 'detail' }
|
80
|
+
its('stdout_json.first'){ should have_key 'message' }
|
81
|
+
its(:stdout_json){ should eq([{"status"=>"Unprocessable Entity", "id"=>"Error", "detail"=>"Quandl::Error::UnknownAttribute", "message"=>"UNKNOWN_ATTRIBUTE_CODE_2 error around line 13\nUnknown Field 'this_attribute_does_not_exist' valid fields are: source_code, code, name, description, private, reference_url, frequency (Quandl::Error::UnknownAttribute)\n"}, {"status"=>"Unprocessable Entity", "id"=>"Error", "detail"=>"Quandl::Error::UnknownAttribute", "message"=>"UNKNOWN_ATTRIBUTE_CODE_3 error around line 25\nUnknown Field 'horse' valid fields are: source_code, code, name, description, private, reference_url, frequency (Quandl::Error::UnknownAttribute)\n"}, {"status"=>"Unprocessable Entity", "id"=>"Error", "detail"=>"Quandl::Error::UnknownAttribute", "message"=>"UNKNOWN_ATTRIBUTE_CODE_4 error around line 37\nUnknown Field 'mouse' valid fields are: source_code, code, name, description, private, reference_url, frequency (Quandl::Error::UnknownAttribute)\n"}]) }
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
38
85
|
|
39
86
|
end
|
@@ -2,14 +2,6 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
require 'open3'
|
4
4
|
|
5
|
-
def quandl(statement)
|
6
|
-
version = "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
|
7
|
-
path = File.join(Quandl::Command::Tasks.root, 'bin/quandl')
|
8
|
-
command = "rvm #{version} do bundle exec #{path} #{statement} --token #{ENV['QUANDL_TEST_TOKEN']} --url #{ENV['QUANDL_TEST_URL']} "
|
9
|
-
stdin, stdout, stderr = Open3.popen3(command)
|
10
|
-
OpenStruct.new( stderr: stderr.read, stdout: stdout.read )
|
11
|
-
end
|
12
|
-
|
13
5
|
describe "./bin/quandl" do
|
14
6
|
|
15
7
|
let(:command){ self.class.superclass.description }
|
@@ -31,7 +23,7 @@ describe "./bin/quandl" do
|
|
31
23
|
end
|
32
24
|
|
33
25
|
context "delete TEST_1 TEST_5 TEST_15 --force-yes" do
|
34
|
-
its(:stdout){ should match '
|
26
|
+
its(:stdout){ should match 'OK' }
|
35
27
|
end
|
36
28
|
|
37
29
|
context "info" do
|
data/spec/spec_helper.rb
CHANGED
@@ -8,13 +8,48 @@ require 'factory_girl'
|
|
8
8
|
require 'pry'
|
9
9
|
require 'commander'
|
10
10
|
require 'quandl/command'
|
11
|
+
require 'open3'
|
11
12
|
|
12
13
|
# disable log output
|
13
|
-
|
14
|
+
class TestOutput
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def info(*args)
|
18
|
+
puts(*args)
|
19
|
+
end
|
20
|
+
def fatal(*args)
|
21
|
+
puts(*args)
|
22
|
+
end
|
23
|
+
def error(*args)
|
24
|
+
puts(*args)
|
25
|
+
end
|
26
|
+
def debug(*args)
|
27
|
+
puts(*args)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
Quandl::Logger.use(TestOutput)
|
14
33
|
|
15
34
|
factory_dir = File.join( File.dirname(__FILE__), 'factories/**/*.rb' )
|
16
35
|
Dir.glob( factory_dir ).each{|f| require(f); puts f }
|
17
36
|
|
18
37
|
RSpec.configure do |config|
|
19
38
|
config.include FactoryGirl::Syntax::Methods
|
39
|
+
end
|
40
|
+
|
41
|
+
def quandl(statement)
|
42
|
+
version = "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
|
43
|
+
path = File.join(Quandl::Command::Tasks.root, 'bin/quandl')
|
44
|
+
command = "bundle exec #{path} #{statement} --token #{ENV['QUANDL_TEST_TOKEN']} --url #{ENV['QUANDL_TEST_URL']} --force-yes --trace"
|
45
|
+
stdin, stdout, stderr = Open3.popen3(command)
|
46
|
+
OpenStruct.new( stderr: stderr.read, stdout: stdout.read )
|
47
|
+
end
|
48
|
+
|
49
|
+
def data_path(path)
|
50
|
+
File.join("spec/fixtures/data/", path)
|
51
|
+
end
|
52
|
+
|
53
|
+
def error_path(path)
|
54
|
+
File.join("spec/fixtures/data/errors/", path)
|
20
55
|
end
|
@@ -28,7 +28,7 @@ class Tasks::Toolbelt::Build::Tarball < Tasks::Toolbelt
|
|
28
28
|
|
29
29
|
def copy_files_into_release
|
30
30
|
# for each path
|
31
|
-
['lib', 'bin', 'config'].each do |path|
|
31
|
+
['lib', 'bin', 'config', 'VERSION'].each do |path|
|
32
32
|
# recursively copy into release
|
33
33
|
cp_r File.join( root_path, path ), File.join( release_path, path )
|
34
34
|
end
|
@@ -41,7 +41,7 @@ class Tasks::Toolbelt::Build::Tarball < Tasks::Toolbelt
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def append_revision_to_release_version
|
44
|
-
version_file = File.join( release_path, '
|
44
|
+
version_file = File.join( release_path, 'VERSION')
|
45
45
|
IO.write(version_file, File.open(version_file) do |f|
|
46
46
|
f.read.gsub(version, "#{version}-#{revision}")
|
47
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quandl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Hilscher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|
@@ -30,42 +30,42 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.2
|
33
|
+
version: 0.4.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.2
|
40
|
+
version: 0.4.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: quandl_client
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2.
|
47
|
+
version: 2.7.4
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2.
|
54
|
+
version: 2.7.4
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: quandl_data
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
61
|
+
version: 1.4.1
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
68
|
+
version: 1.4.1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: quandl_operation
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -262,6 +262,20 @@ dependencies:
|
|
262
262
|
- - ~>
|
263
263
|
- !ruby/object:Gem::Version
|
264
264
|
version: '4.2'
|
265
|
+
- !ruby/object:Gem::Dependency
|
266
|
+
name: quandl_utility
|
267
|
+
requirement: !ruby/object:Gem::Requirement
|
268
|
+
requirements:
|
269
|
+
- - ! '>='
|
270
|
+
- !ruby/object:Gem::Version
|
271
|
+
version: '0'
|
272
|
+
type: :development
|
273
|
+
prerelease: false
|
274
|
+
version_requirements: !ruby/object:Gem::Requirement
|
275
|
+
requirements:
|
276
|
+
- - ! '>='
|
277
|
+
- !ruby/object:Gem::Version
|
278
|
+
version: '0'
|
265
279
|
description: http://quandl.com/help/toolbelt
|
266
280
|
email:
|
267
281
|
- blake@hilscher.ca
|
@@ -278,6 +292,7 @@ files:
|
|
278
292
|
- README.md
|
279
293
|
- Rakefile
|
280
294
|
- UPGRADE.md
|
295
|
+
- VERSION
|
281
296
|
- bin/quandl
|
282
297
|
- config/locales/en.yml
|
283
298
|
- dist/resources/pkg/Distribution.erb
|
@@ -290,14 +305,36 @@ files:
|
|
290
305
|
- lib/quandl/command/client_ext.rb
|
291
306
|
- lib/quandl/command/client_ext/user.rb
|
292
307
|
- lib/quandl/command/compatibility_check.rb
|
293
|
-
- lib/quandl/command/
|
308
|
+
- lib/quandl/command/config.rb
|
309
|
+
- lib/quandl/command/presenter.rb
|
310
|
+
- lib/quandl/command/presenter/record.rb
|
311
|
+
- lib/quandl/command/presenters/dataset_presenter.rb
|
312
|
+
- lib/quandl/command/presenters/error_presenter.rb
|
313
|
+
- lib/quandl/command/presenters/nil_class_presenter.rb
|
314
|
+
- lib/quandl/command/presenters/scraper_presenter.rb
|
315
|
+
- lib/quandl/command/presenters/superset_presenter.rb
|
316
|
+
- lib/quandl/command/task.rb
|
317
|
+
- lib/quandl/command/task/callbacks.rb
|
318
|
+
- lib/quandl/command/task/clientable.rb
|
319
|
+
- lib/quandl/command/task/commandable.rb
|
320
|
+
- lib/quandl/command/task/configurable.rb
|
321
|
+
- lib/quandl/command/task/inputable.rb
|
322
|
+
- lib/quandl/command/task/logging.rb
|
323
|
+
- lib/quandl/command/task/presentation.rb
|
324
|
+
- lib/quandl/command/task/reportable.rb
|
325
|
+
- lib/quandl/command/task/threading.rb
|
326
|
+
- lib/quandl/command/task/translations.rb
|
327
|
+
- lib/quandl/command/task/updatable.rb
|
294
328
|
- lib/quandl/command/tasks.rb
|
295
|
-
- lib/quandl/command/tasks/base.rb
|
296
329
|
- lib/quandl/command/tasks/delete.rb
|
297
330
|
- lib/quandl/command/tasks/download.rb
|
298
331
|
- lib/quandl/command/tasks/info.rb
|
299
332
|
- lib/quandl/command/tasks/list.rb
|
300
333
|
- lib/quandl/command/tasks/login.rb
|
334
|
+
- lib/quandl/command/tasks/replace.rb
|
335
|
+
- lib/quandl/command/tasks/schedule.rb
|
336
|
+
- lib/quandl/command/tasks/search.rb
|
337
|
+
- lib/quandl/command/tasks/superset.rb
|
301
338
|
- lib/quandl/command/tasks/uninstall.rb
|
302
339
|
- lib/quandl/command/tasks/update.rb
|
303
340
|
- lib/quandl/command/tasks/upload.rb
|
@@ -310,8 +347,12 @@ files:
|
|
310
347
|
- scripts/compile_ruby_pkg.sh
|
311
348
|
- scripts/install.sh
|
312
349
|
- scripts/win/quandl_toolbelt.iss
|
350
|
+
- spec/fixtures/scraper.rb
|
313
351
|
- spec/lib/quandl/command/delete_spec.rb
|
314
352
|
- spec/lib/quandl/command/download_spec.rb
|
353
|
+
- spec/lib/quandl/command/replace_spec.rb
|
354
|
+
- spec/lib/quandl/command/schedule_spec.rb
|
355
|
+
- spec/lib/quandl/command/superset_spec.rb
|
315
356
|
- spec/lib/quandl/command/upload_spec.rb
|
316
357
|
- spec/lib/quandl/command_spec.rb
|
317
358
|
- spec/spec_helper.rb
|
@@ -350,8 +391,12 @@ signing_key:
|
|
350
391
|
specification_version: 4
|
351
392
|
summary: Quandl Toolbelt
|
352
393
|
test_files:
|
394
|
+
- spec/fixtures/scraper.rb
|
353
395
|
- spec/lib/quandl/command/delete_spec.rb
|
354
396
|
- spec/lib/quandl/command/download_spec.rb
|
397
|
+
- spec/lib/quandl/command/replace_spec.rb
|
398
|
+
- spec/lib/quandl/command/schedule_spec.rb
|
399
|
+
- spec/lib/quandl/command/superset_spec.rb
|
355
400
|
- spec/lib/quandl/command/upload_spec.rb
|
356
401
|
- spec/lib/quandl/command_spec.rb
|
357
402
|
- spec/spec_helper.rb
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'yaml'
|
3
|
-
require 'ostruct'
|
4
|
-
|
5
|
-
module Quandl
|
6
|
-
module Command
|
7
|
-
class QConfig
|
8
|
-
|
9
|
-
class << self
|
10
|
-
|
11
|
-
def configuration
|
12
|
-
@configuration ||= self.new( config_file: config_file )
|
13
|
-
end
|
14
|
-
|
15
|
-
def config_file
|
16
|
-
return @config_file if defined?(@config_file)
|
17
|
-
@config_file = File.join(root_path, 'config')
|
18
|
-
convert_legacy_config
|
19
|
-
ensure_directory_is_present
|
20
|
-
@config_file
|
21
|
-
end
|
22
|
-
|
23
|
-
def root_path
|
24
|
-
@root_path ||= File.join(ENV['HOME'], '.quandl')
|
25
|
-
end
|
26
|
-
|
27
|
-
protected
|
28
|
-
|
29
|
-
def ensure_directory_is_present
|
30
|
-
return if File.exists?(config_file)
|
31
|
-
FileUtils.mkdir(root_path) unless Dir.exists?(root_path)
|
32
|
-
File.write( config_file, YAML.dump({}) )
|
33
|
-
end
|
34
|
-
|
35
|
-
def convert_legacy_config
|
36
|
-
return if File.directory?(root_path) || !File.exists?(root_path)
|
37
|
-
# otherwise move the old .quandl into .quandl/config
|
38
|
-
FileUtils.mv(root_path, "#{root_path}.old")
|
39
|
-
FileUtils.mkdir(root_path)
|
40
|
-
token = File.read("#{root_path}.old")
|
41
|
-
File.write(config_file, "token: #{token}")
|
42
|
-
end
|
43
|
-
|
44
|
-
def define_attributes(*attr_names)
|
45
|
-
attr_names.each do |attr_name|
|
46
|
-
define_attribute(attr_name)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def define_attribute(name)
|
51
|
-
define_method(name){ read_attribute(name) }
|
52
|
-
define_method("#{name}="){|v| write_attribute(name, v) }
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
attr_accessor :options
|
58
|
-
|
59
|
-
define_attributes :token, :quandl_url, :last_checked_for_update
|
60
|
-
|
61
|
-
def initialize(*args)
|
62
|
-
self.options = OpenStruct.new(args.extract_options!)
|
63
|
-
end
|
64
|
-
|
65
|
-
def config
|
66
|
-
@config ||= OpenStruct.new(YAML.load(File.read(options.config_file)))
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
70
|
-
|
71
|
-
def read_attribute(name)
|
72
|
-
config.send(name)
|
73
|
-
end
|
74
|
-
|
75
|
-
def write_attribute(name, value)
|
76
|
-
config.send("#{name}=", value)
|
77
|
-
commit_config
|
78
|
-
end
|
79
|
-
|
80
|
-
def commit_config
|
81
|
-
File.write( options.config_file, YAML.dump(config.marshal_dump) )
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|