contentfs 0.0.0 → 0.1.0

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
  SHA256:
3
- metadata.gz: 9dd7fc4b06ab77f27e8998c275cb3d4659dc450d013ebf2df47fd5609d9fe322
4
- data.tar.gz: d289facaae4ca3c791054b632397efb2e2286c964602885888215b5584e06d4d
3
+ metadata.gz: b815f957fcccb235ddec7a7cd90ae7392727a949e50883bbcf9425c4904b5fba
4
+ data.tar.gz: 0e20ede1a87ef3fa34f7755740489322039f760580406b44d35914fb6103aff2
5
5
  SHA512:
6
- metadata.gz: dedfb6034eb79b0b09bbbb9645c8de6f04b9a8e6ff78a31186c11798317ca02807e00eed644bd980f57cb5407d13843d7cec1d0c6a3ec5efa8a0a755865c752a
7
- data.tar.gz: 8a9010f2faf608345653e321310208dc2b85afafbc2985a6c9392ddccbfe548e6f500b146a66525aa3adda88320913544e9605ac4f5348de9598f276c6f7f8b1
6
+ metadata.gz: 36c32a237713fdd88a28ce5c6fe0770c0aefa0275e5d350f31a56a363976d83c72428ea6ab89e79645d1c28c0fbfc681704c0dd7856069efcbc7034546398168
7
+ data.tar.gz: a7abf1c49c7cdaadcdb855ed1a5965eb4f3f0623fa63f7a86b03ac72c1f0f2e05bc427d06c84dfcab75aa8323df93e983aba043ffb1c39594e0a1753cd7acfbc
@@ -0,0 +1,16 @@
1
+ ## v0.1.0
2
+ *unreleased*
3
+
4
+
5
+ * `add` [#4](https://github.com/metabahn/contentfs/pull/4) Expose namespaces for databases and content ([bryanp](https://github.com/bryanp))
6
+ * `add` [#3](https://github.com/metabahn/contentfs/pull/3) Introduce `Database#nested` for iterating over databases ([bryanp](https://github.com/bryanp))
7
+ * `chg` [#2](https://github.com/metabahn/contentfs/pull/2) Rename `Database#all` to `Database#content` ([bryanp](https://github.com/bryanp))
8
+ * `add` [#1](https://github.com/metabahn/contentfs/pull/1) Introduce `Database#find` for safer traversal ([bryanp](https://github.com/bryanp))
9
+
10
+ ## [v0.0.0](https://github.com/metabahn/contentfs/releases/tag/v0.0.0)
11
+ *released on 2020-11-11*
12
+
13
+
14
+ * Initial release.
15
+
16
+
@@ -12,16 +12,16 @@ module ContentFS
12
12
  #
13
13
  class Content
14
14
  class << self
15
- def load(path, metadata: {})
16
- new(path: path, metadata: metadata)
15
+ def load(path, metadata: {}, namespace: [])
16
+ new(path: path, metadata: metadata, namespace: namespace)
17
17
  end
18
18
  end
19
19
 
20
20
  FRONT_MATTER_REGEXP = /\A---\s*\n(.*?\n?)^---\s*$\n?/m
21
21
 
22
- attr_reader :format, :prefix, :slug, :metadata
22
+ attr_reader :format, :prefix, :slug, :metadata, :namespace
23
23
 
24
- def initialize(path:, metadata: {})
24
+ def initialize(path:, metadata: {}, namespace: [])
25
25
  path = Pathname.new(path)
26
26
  extname = path.extname
27
27
  name = path.basename(extname)
@@ -31,6 +31,7 @@ module ContentFS
31
31
  @slug = Slug.build(remainder)
32
32
  @content = path.read
33
33
  @metadata = metadata.merge(parse_metadata(@content))
34
+ @namespace = namespace.dup << @slug
34
35
  end
35
36
 
36
37
  def to_s
@@ -11,23 +11,28 @@ module ContentFS
11
11
  #
12
12
  class Database
13
13
  class << self
14
- def load(path)
15
- new(path: path)
14
+ def load(path, namespace: [], root: true)
15
+ new(path: path, namespace: namespace, root: root)
16
16
  end
17
17
  end
18
18
 
19
19
  METADATA_FILE = "_metadata.yml"
20
20
 
21
- attr_reader :prefix, :slug
21
+ attr_reader :prefix, :slug, :namespace
22
22
 
23
- def initialize(path:)
23
+ def initialize(path:, namespace: [], root: false)
24
24
  path = Pathname.new(path)
25
25
  name = path.basename(path.extname)
26
26
  prefix, remainder = Prefix.build(name)
27
27
  @prefix = prefix
28
- @slug = Slug.build(remainder)
29
28
  @children = {}
30
29
  @nested = {}
30
+ @namespace = namespace.dup
31
+
32
+ unless root
33
+ @slug = Slug.build(remainder)
34
+ @namespace << @slug
35
+ end
31
36
 
32
37
  metadata_path = path.join(METADATA_FILE)
33
38
 
@@ -41,10 +46,10 @@ module ContentFS
41
46
  next if path.basename.to_s.start_with?("_")
42
47
 
43
48
  if path.directory?
44
- database = Database.load(path)
49
+ database = Database.load(path, namespace: @namespace, root: false)
45
50
  @nested[database.slug] = database
46
51
  else
47
- content = Content.load(path, metadata: metadata)
52
+ content = Content.load(path, metadata: metadata, namespace: @namespace)
48
53
 
49
54
  if content.slug == :content
50
55
  @content = content
@@ -55,14 +60,22 @@ module ContentFS
55
60
  end
56
61
  end
57
62
 
58
- def all
59
- return to_enum(:all) unless block_given?
63
+ def content
64
+ return to_enum(:content) unless block_given?
60
65
 
61
66
  @children.each_value do |value|
62
67
  yield value
63
68
  end
64
69
  end
65
70
 
71
+ def nested
72
+ return to_enum(:nested) unless block_given?
73
+
74
+ @nested.each_value do |value|
75
+ yield value
76
+ end
77
+ end
78
+
66
79
  def filter(**filters)
67
80
  return to_enum(:filter, **filters) unless block_given?
68
81
 
@@ -77,6 +90,16 @@ module ContentFS
77
90
  }
78
91
  end
79
92
 
93
+ def find(name, *nested)
94
+ if @children.key?(name)
95
+ @children[name]
96
+ elsif @nested.key?(name)
97
+ nested.inject(@nested[name]) { |database, next_nested|
98
+ database.find(next_nested.to_sym)
99
+ }
100
+ end
101
+ end
102
+
80
103
  def to_s
81
104
  @content&.to_s.to_s
82
105
  end
@@ -86,15 +109,7 @@ module ContentFS
86
109
  end
87
110
 
88
111
  def method_missing(name, *nested, **)
89
- if @children.key?(name)
90
- @children[name]
91
- elsif @nested.key?(name)
92
- nested.inject(@nested[name]) { |database, next_nested|
93
- database.public_send(next_nested.to_sym)
94
- }
95
- else
96
- super
97
- end
112
+ find(name, *nested) || super
98
113
  end
99
114
 
100
115
  def respond_to_missing?(name, *)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContentFS
4
- VERSION = "0.0.0"
4
+ VERSION = "0.1.0"
5
5
 
6
6
  def self.version
7
7
  VERSION
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-12 00:00:00.000000000 Z
11
+ date: 2020-11-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A structured content file system.
14
14
  email: bryan@metabahn.com
@@ -16,6 +16,7 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - CHANGELOG.md
19
20
  - LICENSE
20
21
  - README.md
21
22
  - lib/contentfs.rb