general_store 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/general_store/version.rb +1 -1
- data/lib/general_store.rb +17 -18
- data/spec/general_store/general_store_spec.rb +12 -0
- data/spec/spec_helper.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa9778d57620827e5eb79a8a835107c6ce1b9287
|
4
|
+
data.tar.gz: 101bc186fbbf6d7c492749c8615cb296c848e3a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 134dc8ad9d73ddcb6fd33ed623e298f294f4ce63c20213de7e43d8eb19eb1c17ee6f494aab1f076bddf9f1f65bd053cd02a2e713c48a6950c2ac282a03086c60
|
7
|
+
data.tar.gz: fb94f6881b747ad8084921fd80bb7f201709630d43439233cd295651e6863c494ad51afaf618b5184498dae6a25d041bfff4e18582c7084b69cac64dc6220700
|
data/README.md
CHANGED
@@ -37,9 +37,9 @@ And then access them:
|
|
37
37
|
store = GeneralStore.read '~/.your_directory'
|
38
38
|
|
39
39
|
store.consumer_key
|
40
|
-
=> 'my key'
|
40
|
+
# => 'my key'
|
41
41
|
store.consumer_secret
|
42
|
-
=> 'my secret'
|
42
|
+
# => 'my secret'
|
43
43
|
```
|
44
44
|
|
45
45
|
Apply any arbitrary name to your attributes when going into your store;
|
@@ -52,7 +52,7 @@ end
|
|
52
52
|
|
53
53
|
store = GeneralStore.read '~/.some_other_dir'
|
54
54
|
store.SoMethIngCRAZY
|
55
|
-
=> 'I couldnt think of a good example'
|
55
|
+
# => 'I couldnt think of a good example'
|
56
56
|
```
|
57
57
|
|
58
58
|
## Contributing
|
data/lib/general_store.rb
CHANGED
@@ -1,29 +1,30 @@
|
|
1
1
|
require "yaml"
|
2
2
|
require "ostruct"
|
3
|
+
require "fileutils"
|
3
4
|
|
4
5
|
class GeneralStore
|
5
|
-
attr_accessor :config
|
6
|
+
attr_accessor :config, :dir
|
6
7
|
|
7
8
|
def self.read dir_name
|
8
|
-
new YAML.load_file
|
9
|
+
new YAML.load_file(config_file(dir_name)), dir_name
|
9
10
|
rescue Errno::ENOENT
|
10
11
|
puts 'You need to setup your General Store first!'
|
11
12
|
end
|
12
13
|
|
13
14
|
def self.create dir, ostruct = OpenStruct.new
|
14
|
-
|
15
|
-
create_config_file
|
15
|
+
create_config_file dir
|
16
16
|
yield ostruct
|
17
|
-
new(ostruct.to_h).set
|
17
|
+
new(ostruct.to_h, dir).set
|
18
18
|
end
|
19
19
|
|
20
|
-
def set
|
20
|
+
def set
|
21
21
|
klass = self.class
|
22
22
|
klass.write_file klass.config_file(dir), config
|
23
23
|
end
|
24
24
|
|
25
|
-
def initialize config_contents
|
25
|
+
def initialize config_contents, dir
|
26
26
|
self.config = config_contents
|
27
|
+
self.dir = dir
|
27
28
|
config.each do |k,v|
|
28
29
|
accessor = k.to_sym
|
29
30
|
self.class.class_eval do
|
@@ -38,13 +39,13 @@ class GeneralStore
|
|
38
39
|
File.expand_path File.join dir_name, "config.yml"
|
39
40
|
end
|
40
41
|
|
41
|
-
def self.config_dir
|
42
|
-
File.expand_path
|
42
|
+
def self.config_dir dir
|
43
|
+
File.expand_path dir
|
43
44
|
end
|
44
45
|
|
45
|
-
def self.create_config_file
|
46
|
-
|
47
|
-
|
46
|
+
def self.create_config_file dir
|
47
|
+
ensure_dir_existence dir
|
48
|
+
ensure_file_existence dir
|
48
49
|
end
|
49
50
|
|
50
51
|
def self.write_file file, data
|
@@ -53,14 +54,12 @@ class GeneralStore
|
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
56
|
-
def self.
|
57
|
-
|
58
|
-
Dir.mkdir config_dir
|
59
|
-
end
|
57
|
+
def self.ensure_dir_existence dir
|
58
|
+
FileUtils.mkdir_p config_dir dir
|
60
59
|
end
|
61
60
|
|
62
|
-
def self.
|
63
|
-
file = config_file
|
61
|
+
def self.ensure_file_existence dir
|
62
|
+
file = config_file dir
|
64
63
|
unless File.exists? file
|
65
64
|
write_file file, {}
|
66
65
|
end
|
@@ -12,6 +12,7 @@ describe GeneralStore do
|
|
12
12
|
|
13
13
|
after :each do
|
14
14
|
File.delete(project_path + "/config.yml") if File.exist?(project_path + "/config.yml")
|
15
|
+
Dir.rmdir project_path if Dir.exist? project_path
|
15
16
|
end
|
16
17
|
|
17
18
|
describe '.create' do
|
@@ -19,6 +20,17 @@ describe GeneralStore do
|
|
19
20
|
expect {|probe| subject.create(project_path, &probe) }
|
20
21
|
.to yield_control
|
21
22
|
end
|
23
|
+
|
24
|
+
it 'creates the config.yml file' do
|
25
|
+
file = GeneralStore.config_file project_path
|
26
|
+
expect(File.exists? file).to be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'handles deeply nested folders' do
|
30
|
+
expect {
|
31
|
+
subject.create('~/nested/folder/path') {}
|
32
|
+
}.not_to raise_error
|
33
|
+
end
|
22
34
|
end
|
23
35
|
|
24
36
|
describe '.read' do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stuart Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|