Class: Textus::Protocol::Format::Script
- Inherits:
-
Base
- Object
- Base
- Textus::Protocol::Format::Script
show all
- Defined in:
- lib/textus/protocol/format/script.rb
Constant Summary
collapse
- EXTENSIONS =
%w[.rb .py .sh .js .pl .rs .exs].freeze
Class Method Summary
collapse
Methods inherited from Base
format_name, serialize_for_put, validate_against
Class Method Details
.data_to_payload(data) ⇒ Object
48
49
50
51
|
# File 'lib/textus/protocol/format/script.rb', line 48
def self.data_to_payload(data)
data = data.transform_keys(&:to_s) if data.is_a?(Hash)
{ meta: data["_meta"] || {}, body: (data["body"] || "").to_s, content: nil }
end
|
.enforce_name_match!(_path, _meta) ⇒ Object
25
|
# File 'lib/textus/protocol/format/script.rb', line 25
def self.enforce_name_match!(_path, _meta); end
|
.extensions ⇒ Object
22
|
# File 'lib/textus/protocol/format/script.rb', line 22
def self.extensions = EXTENSIONS
|
.nested_ext ⇒ Object
24
|
# File 'lib/textus/protocol/format/script.rb', line 24
def self.nested_ext(*) = ""
|
.nested_glob ⇒ Object
23
|
# File 'lib/textus/protocol/format/script.rb', line 23
def self.nested_glob = "**/*"
|
.parse(raw, path: nil) ⇒ Object
7
8
9
10
11
12
|
# File 'lib/textus/protocol/format/script.rb', line 7
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
27
28
29
|
# File 'lib/textus/protocol/format/script.rb', line 27
def self.rewrite_name(_path, _basename)
false
end
|
.serialize(meta:, body:, content: nil) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/textus/protocol/format/script.rb', line 14
def self.serialize(meta:, body:, content: nil)
_ = meta
_ = content
b = body.to_s
b += "\n" unless b.empty? || b.end_with?("\n")
b
end
|
.validate_path_extension(path, nested) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/textus/protocol/format/script.rb', line 31
def self.validate_path_extension(path, nested)
ext = File.extname(path)
if nested
return if ext == ""
raise UsageError.new("nested script path must not have an extension")
end
return if EXTENSIONS.include?(ext) || ext == ""
raise UsageError.new("script format requires #{EXTENSIONS.join(" | ")} extension (got #{ext.inspect})")
end
|
.validate_raw_entry!(_parsed, lane) ⇒ Object
44
45
46
|
# File 'lib/textus/protocol/format/script.rb', line 44
def self.validate_raw_entry!(_parsed, lane)
nil unless lane == "scratchpad"
end
|