Created
March 1, 2015 16:42
-
-
Save aristotelesbr/68f5ffcc17f7ab02bbec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "fileutils" | |
class Revista | |
def self.find(id) | |
raise DocumentNotFound, | |
"Arquivo db/revistas/#{id} não encontrado.", caller | |
unless File.exists?("db/revistas/#{id}.yml") | |
YAML.load File.open("db/revistas/#{id}.yml", "r") | |
encontrado | |
end | |
end | |
attr_reader :titulo, :id, :destroyed | |
attr_accessor :valor | |
#Cria | |
def initialize (titulo, valor) | |
@titulo = titulo | |
@valor = valor | |
@id = self.class.next_id #Atribui um id ao objeto Revista | |
@destroyed = false | |
end | |
#Salva | |
... | |
... | |
#Procura | |
def self.find(id) | |
YAML.load File.open("db/revistas/#{id}.yml", "r") | |
end | |
#Destroy | |
... | |
... | |
private | |
def serialize | |
YAML.dump self | |
end | |
def self.next_id | |
Dir.glob("db/revistas/*.yml").size + 1 | |
end | |
end |
dodops
commented
Mar 1, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment