general_store 0.0.2 → 0.0.3
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 +4 -4
- data/lib/general_store.rb +19 -19
- data/lib/general_store/version.rb +2 -2
- data/spec/general_store/general_store_spec.rb +56 -0
- data/spec/spec_helper.rb +6 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b1cb6e862360a5486c578fc2abc59d7d157e6e1
|
4
|
+
data.tar.gz: a745ea7bb14ae0700f6c855a8b28da384fea19fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c70ca03dd249ba387b72d71f9e8ade89e40877fe01cba1bb3819d59b58ac5992c7eda63e3a922fd6dfec5a2a90db027aae6c9444d9636465c4809443292af5af
|
7
|
+
data.tar.gz: 59f7cf13980c65f028369bc58ddcb75b0e5fc66d341f34af641824881af2da9fef5181e6724afb7f04cec179c1d8abf0facb5521f263bed28d316546a5eecc26
|
data/lib/general_store.rb
CHANGED
@@ -4,6 +4,24 @@ require "ostruct"
|
|
4
4
|
class GeneralStore
|
5
5
|
attr_accessor :config
|
6
6
|
|
7
|
+
def self.read dir_name
|
8
|
+
new YAML.load_file config_file dir_name
|
9
|
+
rescue Errno::ENOENT
|
10
|
+
puts 'You need to setup your General Store first!'
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.create dir, ostruct = OpenStruct.new
|
14
|
+
@dir = dir
|
15
|
+
create_config_file
|
16
|
+
yield ostruct
|
17
|
+
new(ostruct.to_h).set dir
|
18
|
+
end
|
19
|
+
|
20
|
+
def set dir
|
21
|
+
klass = self.class
|
22
|
+
klass.write_file klass.config_file(dir), config
|
23
|
+
end
|
24
|
+
|
7
25
|
def initialize config_contents
|
8
26
|
self.config = config_contents
|
9
27
|
config.each do |k,v|
|
@@ -14,12 +32,7 @@ class GeneralStore
|
|
14
32
|
send("#{accessor}=", v)
|
15
33
|
end
|
16
34
|
end
|
17
|
-
|
18
|
-
def self.read dir_name
|
19
|
-
new YAML.load_file config_file dir_name
|
20
|
-
rescue Errno::ENOENT
|
21
|
-
puts 'You need to setup your General Store first!'
|
22
|
-
end
|
35
|
+
private_class_method :new
|
23
36
|
|
24
37
|
def self.config_file dir_name
|
25
38
|
File.expand_path File.join dir_name, "config.yml"
|
@@ -29,19 +42,6 @@ class GeneralStore
|
|
29
42
|
File.expand_path @dir
|
30
43
|
end
|
31
44
|
|
32
|
-
def self.create dir
|
33
|
-
@dir = dir
|
34
|
-
create_config_file
|
35
|
-
ostruct = OpenStruct.new
|
36
|
-
yield ostruct
|
37
|
-
new(ostruct.to_h).set dir
|
38
|
-
end
|
39
|
-
|
40
|
-
def set dir
|
41
|
-
klass = self.class
|
42
|
-
klass.write_file klass.config_file(dir), config
|
43
|
-
end
|
44
|
-
|
45
45
|
def self.create_config_file
|
46
46
|
check_dir_existence
|
47
47
|
check_file_existence
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0.
|
1
|
+
class GeneralStore
|
2
|
+
VERSION = "0.0.3"
|
3
3
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GeneralStore do
|
4
|
+
subject { GeneralStore }
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
subject.create project_path do |gs|
|
8
|
+
gs.test = 'test'
|
9
|
+
gs.token = 'token'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
after :each do
|
14
|
+
File.delete(project_path + "/config.yml") if File.exist?(project_path + "/config.yml")
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.create' do
|
18
|
+
it 'yields to ostruct' do
|
19
|
+
expect {|probe| subject.create(project_path, &probe) }
|
20
|
+
.to yield_control
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '.read' do
|
25
|
+
it 'reads the attributes' do
|
26
|
+
expect(subject.read(project_path).test)
|
27
|
+
.to eq('test')
|
28
|
+
|
29
|
+
expect(subject.read(project_path).token)
|
30
|
+
.to eq('token')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'world access' do
|
35
|
+
it 'is not world readable' do
|
36
|
+
file = subject.config_file project_path
|
37
|
+
expect(File.world_writable? file).to be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'is not world writable' do
|
41
|
+
file = subject.config_file project_path
|
42
|
+
expect(File.world_readable? file).to be_nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'private methods' do
|
47
|
+
let(:dir) { '~/.test-dir' }
|
48
|
+
|
49
|
+
describe 'class methods' do
|
50
|
+
it '.new' do
|
51
|
+
expect { subject.public_send :new }
|
52
|
+
.to raise_error NoMethodError, /private method/
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,6 +4,12 @@
|
|
4
4
|
# loaded once.
|
5
5
|
#
|
6
6
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
require 'general_store'
|
8
|
+
|
9
|
+
def project_path
|
10
|
+
File.expand_path("../..", __FILE__)
|
11
|
+
end
|
12
|
+
|
7
13
|
RSpec.configure do |config|
|
8
14
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
15
|
config.run_all_when_everything_filtered = true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: general_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stuart Nelson
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- general_store.gemspec
|
69
69
|
- lib/general_store.rb
|
70
70
|
- lib/general_store/version.rb
|
71
|
+
- spec/general_store/general_store_spec.rb
|
71
72
|
- spec/spec_helper.rb
|
72
73
|
homepage: ''
|
73
74
|
licenses:
|
@@ -89,9 +90,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
90
|
version: '0'
|
90
91
|
requirements: []
|
91
92
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.
|
93
|
+
rubygems_version: 2.1.5
|
93
94
|
signing_key:
|
94
95
|
specification_version: 4
|
95
96
|
summary: Directory and attributes go in, attributes come out
|
96
97
|
test_files:
|
98
|
+
- spec/general_store/general_store_spec.rb
|
97
99
|
- spec/spec_helper.rb
|