1
0
Fork 0

Rails BeatDB draft

This commit is contained in:
magnolia-fan 2011-04-07 00:59:50 +04:00
parent 4cdd06efca
commit 2f611742ba
6 changed files with 54 additions and 3 deletions

View File

@ -1,5 +1,6 @@
class ApplicationController < ActionController::Base
protect_from_forgery
require 'beatdb'
require 'pp'
#require 'cobravsmongoose'
end

View File

@ -1,2 +1,15 @@
module ApplicationHelper
end
class Numeric
def toSeconds
(self / 1000).round
end
def toTime
s = self.toSeconds
m = (s / 60).floor
s -= m * 60
m.to_s << ':' << (s < 10 ? '0' : '') << s.to_s
end
end

View File

@ -0,0 +1,33 @@
class BeatDB
@@db_root = '/www/beatdb'
def self.get key
unless self.exists(key) || File.readable?(self.filePathByKey(key))
return false
end
h = File.open(self.filePathByKey(key), 'r')
JSON.decode(h.readline)
end
def self.set key, data
unless self.exists(key) || File.writable?(self.filePathByKey(key))
return false
end
h = File.open(self.filePathByKey(key), 'w')
h.puts(JSON.encode(data))
end
def self.delete key
end
def self.exists key
File.exists?(self.filePathByKey(key))
end
def self.filePathByKey key
path = ''
key.to_s.each_char {|c| path << '/' + c}
@@db_root + path[0..(path.length-2)] << key.to_s + '.json'
end
end

View File

@ -1,9 +1,9 @@
<h1 class="artist"><%= @artist.name %></h1>
<% @artist.albums.each do |album| %>
<% if album.releases.length > 0 %>
<% unless album.releases.empty? %>
<div class="album">
<div class="pic"></div>
<h3 class="name"><%= album.name %> (<%= album.year %>)</h3>
<h3 class="name"><%= album.name %> <%= (album.year ? album.year : '') %></h3>
<%
releases = album.releases
first_release = releases.first
@ -13,7 +13,7 @@
<li>
<span class="play"></span>
<span class="track-name"><%= track.name %></span>
<span class="duration"><%= track.length %></span>
<span class="duration"><%= track.length.toTime %></span>
</li>
<% end %>
</ul>

View File

@ -38,5 +38,7 @@ module Beathaven
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
#config.autoload_paths += %W(#{config.root}/lib/db)
end
end

View File

@ -1,6 +1,8 @@
#utf-8
require 'rubygems'
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
require 'json'