Rails BeatDB draft
This commit is contained in:
parent
4cdd06efca
commit
2f611742ba
|
@ -1,5 +1,6 @@
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
protect_from_forgery
|
protect_from_forgery
|
||||||
|
require 'beatdb'
|
||||||
require 'pp'
|
require 'pp'
|
||||||
#require 'cobravsmongoose'
|
#require 'cobravsmongoose'
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,2 +1,15 @@
|
||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
end
|
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
|
|
@ -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
|
|
@ -1,9 +1,9 @@
|
||||||
<h1 class="artist"><%= @artist.name %></h1>
|
<h1 class="artist"><%= @artist.name %></h1>
|
||||||
<% @artist.albums.each do |album| %>
|
<% @artist.albums.each do |album| %>
|
||||||
<% if album.releases.length > 0 %>
|
<% unless album.releases.empty? %>
|
||||||
<div class="album">
|
<div class="album">
|
||||||
<div class="pic"></div>
|
<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
|
releases = album.releases
|
||||||
first_release = releases.first
|
first_release = releases.first
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
<li>
|
<li>
|
||||||
<span class="play"></span>
|
<span class="play"></span>
|
||||||
<span class="track-name"><%= track.name %></span>
|
<span class="track-name"><%= track.name %></span>
|
||||||
<span class="duration"><%= track.length %></span>
|
<span class="duration"><%= track.length.toTime %></span>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -38,5 +38,7 @@ module Beathaven
|
||||||
|
|
||||||
# Configure sensitive parameters which will be filtered from the log file.
|
# Configure sensitive parameters which will be filtered from the log file.
|
||||||
config.filter_parameters += [:password]
|
config.filter_parameters += [:password]
|
||||||
|
|
||||||
|
#config.autoload_paths += %W(#{config.root}/lib/db)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
#utf-8
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
|
|
||||||
# Set up gems listed in the Gemfile.
|
# Set up gems listed in the Gemfile.
|
||||||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
||||||
|
|
||||||
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
||||||
|
require 'json'
|
Loading…
Reference in New Issue