Sha256: 4a039a86c7dcdfb38a55b799dd85d5cef43af05c2616c4fb195ce9b5a70330da
Contents?: true
Size: 949 Bytes
Versions: 1
Compression:
Stored size: 949 Bytes
Contents
require 'multi_json' module Rhino module Model class FileModel def initialize(file_name) @file_name = file_name base_name = File.split(file_name)[-1] @id = File.basename(base_name, ".json").to_i obj = File.read(file_name) @hash = MultiJson.load(obj) end def [](name) @hash[name.to_s] end def []=(name, value) @hash[name.to_s] = value end def self.find(id) FileModel.new(Rhino::Application.root_path + "/db/quotes/#{id}.json") rescue nil end def self.all files = Dir[Rhino::Application.root_path + '/db/quotes/*.json'] files.map{|f| FileModel.new f}.select{|x| !x.nil? } end # TODO def self.find_by_committer(committer) end # TODO def self.where(options={}) end # TODO def update_attribute(options={}) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rhino-framework-0.0.4 | lib/rhino/file_model.rb |