contentfs 0.0.0 → 0.3.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: 5386e4d1a1ef23527ec457ecb544d4d36d02e44811fe81f87db93f4188d82145
4
+ data.tar.gz: f44614daf6d97aabd4d83a0e2339dd8d20e19d742b8b8403c37fc2967dd40925
5
5
  SHA512:
6
- metadata.gz: dedfb6034eb79b0b09bbbb9645c8de6f04b9a8e6ff78a31186c11798317ca02807e00eed644bd980f57cb5407d13843d7cec1d0c6a3ec5efa8a0a755865c752a
7
- data.tar.gz: 8a9010f2faf608345653e321310208dc2b85afafbc2985a6c9392ddccbfe548e6f500b146a66525aa3adda88320913544e9605ac4f5348de9598f276c6f7f8b1
6
+ metadata.gz: 39ee593b9c158d2093d5a8bc59a8d8510adb8a206d4b786a0465347e79f12323806765be999be8ad7fd14bccb4e32134696c1f851fa466a1a515d3b44d7ecc63
7
+ data.tar.gz: f1ab2b7a9cc994b5d91cef392fa8d4a4c1bedaac69428ceb9552143b7f969391ec32a16ae1240c66da616a80440945bfae9f8a30e010bcd47f2f36f7aa89e3ef
@@ -0,0 +1,40 @@
1
+ ## v0.3.0
2
+
3
+ *unreleased*
4
+
5
+ * `chg` [#8](https://github.com/metabahn/contentfs/pull/8) Load database content from _content to avoid collisions ([bryanp](https://github.com/bryanp))
6
+
7
+ ## v0.2.1
8
+
9
+ *unreleased*
10
+
11
+ * `fix` [#7](https://github.com/metabahn/contentfs/pull/7) Order content and databases by prefix or slug ([bryanp](https://github.com/bryanp))
12
+
13
+ ## [v0.2.0](https://github.com/metabahn/contentfs/releases/tag/v0.2.0)
14
+
15
+ *released on 2020-11-14*
16
+
17
+ * `add` [#6](https://github.com/metabahn/contentfs/pull/6) Expose database metadata ([bryanp](https://github.com/bryanp))
18
+
19
+ ## [v0.1.1](https://github.com/metabahn/contentfs/releases/tag/v0.1.1)
20
+
21
+ *released on 2020-11-13*
22
+
23
+ * `fix` [#5](https://github.com/metabahn/contentfs/pull/5) Remove front-matter from content ([bryanp](https://github.com/bryanp))
24
+
25
+ ## [v0.1.0](https://github.com/metabahn/contentfs/releases/tag/v0.1.0)
26
+
27
+ *released on 2020-11-12*
28
+
29
+ * `add` [#4](https://github.com/metabahn/contentfs/pull/4) Expose namespaces for databases and content ([bryanp](https://github.com/bryanp))
30
+ * `add` [#3](https://github.com/metabahn/contentfs/pull/3) Introduce `Database#nested` for iterating over databases ([bryanp](https://github.com/bryanp))
31
+ * `chg` [#2](https://github.com/metabahn/contentfs/pull/2) Rename `Database#all` to `Database#content` ([bryanp](https://github.com/bryanp))
32
+ * `add` [#1](https://github.com/metabahn/contentfs/pull/1) Introduce `Database#find` for safer traversal ([bryanp](https://github.com/bryanp))
33
+
34
+ ## [v0.0.0](https://github.com/metabahn/contentfs/releases/tag/v0.0.0)
35
+
36
+ *released on 2020-11-11*
37
+
38
+ * Initial release.
39
+
40
+
@@ -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)
@@ -29,8 +29,11 @@ module ContentFS
29
29
  @prefix = prefix
30
30
  @format = extname.to_s[1..-1]&.to_sym
31
31
  @slug = Slug.build(remainder)
32
- @content = path.read
33
- @metadata = metadata.merge(parse_metadata(@content))
32
+ @namespace = namespace.dup << @slug
33
+
34
+ content = path.read
35
+ @metadata = metadata.merge(parse_metadata(content))
36
+ @content = content.gsub(FRONT_MATTER_REGEXP, "")
34
37
  end
35
38
 
36
39
  def to_s
@@ -11,58 +11,84 @@ 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, :metadata
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
- @children = {}
30
- @nested = {}
28
+ @namespace = namespace.dup
29
+
30
+ unless root
31
+ @slug = Slug.build(remainder)
32
+ @namespace << @slug
33
+ end
31
34
 
32
35
  metadata_path = path.join(METADATA_FILE)
33
36
 
34
- metadata = if metadata_path.exist?
37
+ @metadata = if metadata_path.exist?
35
38
  YAML.safe_load(metadata_path.read).to_h
36
39
  else
37
40
  {}
38
41
  end
39
42
 
43
+ content_path = path.join.glob("_content.*")[0]
44
+
45
+ @content = if content_path&.exist?
46
+ Content.load(content_path, metadata: @metadata, namespace: @namespace)
47
+ end
48
+
49
+ children, nested = {}, {}
40
50
  Pathname.new(path).glob("*") do |path|
41
51
  next if path.basename.to_s.start_with?("_")
42
52
 
43
53
  if path.directory?
44
- database = Database.load(path)
45
- @nested[database.slug] = database
54
+ database = Database.load(path, namespace: @namespace, root: false)
55
+ nested[database.slug] = database
46
56
  else
47
- content = Content.load(path, metadata: metadata)
57
+ content = Content.load(path, metadata: @metadata, namespace: @namespace)
48
58
 
49
- if content.slug == :content
50
- @content = content
51
- else
52
- @children[content.slug] = content
53
- end
59
+ children[content.slug] = content
54
60
  end
55
61
  end
62
+
63
+ @children = Hash[
64
+ children.sort_by { |key, content|
65
+ (content.prefix || content.slug).to_s
66
+ }
67
+ ]
68
+
69
+ @nested = Hash[
70
+ nested.sort_by { |key, database|
71
+ (database.prefix || database.slug).to_s
72
+ }
73
+ ]
56
74
  end
57
75
 
58
- def all
59
- return to_enum(:all) unless block_given?
76
+ def content
77
+ return to_enum(:content) unless block_given?
60
78
 
61
79
  @children.each_value do |value|
62
80
  yield value
63
81
  end
64
82
  end
65
83
 
84
+ def nested
85
+ return to_enum(:nested) unless block_given?
86
+
87
+ @nested.each_value do |value|
88
+ yield value
89
+ end
90
+ end
91
+
66
92
  def filter(**filters)
67
93
  return to_enum(:filter, **filters) unless block_given?
68
94
 
@@ -77,6 +103,16 @@ module ContentFS
77
103
  }
78
104
  end
79
105
 
106
+ def find(name, *nested)
107
+ if @children.key?(name)
108
+ @children[name]
109
+ elsif @nested.key?(name)
110
+ nested.inject(@nested[name]) { |database, next_nested|
111
+ database.find(next_nested.to_sym)
112
+ }
113
+ end
114
+ end
115
+
80
116
  def to_s
81
117
  @content&.to_s.to_s
82
118
  end
@@ -86,15 +122,7 @@ module ContentFS
86
122
  end
87
123
 
88
124
  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
125
+ find(name, *nested) || super
98
126
  end
99
127
 
100
128
  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.3.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.3.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-18 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