turbotlib 0.0.8 → 0.0.9

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.
@@ -1,3 +1,3 @@
1
1
  module TurbotLib
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/lib/turbotlib.rb CHANGED
@@ -10,8 +10,15 @@ class Turbotlib
10
10
  end
11
11
 
12
12
  def data_dir
13
- set_up_data_dir
14
- data_dir_location
13
+ path_to("data")
14
+ end
15
+
16
+ def sources_dir
17
+ if in_production? && !is_admin?
18
+ raise "Only admins are permitted to write to `sources_dir`"
19
+ else
20
+ path_to("sources")
21
+ end
15
22
  end
16
23
 
17
24
  def save_var(key, val)
@@ -36,6 +43,10 @@ class Turbotlib
36
43
  !!ENV['MORPH_URL']
37
44
  end
38
45
 
46
+ def is_admin?
47
+ ENV['USER_ROLES'].to_s.split(",").include?("admin")
48
+ end
49
+
39
50
  def get_vars
40
51
  begin
41
52
  YAML.load_file(vars_path)
@@ -53,17 +64,19 @@ class Turbotlib
53
64
  "#{data_dir}/_vars.yml"
54
65
  end
55
66
 
56
- def data_dir_location
67
+ def path_to(dir)
57
68
  if in_production?
58
- "/data"
69
+ location = "/#{dir}"
59
70
  else
60
- "data"
71
+ location = dir
72
+ set_up_dir(location)
61
73
  end
74
+ location
62
75
  end
63
76
 
64
- def set_up_data_dir
77
+ def set_up_dir(location)
65
78
  begin
66
- Dir.mkdir(data_dir_location)
79
+ Dir.mkdir(location)
67
80
  rescue Errno::EEXIST
68
81
  end
69
82
  end
@@ -40,4 +40,44 @@ describe Turbotlib do
40
40
  end
41
41
  end
42
42
  end
43
+
44
+ describe "sources_dir" do
45
+ context "when developing" do
46
+ after do
47
+ FileUtils.rm_rf("sources")
48
+ end
49
+
50
+ it "should return sources" do
51
+ expect(Turbotlib.sources_dir).to eq("sources")
52
+ end
53
+
54
+ it "should create sources directory" do
55
+ Turbotlib.sources_dir
56
+ expect(File.exists?("sources")).to eq(true)
57
+ end
58
+ end
59
+
60
+ context "when running in morph" do
61
+ context "and not an admin" do
62
+ before do
63
+ allow(Turbotlib).to receive(:in_production?).and_return(true)
64
+ end
65
+
66
+ it "should raise exception" do
67
+ expect{Turbotlib.sources_dir}.to raise_error
68
+ end
69
+ end
70
+
71
+ context "and an admin" do
72
+ before do
73
+ allow(Turbotlib).to receive(:in_production?).and_return(true)
74
+ allow(Turbotlib).to receive(:is_admin?).and_return(true)
75
+ end
76
+
77
+ it "should return /sources" do
78
+ expect(Turbotlib.sources_dir).to eq("/sources")
79
+ end
80
+ end
81
+ end
82
+ end
43
83
  end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbotlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Turbot
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-08-11 00:00:00.000000000 Z
12
+ date: 2015-09-03 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: scraperwiki
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - '='
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - '='
25
28
  - !ruby/object:Gem::Version
@@ -36,26 +39,27 @@ files:
36
39
  homepage: http://turbot.opencorporates.com/
37
40
  licenses:
38
41
  - MIT
39
- metadata: {}
40
42
  post_install_message:
41
43
  rdoc_options: []
42
44
  require_paths:
43
45
  - lib
44
46
  required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
45
48
  requirements:
46
49
  - - ! '>='
47
50
  - !ruby/object:Gem::Version
48
51
  version: 1.9.2
49
52
  required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
50
54
  requirements:
51
55
  - - ! '>='
52
56
  - !ruby/object:Gem::Version
53
57
  version: '0'
54
58
  requirements: []
55
59
  rubyforge_project:
56
- rubygems_version: 2.2.2
60
+ rubygems_version: 1.8.23.2
57
61
  signing_key:
58
- specification_version: 4
62
+ specification_version: 3
59
63
  summary: Helpers for writing turbot bots.
60
64
  test_files: []
61
65
  has_rdoc:
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZTk5ZmY5N2RkMTc1YWVlOTU0ZTBlZjA2NzRjMDRkYTgzNDY2ZDY1Yg==
5
- data.tar.gz: !binary |-
6
- MWJiNzVlOTRjOWM5M2U1NTAyZjk1OGExY2RhMGUzMDVhZGVmYzU1Yw==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- NTJiOTNlMDc4YTI5NDMwMzFkMTFiYWE0MWE3YTkzZWYyNThmNTAzNDdjNjNh
10
- MjIyY2VhMWQzYTljYThjZGNhYjc2YmU2YzUwNTM0ZmEzNmJlOGI4ZWMyZmJk
11
- NTA5NGQxNjg3MzQ0ZDdkYzM1ZTczNDk0MjNkNGIzNDRiM2JmZTM=
12
- data.tar.gz: !binary |-
13
- ZTZkMzljZTUzMjFjMDIyZDI0ZGYwYTI0ZmU1YmQ4NTc3ZTY0Y2JiODZjNzk5
14
- YWU1ZTM0Mzk3ODhiZGI0NDE3MmZkZDUyNTgxMzkxNTg3MWU3ZDliMWMzZTQw
15
- NmRlMDg1YzIzNTFlNzc3NWIyZDFkMGQ1NjQ4NDQzODY1YWY0MGM=