lib/shinmun/comment.rb in shinmun-0.2 vs lib/shinmun/comment.rb in shinmun-0.5
- old
+ new
@@ -1,43 +1,16 @@
module Shinmun
class Comment
-
+
attr_accessor :time, :name, :email, :website, :text
def initialize(attributes)
for k, v in attributes
- send "#{k}=", v
+ send("#{k}=", v) if respond_to?("#{k}=")
end
- end
-
- def self.read(path)
- file = "comments/#{path}"
- comments = []
- if File.exist?(file)
- File.open(file, "r") do |io|
- io.flock(File::LOCK_SH)
- YAML.each_document(io) do |comment|
- comments << comment
- end
- io.flock(File::LOCK_UN)
- end
- end
-
- comments
- end
-
- def self.write(path, comment)
- file = "comments/#{path}"
-
- FileUtils.mkdir_p(File.dirname(file))
-
- File.open(file, "a") do |io|
- io.flock(File::LOCK_EX)
- io.puts(comment.to_yaml)
- io.flock(File::LOCK_UN)
- end
+ self.time ||= Time.now
end
end
end