-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved things around to package into yogo-framework gem.
- Loading branch information
Showing
14 changed files
with
145 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,27 @@ | ||
# require 'rubygems' | ||
# require 'bundler/setup' | ||
# | ||
# Bundler.require(:default, ENV['RACK_ENV']) | ||
# | ||
# $:.unshift File.dirname(__FILE__) | ||
# | ||
# require 'lib/yogo/model_lookup' | ||
# | ||
# require 'app/yogo/schema_app' | ||
# encoding: utf-8 | ||
# Standard requirements for Bundler management | ||
require 'rubygems' | ||
require 'bundler/setup' | ||
|
||
require './config/requires' | ||
# Load the bundler gemset | ||
Bundler.require(:default, ENV['RACK_ENV'] || :development ) | ||
|
||
# Mess with load paths | ||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib')) | ||
|
||
# Configure DataMapper | ||
require 'config/datamapper' | ||
|
||
# Load Application pieces | ||
require 'yogo/rack/model_lookup' | ||
require 'yogo/schema_app' | ||
require 'yogo/data_app' | ||
|
||
# Load the Application Version | ||
APP_VERSION = IO.readlines(File.join(File.dirname(__FILE__), 'VERSION'))[0] | ||
|
||
# Make the model lookup map | ||
use Yogo::Rack::ModelLookup, :paths => ['schema', 'data'] | ||
|
||
use Yogo::SchemaApp | ||
run Sinatra::Base | ||
# Run the app | ||
run Rack::Cascade.new([Yogo::SchemaApp, Yogo::DataApp]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,50 @@ | ||
require 'sinatra' | ||
# require 'json' | ||
|
||
module Yogo | ||
class DataApp < ::Sinatra::Base | ||
|
||
# configure(:development) do | ||
# register ::Sinatra::Reloader | ||
# also_reload "app/models/*.rb" | ||
# # dont_reload "lib/**/*.rb" | ||
# end | ||
|
||
before do | ||
content_type :json | ||
end | ||
|
||
# I don't think this should return anything. | ||
# get '/data/?' do | ||
# { :content => Schema.all }.to_json | ||
# end | ||
|
||
get '/data/:model_id/?' do | ||
{ :content => env['yogo.resource'].all }.to_json | ||
end | ||
|
||
get '/data/:model_id/:id' do | ||
resource = env['yogo.resource'] | ||
item = resource.get(params[:id]) | ||
|
||
{ :content => item }.to_json | ||
end | ||
|
||
post '/data/:model_id' do | ||
resource = env['yogo.resource'] | ||
opts = resource.parse_json(request.body.read) rescue nil | ||
|
||
halt(401, 'Invalid Format') if opts.nil? | ||
|
||
item = resource.new(opts) | ||
|
||
halt(500, 'Could not save item') unless item.save | ||
|
||
response['Location'] = item.to_url | ||
response.status = 201 | ||
end | ||
|
||
put '/schema/:model_id/:id' do | ||
resource = env['yogo.resource'] | ||
item = resource.get(params[:id]) | ||
opts = resource.parse_json(request.body.read) rescue nil | ||
halt(401, 'Invalid Format') if opts.nil? | ||
|
||
halt(500, 'Could not update schema') unless item.update(opts) | ||
|
||
{ :content => item }.to_json | ||
end | ||
|
||
delete '/schema/:model_id/:id' do | ||
env['yogo.resource'].get(params[:id]).destroy | ||
end | ||
|
||
end | ||
end |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.