Permalink
Browse files

Bunch of changes

  • Loading branch information...
1 parent df61dae commit 0167038c535352ef99198aa8f6aff6f9aab47280 @meh committed Feb 17, 2012
Showing with 33 additions and 11 deletions.
  1. +7 −1 api/1.rb
  2. +4 −6 config.ru
  3. +22 −4 models/tag.rb
View
@@ -11,7 +11,7 @@
module Fag
class API < Grape::API
- version ?1
+ version ?1, using: :header, vendor: 'fag'
helpers do
def session
@@ -166,6 +166,12 @@ def authenticate!
end
end
+ resource :tags do
+ get '/:id' do
+ Tag.get(params[:id])
+ end
+ end
+
resource :flows do
get do
result = if !params[:expression] || params[:expression] == ?*
View
@@ -33,8 +33,6 @@ if ENV['FAG_PROFILE']
@app.call(env).tap {
profiler.stop
- FileUtils.mkpath path rescue nil
-
profiler.show File.open("#{path}/flat", 'w')
}
else
@@ -43,15 +41,15 @@ if ENV['FAG_PROFILE']
RubyProf.start
@app.call(env).tap {
- FileUtils.mkpath path rescue nil
-
RubyProf::MultiPrinter.new(RubyProf.stop).print(path: path, profile: 'profile')
}
end
end
def path
- ENV['FAG_PROFILE_PATH'] || '/tmp/profile'
+ (ENV['FAG_PROFILE_PATH'] || '/tmp/profile').tap {|path|
+ FileUtils.mkpath path rescue nil
+ }
end
}
end
@@ -62,7 +60,7 @@ use Rack::Csrf, field: 'csrf'
if Fag::Domains.empty?
run Fag::API
else
- run lambda {|env|
+ run -> env {
Fag::API.call(env).tap {|r|
%w[Origin Methods Headers].each {|name|
r[1]["Access-Control-Allow-#{name}"] = Fag::Domains.join ','
View
@@ -15,24 +15,42 @@ class Tag
include Fag::Serializable
include Fag::WithMetadata
+ def self.get (what)
+ what = what.to_s
+
+ if what.integer?
+ super(what.to_i)
+ else
+ first(name: what)
+ end
+ end
+
property :id, Serial
property :name, String, unique: true, required: true
+ def for_flows
+ FlowTag
+ end
+
+ def for_floats
+ FloatTag
+ end
+
def flows
- Flow.all(id: FlowTag.all(tag_id: id).unlazy.map(&:flow_id))
+ Flow.all(id: for_flows.all(tag_id: id).unlazy.map(&:flow_id))
end
def count_flows
- FlowTag.count(tag_id: id)
+ for_flows.count(tag_id: id)
end
def floats
- Float.all(id: FloatTag.all(tag_id: id).unlazy.map(&:float_id))
+ Float.all(id: for_floats.all(tag_id: id).unlazy.map(&:float_id))
end
def count_floats
- FloatTag.count(tag_id: id)
+ for_floats.count(tag_id: id)
end
serialize_as do

0 comments on commit 0167038

Please sign in to comment.