Class: Backup::Entry

Inherits:
Object
  • Object
show all
Defined in:
app/models/backup.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, title, extension, content) ⇒ Entry

Returns a new instance of Entry.



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/models/backup.rb', line 72

def initialize(id, title, extension, content)
  if title
    title = "%05d_%s" % [id, title]
  else
    title = "%05d" % id
  end

  title = DatabaseFile.sanitize title
  extension = DatabaseFile.sanitize(extension || "")
  extension = ".#{extension}" if extension.present?
  @filename = "#{title}#{extension}"
  @content = content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



70
71
72
# File 'app/models/backup.rb', line 70

def content
  @content
end

#filenameObject (readonly)

Returns the value of attribute filename.



70
71
72
# File 'app/models/backup.rb', line 70

def filename
  @filename
end

#keyObject (readonly)

Returns the value of attribute key.



70
71
72
# File 'app/models/backup.rb', line 70

def key
  @key
end

Class Method Details

.from_record(record) ⇒ Object



100
101
102
103
# File 'app/models/backup.rb', line 100

def from_record(record)
  title = record.zip_title if record.respond_to? :zip_title
  new record.id, title, "json", record.to_json
end

Instance Method Details

#pathObject



95
96
97
# File 'app/models/backup.rb', line 95

def path
  "#{safe_key}/#{filename}"
end

#safe_keyObject



91
92
93
# File 'app/models/backup.rb', line 91

def safe_key
  DatabaseFile.sanitize key.to_s
end

#with_key(key) ⇒ Object



86
87
88
89
# File 'app/models/backup.rb', line 86

def with_key(key)
  @key = key
  self
end