cabi 0.1.1 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb182df9ed5993329f7ae5ab75021a2841c95a1d
4
- data.tar.gz: 99cb126fd223820989b2dd16e7df542426834bd1
3
+ metadata.gz: cec2656830ddd4ae65fba64c3821363be983765b
4
+ data.tar.gz: 25638dce3ba1f2f014f2629e190cf9ca9a7af450
5
5
  SHA512:
6
- metadata.gz: 6b1ae9a7cb08d2353d3dc25b43f59c5de4e7bc2db01aca962d65fbfaf6e527477553ea1f159cf83e6ce2b7494a120c8be838211919c699d36eef27f133426200
7
- data.tar.gz: ca256fb320b45f733c92b2ea772ca4c78fa73e7fab9009ff71aef7cbd8e22bae285c8bc840e4e3ec913e61e2dcdb6ecc6e0d67475bfbd46fcf6e1e3cec052a3f
6
+ metadata.gz: 5ebf6f96dd020f6ac2149ce3b6a2c47a584270d0a3e031d5b239ddbe197b1be4c1401884c9c75841ecb7f37269ebe7fc415d880ff1c27ac754c157992f4a3f28
7
+ data.tar.gz: ba777a2f2eaa0f25048341d9c72ef93fbe360782b015c51954f6add362bc3667e66232aae71cb8dcf9d1bf368003df2b570b29ba049276db36304ceb46090c9a
data/README.md CHANGED
@@ -8,7 +8,7 @@ Cabi is a flat-file datastore where data is stored by directory stucture and acc
8
8
 
9
9
  ``` bash
10
10
  $ gem install cabi
11
- $ cabi init --mock # use --mock to init cabi cache with some fake data
11
+ $ cabi init --mock # use --mock to init cabi data with some fake data
12
12
  ```
13
13
 
14
14
  Then access your data like so:
@@ -22,7 +22,7 @@ $ irb
22
22
 
23
23
  ### Usage
24
24
 
25
- Assuming your `cabi-cache` folder has the following structure:
25
+ Assuming your `cabi-data` folder has the following structure:
26
26
 
27
27
  .
28
28
  ├── info.yml
@@ -55,18 +55,18 @@ Cabi.read('posts:some-article:index.html') # contents of posts/some-article/i
55
55
  # selection will work.
56
56
  Cabi.read('pages:about:*') # an array of body.html and meta.yml contents
57
57
  Cabi.read('pages:about:person-*') # an array of all person-* html files
58
- Cabi.read('**/**') # an array of all files in cache
58
+ Cabi.read('**/*') # an array of all files in data
59
59
 
60
60
  # Selection within YAML files
61
61
  Cabi.read('pages:about:meta:foo:bar') # contents of ['foo']['bar'] in page/about/meta.yml hash
62
62
  Cabi.read('info:foo:bar:baz') # contents of ['foo']['bar']['baz'] in info.yml hash
63
63
  ```
64
64
 
65
- ### Custom Cache Directory
65
+ ### Custom Data Directory
66
66
 
67
- Cabi assumes that your cache directory is either a folder at the top level of your project with a `.cabi-cache` file in it (to indicate that it's the cache directory). If one is not found, the cache directory defaults to `./cabi-cache`.
67
+ Cabi assumes that your data directory is either a folder at the top level of your project with a `.cabi-data` file in it (to indicate that it's the data directory). If one is not found, the data directory defaults to `./cabi-data`.
68
68
 
69
- For instance, if you had a folder called `super-cache` located inside of your project's root that had a file called `.cabi-cache` inside of it, this folder would be treated as your cache directory.
69
+ For instance, if you had a folder called `super-data` located inside of your project's root that had a file called `.cabi-data` inside of it, this folder would be treated as your data directory.
70
70
 
71
71
  ### Icon <img src="https://rawgithub.com/briangonzalez/cabi-gem/master/data/cabi.svg" width=20 style="margin-right: 10px">
72
72
 
data/bin/cabi CHANGED
@@ -6,33 +6,33 @@ require File.join( File.expand_path("../..", __FILE__), "lib", "cabi")
6
6
 
7
7
  class CabiCLI < Thor
8
8
 
9
- desc "init", "Initialize Cabi cache directory (use --mock to create fake data, use --target to specify your own directory)"
9
+ desc "init", "Initialize Cabi data directory (use --mock to create fake data, use --target to specify your own directory)"
10
10
  method_options :mock => :boolean, :target => :string
11
11
  def init
12
12
 
13
- target = options[:target] || Cabi::CABI_CACHE_DIR
13
+ target = options[:target] || Cabi::CABI_DATA_DIR
14
14
  FileUtils.mkdir( target )
15
15
 
16
16
  if options[:mock]
17
- f = File.expand_path( "../../data/cabi-cache.tar.gz", __FILE__ )
18
- `tar -xf #{f} --strip-components=2 -C #{target}`
17
+ f = File.expand_path( "../../data/cabi-data.tar.gz", __FILE__ )
18
+ `tar -xf #{f} --strip-components=1 -C #{target}`
19
19
  end
20
20
 
21
- puts " ** Cabi cache created in #{target}"
21
+ puts " ** Cabi data created in #{target}"
22
22
  end
23
23
 
24
- desc "clean", "Remove Cabi cache directory"
24
+ desc "clean", "Remove Cabi data directory"
25
25
  method_options :force => :boolean
26
26
  def clean
27
27
  if options[:force]
28
28
  begin
29
- FileUtils.rm_rf( Cabi.cache_dir )
30
- FileUtils.rm_rf( Cabi::CABI_CACHE_DIR)
31
- puts " ** Cleaned cabi cache"
29
+ FileUtils.rm_rf( Cabi.data_dir )
30
+ FileUtils.rm_rf( Cabi::CABI_DATA_DIR)
31
+ puts " ** Cleaned cabi data"
32
32
  rescue Exception => e
33
33
  end
34
34
  else
35
- puts " ** Not cleaning cabi cache without --force"
35
+ puts " ** Not cleaning cabi data folder without --force"
36
36
  end
37
37
  end
38
38
 
data/cabi.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'cabi'
3
- s.version = '0.1.1'
3
+ s.version = '0.1.2'
4
4
  s.summary = "A simple, flat-file datastore for Ruby."
5
5
 
6
6
  s.description = "Cabi is a flat-file datastore where data is stored by directory stucture and accessed by colon-delimited strings."
data/lib/cabi.rb CHANGED
@@ -10,15 +10,15 @@ module Cabi
10
10
  DELIMITER = ':'
11
11
  BULK_SELECTOR = '*'
12
12
  YAML_EXT = '.yml'
13
- CABI_CACHE_ID = '.cabi-cache'
14
- CABI_CACHE_DIR = './cabi-cache'
13
+ CABI_DATA_ID = '.cabi-data'
14
+ CABI_DATA_DIR = './cabi-data'
15
15
 
16
16
  def self.read(id)
17
- Cache.read(id)
17
+ Data.read(id)
18
18
  end
19
19
 
20
20
  def self.write(id, content)
21
- Cache.write(id, content)
21
+ Data.write(id, content)
22
22
  end
23
23
 
24
24
  end
data/lib/data.rb ADDED
@@ -0,0 +1,39 @@
1
+ module Cabi
2
+
3
+ class Data
4
+
5
+ def self.read(id)
6
+ DataFile.contents(id) || nil
7
+ end
8
+
9
+ def self.write(id, content)
10
+ file = DataFile.write(id, content)
11
+ end
12
+
13
+ def self.user_data_dir
14
+ dir = false
15
+
16
+ Dir.foreach('.') do |item|
17
+ next if item == '..' or !File.directory?(item)
18
+ dir = item if File.exists?( File.join(item, CABI_DATA_ID) )
19
+ break if dir
20
+ end
21
+
22
+ dir
23
+ end
24
+
25
+ end
26
+
27
+ # Helpers for setting/getting data dir.
28
+ def self.data_dir
29
+ dir = Data.user_data_dir || CABI_DATA_DIR
30
+ @@data_dir = File.expand_path(dir)
31
+ raise LoadError.new "Could not find cabi data folder!" unless File.exists? @@data_dir
32
+ @@data_dir
33
+ end
34
+
35
+ def self.reset_data_dir
36
+ @@data_dir = nil
37
+ end
38
+
39
+ end
data/lib/datafile.rb CHANGED
@@ -64,7 +64,7 @@ module Cabi
64
64
 
65
65
  def self.id_array(id)
66
66
  id = id.split( DELIMITER )
67
- [Cabi.cache_dir] + id
67
+ [Cabi.data_dir] + id
68
68
  end
69
69
 
70
70
  def self.exists?(id)
@@ -94,7 +94,7 @@ module Cabi
94
94
  id.each_with_index do |key, index|
95
95
  break if val
96
96
 
97
- a = [Cabi.cache_dir] + id[0..index]
97
+ a = [Cabi.data_dir] + id[0..index]
98
98
  a[ a.length - 1 ] = a[a.length - 1 ] + YAML_EXT
99
99
  f = File.join( *a )
100
100
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cabi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Gonzalez
@@ -43,10 +43,10 @@ files:
43
43
  - cabi.gemspec
44
44
  - bin/cabi
45
45
  - lib/cabi.rb
46
- - lib/cache.rb
46
+ - lib/data.rb
47
47
  - lib/datafile.rb
48
48
  - lib/hash.rb
49
- - data/cabi-cache.tar.gz
49
+ - data/cabi-data.tar.gz
50
50
  - data/cabi.svg
51
51
  homepage: http://github.com/briangonzalez/cabi-gem
52
52
  licenses:
data/lib/cache.rb DELETED
@@ -1,39 +0,0 @@
1
- module Cabi
2
-
3
- class Cache
4
-
5
- def self.read(id)
6
- DataFile.contents(id) || nil
7
- end
8
-
9
- def self.write(id, content)
10
- file = DataFile.write(id, content)
11
- end
12
-
13
- def self.user_cache_dir
14
- dir = false
15
-
16
- Dir.foreach('.') do |item|
17
- next if item == '..' or !File.directory?(item)
18
- dir = item if File.exists?( File.join(item, CABI_CACHE_ID) )
19
- break if dir
20
- end
21
-
22
- dir
23
- end
24
-
25
- end
26
-
27
- # Helpers for setting/getting cache dir.
28
- def self.cache_dir
29
- dir = Cache.user_cache_dir || CABI_CACHE_DIR
30
- @@cache_dir = File.expand_path(dir)
31
- raise LoadError.new "Could not find cabi cache folder!" unless File.exists? @@cache_dir
32
- @@cache_dir
33
- end
34
-
35
- def self.reset_cache_dir
36
- @@cache_dir = nil
37
- end
38
-
39
- end