Class: SmartBox::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_box/metadata.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/smart_box/metadata.rb', line 8

def data
  @data
end

#pathObject (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

#baseObject



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

#checkpointsObject



103
104
105
# File 'lib/smart_box/metadata.rb', line 103

def checkpoints
  @data["checkpoints"] ||= []
end

#created_atObject



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

#idObject

— 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

#modeObject



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

#nameObject



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_pathObject



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

#statsObject



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

#statusObject



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_atObject



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_pathObject



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