class Hyrb::Model

Attributes

data[RW]
path[RW]

Public Class Methods

new(path, data = nil) click to toggle source
# File lib/hyrb/model.rb, line 17
def initialize(path, data = nil)
  @path = File.join(ENV["HYFN_CONFIG_PATH"] || Hyrb::DEFAULT_PATH, path)
  @data = deserialize(load_config_file) || data
end

Public Instance Methods

filepath() click to toggle source
# File lib/hyrb/model.rb, line 28
def filepath
  @path + ".yml"
end
load_config_file() click to toggle source
# File lib/hyrb/model.rb, line 22
def load_config_file
  YAML.load_file(filepath)
rescue Errno::ENOENT
  nil
end
reload!() click to toggle source
# File lib/hyrb/model.rb, line 32
def reload!
  @data = self.load_config_file
end
save!() click to toggle source
# File lib/hyrb/model.rb, line 36
def save!
  FileUtils.mkdir_p(File.dirname(@path))
  File.open(filepath, File::RDWR|File::TRUNC|File::CREAT, 0600) do |file|
    file.write(serialize(@data).to_yaml)
  end
end

Protected Instance Methods

deserialize(data) click to toggle source
# File lib/hyrb/model.rb, line 49
def deserialize(data)
  data
end
serialize(data) click to toggle source
# File lib/hyrb/model.rb, line 45
def serialize(data)
  data
end