Class: SmartBox::Metadata
- Inherits:
-
Object
- Object
- SmartBox::Metadata
- Defined in:
- lib/smart_box/metadata.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #add_checkpoint(id:, name:, git_commit:, created_at: Time.now.utc.iso8601) ⇒ Object
- #base ⇒ Object
- #base=(val) ⇒ Object
- #checkpoints ⇒ Object
- #created_at ⇒ Object
- #created_at=(val) ⇒ Object
-
#id ⇒ Object
— Convenience accessors —.
- #id=(val) ⇒ Object
-
#initialize(path) ⇒ Metadata
constructor
A new instance of Metadata.
- #load! ⇒ Object
- #mode ⇒ Object
- #mode=(val) ⇒ Object
- #name ⇒ Object
- #name=(val) ⇒ Object
- #save! ⇒ Object
- #source_path ⇒ Object
- #source_path=(val) ⇒ Object
- #stats ⇒ Object
- #stats=(val) ⇒ Object
- #status ⇒ Object
- #status=(val) ⇒ Object
- #updated_at ⇒ Object
- #updated_at=(val) ⇒ Object
- #workspace_path ⇒ Object
- #workspace_path=(val) ⇒ Object
Constructor Details
#initialize(path) ⇒ Metadata
Returns a new instance of Metadata.
10 11 12 13 |
# File 'lib/smart_box/metadata.rb', line 10 def initialize(path) @path = path @data = {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/smart_box/metadata.rb', line 8 def data @data end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/smart_box/metadata.rb', line 8 def path @path end |
Instance Method Details
#add_checkpoint(id:, name:, git_commit:, created_at: Time.now.utc.iso8601) ⇒ Object
115 116 117 118 119 120 121 122 |
# File 'lib/smart_box/metadata.rb', line 115 def add_checkpoint(id:, name:, git_commit:, created_at: Time.now.utc.iso8601) checkpoints << { "id" => id, "name" => name, "git_commit" => git_commit, "created_at" => created_at } end |
#base ⇒ Object
95 96 97 |
# File 'lib/smart_box/metadata.rb', line 95 def base @data["base"] ||= {} end |
#base=(val) ⇒ Object
99 100 101 |
# File 'lib/smart_box/metadata.rb', line 99 def base=(val) @data["base"] = val end |
#checkpoints ⇒ Object
103 104 105 |
# File 'lib/smart_box/metadata.rb', line 103 def checkpoints @data["checkpoints"] ||= [] end |
#created_at ⇒ Object
79 80 81 |
# File 'lib/smart_box/metadata.rb', line 79 def created_at @data["created_at"] end |
#created_at=(val) ⇒ Object
83 84 85 |
# File 'lib/smart_box/metadata.rb', line 83 def created_at=(val) @data["created_at"] = val end |
#id ⇒ Object
— Convenience accessors —
31 32 33 |
# File 'lib/smart_box/metadata.rb', line 31 def id @data["id"] end |
#id=(val) ⇒ Object
35 36 37 |
# File 'lib/smart_box/metadata.rb', line 35 def id=(val) @data["id"] = val end |
#load! ⇒ Object
15 16 17 18 19 20 |
# File 'lib/smart_box/metadata.rb', line 15 def load! if File.exist?(@path) @data = YAML.safe_load_file(@path, permitted_classes: [Time]) || {} end self end |
#mode ⇒ Object
47 48 49 |
# File 'lib/smart_box/metadata.rb', line 47 def mode @data["mode"] end |
#mode=(val) ⇒ Object
51 52 53 |
# File 'lib/smart_box/metadata.rb', line 51 def mode=(val) @data["mode"] = val end |
#name ⇒ Object
39 40 41 |
# File 'lib/smart_box/metadata.rb', line 39 def name @data["name"] end |
#name=(val) ⇒ Object
43 44 45 |
# File 'lib/smart_box/metadata.rb', line 43 def name=(val) @data["name"] = val end |
#save! ⇒ Object
22 23 24 25 26 27 |
# File 'lib/smart_box/metadata.rb', line 22 def save! dir = File.dirname(@path) FileUtils.mkdir_p(dir) File.write(@path, YAML.dump(@data)) self end |
#source_path ⇒ Object
55 56 57 |
# File 'lib/smart_box/metadata.rb', line 55 def source_path @data["source_path"] end |
#source_path=(val) ⇒ Object
59 60 61 |
# File 'lib/smart_box/metadata.rb', line 59 def source_path=(val) @data["source_path"] = val end |
#stats ⇒ Object
107 108 109 |
# File 'lib/smart_box/metadata.rb', line 107 def stats @data["stats"] ||= {} end |
#stats=(val) ⇒ Object
111 112 113 |
# File 'lib/smart_box/metadata.rb', line 111 def stats=(val) @data["stats"] = val end |
#status ⇒ Object
71 72 73 |
# File 'lib/smart_box/metadata.rb', line 71 def status @data["status"] || "active" end |
#status=(val) ⇒ Object
75 76 77 |
# File 'lib/smart_box/metadata.rb', line 75 def status=(val) @data["status"] = val end |
#updated_at ⇒ Object
87 88 89 |
# File 'lib/smart_box/metadata.rb', line 87 def updated_at @data["updated_at"] || Time.now.utc.iso8601 end |
#updated_at=(val) ⇒ Object
91 92 93 |
# File 'lib/smart_box/metadata.rb', line 91 def updated_at=(val) @data["updated_at"] = val end |
#workspace_path ⇒ Object
63 64 65 |
# File 'lib/smart_box/metadata.rb', line 63 def workspace_path @data["workspace_path"] end |
#workspace_path=(val) ⇒ Object
67 68 69 |
# File 'lib/smart_box/metadata.rb', line 67 def workspace_path=(val) @data["workspace_path"] = val end |