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.



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/models/backup.rb', line 76

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.



74
75
76
# File 'app/models/backup.rb', line 74

def content
  @content
end

#filenameObject (readonly)

Returns the value of attribute filename.



74
75
76
# File 'app/models/backup.rb', line 74

def filename
  @filename
end

#keyObject (readonly)

Returns the value of attribute key.



74
75
76
# File 'app/models/backup.rb', line 74

def key
  @key
end

Class Method Details

.from_record(record) ⇒ Object



104
105
106
107
# File 'app/models/backup.rb', line 104

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



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

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

#safe_keyObject



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

def safe_key
  DatabaseFile.sanitize key.to_s
end

#with_key(key) ⇒ Object



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

def with_key(key)
  @key = key
  self
end