general_store 0.0.1 → 0.0.2
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/README.md +37 -2
- data/lib/general_store.rb +9 -2
- data/lib/general_store/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0fcdc610162d8cfc8ce79887f9a6b7e5dfbbf91
|
4
|
+
data.tar.gz: 339c04790979665714fbf03160d46240d97e5959
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8df4f776ab2f006532a6d50eb183756fdf975edacfd52ee40cacb47470e55de89ec74622842c10474e8c18c76eda3f49933034e30de2f958904ee13903c57e8b
|
7
|
+
data.tar.gz: 6b0441024dd5cec88771137b8e8da5645626e590cbd92b2b399133e744469e93a80b7566a446a453f7e5cc03344aafc8b70529c808015a38f497353e7b325a5d
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# GeneralStore
|
2
2
|
|
3
|
-
|
3
|
+
General Store is an easy way to store user-specific credentials for an
|
4
|
+
app on a user's machine.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -18,7 +19,41 @@ Or install it yourself as:
|
|
18
19
|
|
19
20
|
## Usage
|
20
21
|
|
21
|
-
|
22
|
+
Set the directory you want your `config.yml` file saved in, and push in
|
23
|
+
the values you want to store:
|
24
|
+
|
25
|
+
``` ruby
|
26
|
+
GeneralStore.create '~/.your_directory' do |gs|
|
27
|
+
gs.consumer_key = 'my key'
|
28
|
+
gs.consumer_secret = 'my secret'
|
29
|
+
gs.oauth_token = 'oauth token'
|
30
|
+
gs.oauth_token_secret = 'oauth token secret'
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
And then access them:
|
35
|
+
|
36
|
+
``` ruby
|
37
|
+
store = GeneralStore.read '~/.your_directory'
|
38
|
+
|
39
|
+
store.consumer_key
|
40
|
+
=> 'my key'
|
41
|
+
store.consumer_secret
|
42
|
+
=> 'my secret'
|
43
|
+
```
|
44
|
+
|
45
|
+
Apply any arbitrary name to your attributes when going into your store;
|
46
|
+
they will be accessible when you take them out:
|
47
|
+
|
48
|
+
``` ruby
|
49
|
+
GeneralStore.create '~/.some_other_dir' do |gs|
|
50
|
+
gs.SoMethIngCRAZY = 'I couldnt think of a good example'
|
51
|
+
end
|
52
|
+
|
53
|
+
store = GeneralStore.read '~/.some_other_dir'
|
54
|
+
store.SoMethIngCRAZY
|
55
|
+
=> 'I couldnt think of a good example'
|
56
|
+
```
|
22
57
|
|
23
58
|
## Contributing
|
24
59
|
|
data/lib/general_store.rb
CHANGED
@@ -38,7 +38,8 @@ class GeneralStore
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def set dir
|
41
|
-
|
41
|
+
klass = self.class
|
42
|
+
klass.write_file klass.config_file(dir), config
|
42
43
|
end
|
43
44
|
|
44
45
|
def self.create_config_file
|
@@ -46,6 +47,12 @@ class GeneralStore
|
|
46
47
|
check_file_existence
|
47
48
|
end
|
48
49
|
|
50
|
+
def self.write_file file, data
|
51
|
+
File.open file, File::RDWR|File::TRUNC|File::CREAT, 0600 do |config|
|
52
|
+
config.write YAML.dump data
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
49
56
|
def self.check_dir_existence
|
50
57
|
unless Dir.exists? config_dir
|
51
58
|
Dir.mkdir config_dir
|
@@ -55,7 +62,7 @@ class GeneralStore
|
|
55
62
|
def self.check_file_existence
|
56
63
|
file = config_file @dir
|
57
64
|
unless File.exists? file
|
58
|
-
|
65
|
+
write_file file, {}
|
59
66
|
end
|
60
67
|
end
|
61
68
|
end
|