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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b1cb6e862360a5486c578fc2abc59d7d157e6e1
4
- data.tar.gz: a745ea7bb14ae0700f6c855a8b28da384fea19fe
3
+ metadata.gz: aa9778d57620827e5eb79a8a835107c6ce1b9287
4
+ data.tar.gz: 101bc186fbbf6d7c492749c8615cb296c848e3a4
5
5
  SHA512:
6
- metadata.gz: c70ca03dd249ba387b72d71f9e8ade89e40877fe01cba1bb3819d59b58ac5992c7eda63e3a922fd6dfec5a2a90db027aae6c9444d9636465c4809443292af5af
7
- data.tar.gz: 59f7cf13980c65f028369bc58ddcb75b0e5fc66d341f34af641824881af2da9fef5181e6724afb7f04cec179c1d8abf0facb5521f263bed28d316546a5eecc26
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
@@ -1,3 +1,3 @@
1
1
  class GeneralStore
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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 config_file dir_name
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
- @dir = dir
15
- create_config_file
15
+ create_config_file dir
16
16
  yield ostruct
17
- new(ostruct.to_h).set dir
17
+ new(ostruct.to_h, dir).set
18
18
  end
19
19
 
20
- def set dir
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 @dir
42
+ def self.config_dir dir
43
+ File.expand_path dir
43
44
  end
44
45
 
45
- def self.create_config_file
46
- check_dir_existence
47
- check_file_existence
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.check_dir_existence
57
- unless Dir.exists? config_dir
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.check_file_existence
63
- file = config_file @dir
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
@@ -7,7 +7,8 @@
7
7
  require 'general_store'
8
8
 
9
9
  def project_path
10
- File.expand_path("../..", __FILE__)
10
+ path = File.expand_path("../..", __FILE__)
11
+ path + '/tmp'
11
12
  end
12
13
 
13
14
  RSpec.configure do |config|
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.3
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-06 00:00:00.000000000 Z
11
+ date: 2013-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler