Class: Insta::Snapshot
- Inherits:
-
Object
- Object
- Insta::Snapshot
- Defined in:
- lib/insta/snapshot.rb,
sig/insta/snapshot.rbs
Constant Summary collapse
- SEPARATOR =
@rbs! type snapshot_metadata = Hash[String, untyped]
"---"
Instance Attribute Summary collapse
-
#content ⇒ String
readonly
: String.
-
#metadata ⇒ snapshot_metadata
readonly
: snapshot_metadata.
Class Method Summary collapse
-
.parse(raw) ⇒ Snapshot
: (String) -> Snapshot.
Instance Method Summary collapse
-
#description ⇒ String?
: () -> String?.
-
#expression ⇒ String?
: () -> String?.
-
#info ⇒ Hash[String, untyped]?
: () -> Hash[String, untyped]?.
-
#initialize(content, metadata = {}) ⇒ Snapshot
constructor
: (String, ?snapshot_metadata) -> void.
-
#input ⇒ String?
: () -> String?.
-
#serialize ⇒ String
: () -> String.
-
#source ⇒ String?
: () -> String?.
Constructor Details
#initialize(content, metadata = {}) ⇒ Snapshot
: (String, ?snapshot_metadata) -> void
16 17 18 19 |
# File 'lib/insta/snapshot.rb', line 16 def initialize(content, = {}) @content = content @metadata = end |
Instance Attribute Details
#content ⇒ String (readonly)
: String
12 13 14 |
# File 'lib/insta/snapshot.rb', line 12 def content @content end |
#metadata ⇒ snapshot_metadata (readonly)
: snapshot_metadata
13 14 15 |
# File 'lib/insta/snapshot.rb', line 13 def @metadata end |
Class Method Details
.parse(raw) ⇒ Snapshot
: (String) -> Snapshot
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/insta/snapshot.rb', line 22 def self.parse(raw) raw = raw.to_s if raw.start_with?("#{SEPARATOR}\n") parts = raw.split("#{SEPARATOR}\n", 3) if parts.length >= 3 = begin YAML.safe_load(parts[1], permitted_classes: [Symbol]) || {} rescue Psych::SyntaxError {} #: snapshot_metadata end return new(parts[2].chomp.concat("\n"), ) end end new(raw, {}) end |
Instance Method Details
#description ⇒ String?
: () -> String?
60 61 62 |
# File 'lib/insta/snapshot.rb', line 60 def description @metadata["description"] end |
#expression ⇒ String?
: () -> String?
65 66 67 |
# File 'lib/insta/snapshot.rb', line 65 def expression @metadata["expression"] end |
#info ⇒ Hash[String, untyped]?
: () -> Hash[String, untyped]?
70 71 72 |
# File 'lib/insta/snapshot.rb', line 70 def info @metadata["info"] end |
#input ⇒ String?
: () -> String?
55 56 57 |
# File 'lib/insta/snapshot.rb', line 55 def input @metadata["input"] end |
#serialize ⇒ String
: () -> String
43 44 45 46 47 |
# File 'lib/insta/snapshot.rb', line 43 def serialize return @content if @metadata.empty? YAML.dump(@metadata) + "#{SEPARATOR}\n" + @content end |
#source ⇒ String?
: () -> String?
50 51 52 |
# File 'lib/insta/snapshot.rb', line 50 def source @metadata["source"] end |