contentfs 0.0.0 → 0.1.0
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/CHANGELOG.md +16 -0
- data/lib/contentfs/content.rb +5 -4
- data/lib/contentfs/database.rb +33 -18
- data/lib/contentfs/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b815f957fcccb235ddec7a7cd90ae7392727a949e50883bbcf9425c4904b5fba
|
4
|
+
data.tar.gz: 0e20ede1a87ef3fa34f7755740489322039f760580406b44d35914fb6103aff2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36c32a237713fdd88a28ce5c6fe0770c0aefa0275e5d350f31a56a363976d83c72428ea6ab89e79645d1c28c0fbfc681704c0dd7856069efcbc7034546398168
|
7
|
+
data.tar.gz: a7abf1c49c7cdaadcdb855ed1a5965eb4f3f0623fa63f7a86b03ac72c1f0f2e05bc427d06c84dfcab75aa8323df93e983aba043ffb1c39594e0a1753cd7acfbc
|
data/CHANGELOG.md
ADDED
@@ -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
|
+
|
data/lib/contentfs/content.rb
CHANGED
@@ -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
|
data/lib/contentfs/database.rb
CHANGED
@@ -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
|
59
|
-
return to_enum(:
|
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
|
-
|
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, *)
|
data/lib/contentfs/version.rb
CHANGED
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.
|
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-
|
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
|