Class: Textus::Entry::Text
Overview
Plain-text entry storage. No frontmatter or structured content.
Class Method Summary collapse
- .enforce_name_match!(_path, _meta) ⇒ Object
- .extensions ⇒ Object
- .inject_uid(meta, content, _existing_uid) ⇒ Object
- .nested_glob ⇒ Object
- .parse(raw, path: nil) ⇒ Object
-
.rewrite_name(_path, _basename) ⇒ Object
No-op; text has no meta.
- .serialize(meta:, body:, content: nil) ⇒ Object
- .serialize_for_put(meta:, body:, content:, path:) ⇒ Object
- .validate_path_extension(path, nested) ⇒ Object
Methods inherited from Base
Class Method Details
.enforce_name_match!(_path, _meta) ⇒ Object
28 29 30 |
# File 'lib/textus/entry/text.rb', line 28 def self.enforce_name_match!(_path, ) # text has no meta home; no-op end |
.extensions ⇒ Object
20 |
# File 'lib/textus/entry/text.rb', line 20 def self.extensions = [".txt"] |
.inject_uid(meta, content, _existing_uid) ⇒ Object
24 25 26 |
# File 'lib/textus/entry/text.rb', line 24 def self.inject_uid(, content, _existing_uid) [, content] end |
.nested_glob ⇒ Object
22 |
# File 'lib/textus/entry/text.rb', line 22 def self.nested_glob = "**/*.txt" |
.parse(raw, path: nil) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/textus/entry/text.rb', line 5 def self.parse(raw, path: nil) raw = raw.dup.force_encoding(Encoding::UTF_8) raise BadFrontmatter.new(path, "entry is not valid UTF-8") unless raw.valid_encoding? { "_meta" => {}, "body" => raw, "content" => nil } end |
.rewrite_name(_path, _basename) ⇒ Object
No-op; text has no meta. Returns false (never writes).
40 41 42 |
# File 'lib/textus/entry/text.rb', line 40 def self.rewrite_name(_path, _basename) # rubocop:disable Naming/PredicateMethod false end |
.serialize(meta:, body:, content: nil) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/textus/entry/text.rb', line 12 def self.serialize(meta:, body:, content: nil) _ = _ = content b = body.to_s b += "\n" unless b.empty? || b.end_with?("\n") b end |
.serialize_for_put(meta:, body:, content:, path:) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/textus/entry/text.rb', line 32 def self.serialize_for_put(meta:, body:, content:, path:) _ = path _ = content bytes = serialize(meta: || {}, body: body.to_s) [bytes, , body.to_s, nil] end |
.validate_path_extension(path, nested) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/textus/entry/text.rb', line 44 def self.validate_path_extension(path, nested) ext = File.extname(path) if nested return if ext == "" raise UsageError.new("nested text path must not have an extension") end return if [".txt", ""].include?(ext) raise UsageError.new("text format requires '.txt' or no extension (got #{ext.inspect})") end |