cabi 0.1.7 → 0.1.8

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: 0b09ee246dba02249981cbb0f0c42274da912aac
4
- data.tar.gz: 17a4990844a94d7a72d0d929c26daba3c0c242b4
3
+ metadata.gz: ef8499690487070c9e95e0f172f87d60b6891c28
4
+ data.tar.gz: 6ff6984f617c702abe45ef66d06a714a5b9614b8
5
5
  SHA512:
6
- metadata.gz: aa15f5e116ac640f3a90a7de36ca1bc732ea74b4dc0d4c2e758730255f9793291252f5cca4c923956c4f1c1be64483f2f86d1bef8a8e7ce16a22c317957819f3
7
- data.tar.gz: 5d93f37b690435ab11f4eb1c1154f20b97edafc04096bbf6b1db02135e599fdfc63dd38926ee88fd7b892e8664ee95d73f4417459a64883033a031fda52bfcb0
6
+ metadata.gz: ca62a4ff0f7e567ec88228e2a827e82360ba431d65c74c8e09615b622b26f20e1b54521c3edc9a18461a50cba90f10c5ab5e30dee581b0e04d82e8fce3cc6236
7
+ data.tar.gz: 4f4b15e3f1c5d8b4d88551b8a1686942cab1b9aca2d554506ed05c54a314a07830c9d53a559230bb2d3f2fb63877c69a1bea5a0521ce462f860f985de13b0468
data/README.md CHANGED
@@ -63,6 +63,10 @@ Cabi.read('pages:about:meta:foo:bar') # contents of ['foo']['bar'] in pa
63
63
  Cabi.read('pages:about:meta.yml:foo:bar') # same as above
64
64
  Cabi.read('info:foo:bar:baz') # contents of ['foo']['bar']['baz'] in info.yml hash
65
65
  Cabi.read('info.yml:foo:bar:baz') # same as above
66
+
67
+ # Return a file path for a Cabi ID.
68
+ Cabi.file('pages:about:meta:foo:bar') # path fo file at /pages/about/meta/foo/bar
69
+ Cabi.path_to_id('/pages/about/meta/foo/bar') # pages:about:meta:foo:bar
66
70
  ```
67
71
 
68
72
  ### Custom Data Directory
data/Rakefile CHANGED
@@ -24,7 +24,6 @@ namespace :gem do
24
24
  desc "release"
25
25
  task :release do
26
26
  gems = Dir.glob("*.gem").length
27
- puts gems
28
27
  raise "0 or > 1 gem in directory; aborting!" if gems != 1
29
28
  puts %x[gem push *.gem]
30
29
  puts %x[rm -rf *.gem]
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.7'
3
+ s.version = '0.1.8'
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
@@ -13,20 +13,31 @@ module Cabi
13
13
  CABI_DATA_ID = '.cabi-data'
14
14
  CABI_DATA_DIR = './cabi-data'
15
15
 
16
- def self.read(id)
17
- Data.read(id)
16
+ def self.read(id, opts={})
17
+ Data.read(id, opts)
18
18
  end
19
19
 
20
20
  def self.write(id, content)
21
21
  Data.write(id, content)
22
22
  end
23
23
 
24
+ def self.create(id, content='')
25
+ Data.write(id, content)
26
+ end
27
+
24
28
  def self.file(id, opts={})
25
29
  DataFile.file_yaml_or_non_extension_file(id)
26
30
  end
27
31
 
28
- def self.list(id)
29
- Cabi::List.list(id)
32
+ def self.list(id='*', opts={})
33
+ Cabi::List.list(id, opts)
34
+ end
35
+
36
+ def self.path_to_id(path)
37
+ path = path.split(Cabi.data_dir).last
38
+ path = path[1..-1] if path[0] == '/'
39
+ path = path.gsub('/', DELIMITER)
40
+ path
30
41
  end
31
42
 
32
43
  end
data/lib/data.rb CHANGED
@@ -2,14 +2,18 @@ module Cabi
2
2
 
3
3
  class Data
4
4
 
5
- def self.read(id)
6
- DataFile.contents(id) || nil
5
+ def self.read(id, opts={})
6
+ DataFile.contents(id, opts) || nil
7
7
  end
8
8
 
9
9
  def self.write(id, content)
10
10
  file = DataFile.write(id, content)
11
11
  end
12
12
 
13
+ def self.create(id, content)
14
+ file = DataFile.create(id, content)
15
+ end
16
+
13
17
  def self.user_data_dir
14
18
  dir = false
15
19
 
data/lib/datafile.rb CHANGED
@@ -1,10 +1,12 @@
1
- module Cabi
2
1
 
2
+ require 'FileUtils'
3
+
4
+ module Cabi
3
5
  class DataFile
4
6
 
5
- def self.contents(id)
7
+ def self.contents(id, opts={})
6
8
  return self.bulk_selection(id) if self.bulk_selection?(id)
7
- return YAML.load(File.read( self.yaml_file(id) )) if self.yaml_exists?(id)
9
+ return YAML.load(File.read( self.yaml_file(id) )) if self.yaml_exists?(id) and !opts[:no_yaml]
8
10
  return File.read( self.file(id) ) if self.file_exists?(id)
9
11
  return File.read( self.non_extension_file(id) ) if self.non_extension_file(id)
10
12
  return self.sub_yaml(id)
@@ -25,6 +27,16 @@ module Cabi
25
27
  File.open( file, 'w') {|f| f.write(content) }
26
28
  end
27
29
 
30
+ def self.create(id, content="")
31
+ file = self.file(id)
32
+ raise "File exists." if self.file_exists?(id)
33
+ dir = File.dirname(file)
34
+
35
+ FileUtils.mkdir_p(dir) unless File.exists?(dir)
36
+ FileUtils.touch(file)
37
+ Cabi.write(id, content)
38
+ end
39
+
28
40
  def self.file_yaml_or_non_extension_file(id, opts={})
29
41
  return self.bulk_selection(id, only_file: true) if self.bulk_selection?(id)
30
42
  return self.yaml_file(id) if self.yaml_exists?(id)
data/lib/list.rb CHANGED
@@ -2,13 +2,17 @@ module Cabi
2
2
  class List
3
3
 
4
4
  def self.list(id, opts={})
5
- ls = []
5
+ ls = []
6
+ path = id.gsub( DELIMITER, '/')
6
7
 
7
- Dir.glob( "#{Cabi.data_dir}/#{id}") do |item|
8
+ Dir.glob( "#{Cabi.data_dir}/#{path}") do |item|
8
9
  next if item == '.' or item == '..'
9
- ls << [ item, File.directory?(item) ? "dir" : "file" ]
10
+
11
+ i = opts[:full_path] ? item : Cabi.path_to_id(item)
12
+ ls << [ i, File.directory?(item) ? "dir" : "file", File.basename(item) ]
10
13
  end
11
14
 
15
+ ls.sort_by!{ |f| f[1] } if opts[:dirs_first] # "dir" < "file"
12
16
  ls
13
17
  end
14
18
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cabi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Gonzalez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-25 00:00:00.000000000 Z
11
+ date: 2013-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor