Permalink
Browse files

Rename Tent::Server to TentServer, start on Post model

  • Loading branch information...
1 parent 3ca0f94 commit ab52270e5d96e51eaa61a236b79cd205dbbcfadb @titanous titanous committed Aug 24, 2012
View
2 Gemfile
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in tent-server.gemspec
gemspec
+
+gem 'dm-postgres-adapter'
View
2 Guardfile
@@ -1,6 +1,6 @@
guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^lib/tent-server/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
watch(%r{^lib/[^/]+\.rb$}) { "spec" }
watch(%r{spec/(spec_helper|support/).*\.rb}) { "spec" }
end
View
10 lib/tent-server.rb
@@ -1,9 +1,7 @@
require 'tent-server/version'
-module Tent
- module Server
- autoload :API, 'tent-server/api'
- end
+module TentServer
+ autoload :API, 'tent-server/api'
+ autoload :Action, 'tent-server/action'
+ autoload :Model, 'tent-server/model'
end
-
-require 'tent-server/action'
View
9 lib/tent-server/action.rb
@@ -1,7 +1,6 @@
-module Tent
- module Server
- module Action
- autoload :Posts, 'tent-server/action/posts'
- end
+module TentServer
+ module Action
+ autoload :Posts, 'tent-server/action/posts'
+ autoload :Builder, 'tent-server/action/builder'
end
end
View
63 lib/tent-server/action/builder.rb
@@ -1,41 +1,38 @@
-module Tent
- module Server
- module Action
- # Tent::Server::Action::Builder implements a small DSL to add middleware to the call stack.
+module TentServer
+ module Action
+ # Tent::Server::Action::Builder implements a small DSL to add middleware to the call stack.
+ #
+ # Example:
+ #
+ # app = Tent::Server::Action::Builder.new.tap do |b|
+ # b.use Rack::CommonLogger
+ # end
+ #
+ # app.call(env)
+ class Builder
+ # Specifies middleware to use in a stack.
#
- # Example:
+ # class Middleware
+ # def initialize(app)
+ # @app = app
+ # end
#
- # app = Tent::Server::Action::Builder.new.tap do |b|
- # b.use Rack::CommonLogger
- # end
+ # def call(env)
+ # @app.call(env)
+ # end
+ # end
#
- # app.call(env)
-
- class Builder
- # Specifies middleware to use in a stack.
- #
- # class Middleware
- # def initialize(app)
- # @app = app
- # end
- #
- # def call(env)
- # @app.call(env)
- # end
- # end
- #
- def use(middleware, *args, &block)
- (@stack ||= []) << proc { |app| middleware.new(app, *args, &block) }
- end
+ def use(middleware, *args, &block)
+ (@stack ||= []) << proc { |app| middleware.new(app, *args, &block) }
+ end
- def to_app
- app = lambda { |env| env }
- @stack.reverse.inject(app) { |a,e| e[a] }
- end
+ def to_app
+ app = lambda { |env| env }
+ @stack.reverse.inject(app) { |a,e| e[a] }
+ end
- def call(env)
- to_app.call(env)
- end
+ def call(env)
+ to_app.call(env)
end
end
end
View
18 lib/tent-server/action/posts.rb
@@ -1,14 +1,12 @@
-module Tent
- module Server
- module Action
- class Posts
- autoload :Get, 'tent-server/action/posts/get'
+module TentServer
+ module Action
+ class Posts
+ autoload :Get, 'tent-server/action/posts/get'
- def self.get(env)
- Builder.new.tap do |b|
- b.use Get
- end.call env
- end
+ def self.get(env)
+ Builder.new.tap do |b|
+ b.use Get
+ end.call env
end
end
end
View
22 lib/tent-server/action/posts/get.rb
@@ -1,16 +1,14 @@
-module Tent
- module Server
- module Action
- class Posts
- class Get
- def initialize(app, options={})
- @app, @options = app, options
- end
+module TentServer
+ module Action
+ class Posts
+ class Get
+ def initialize(app, options={})
+ @app, @options = app, options
+ end
- def call(env)
- env['tent.post'] = ::Tent::Server::Post.find(env['post_id'])
- @app.call(env)
- end
+ def call(env)
+ env['tent.post'] = ::TentServer::Post.find(env['post_id'])
+ @app.call(env)
end
end
end
View
10 lib/tent-server/api.rb
@@ -1,11 +1,9 @@
require 'grape'
-module Tent
- module Server
- class API < Grape::API
- autoload :Posts, 'tent-server/api/posts'
+module TentServer
+ class API < Grape::API
+ autoload :Posts, 'tent-server/api/posts'
- mount Posts
- end
+ mount Posts
end
end
View
12 lib/tent-server/api/posts.rb
@@ -1,10 +1,8 @@
-module Tent
- module Server
- class API
- class Posts < Grape::API
- get "/posts/:post_id" do
- Action.get_post(env)
- end
+module TentServer
+ class API
+ class Posts < Grape::API
+ get "/posts/:post_id" do
+ Action.get_post(env)
end
end
end
View
16 lib/tent-server/data_mapper_array_property.rb
@@ -0,0 +1,16 @@
+module DataMapper
+ class Property
+ # Implements flat postgres string arrays
+ class Array < String
+ load_as ::Array
+
+ def load(value)
+ value[1..-2].split(',') if value
+ end
+
+ def dump(value)
+ "{#{value.map(&:to_s).map(&:inspect).join(',')}}" if value
+ end
+ end
+ end
+end
View
8 lib/tent-server/model.rb
@@ -0,0 +1,8 @@
+require 'data_mapper'
+require 'tent-server/data_mapper_array_property'
+
+module TentServer
+ module Model
+ autoload :Post, 'tent-server/model/post'
+ end
+end
View
18 lib/tent-server/model/post.rb
@@ -0,0 +1,18 @@
+module TentServer
+ module Model
+ class Post
+ include DataMapper::Resource
+
+ property :id, Serial
+ property :entity, URI
+ property :scope, Enum[:public, :limited, :direct], :default => :direct
+ property :type, URI
+ property :licenses, Array
+ property :groups, Array
+ property :recipients, Array
+ property :content, Json
+ property :published_at, DateTime
+ property :received_at, DateTime
+ end
+ end
+end
View
6 lib/tent-server/version.rb
@@ -1,5 +1,3 @@
-module Tent
- module Server
- VERSION = "0.0.1"
- end
+module TentServer
+ VERSION = '0.0.1'
end
View
6 spec/integration/model/post.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+describe TentServer::Model::Post do
+
+
+end
View
4 spec/lib/tent-server/action/builder_spec.rb → spec/unit/action/builder_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path("../../../../../lib/tent-server/action/builder", __FILE__)
+require 'spec_helper'
class TestMiddleware
def initialize(app)
@@ -12,7 +12,7 @@ def call(env)
end
end
-describe Tent::Server::Action::Builder do
+describe TentServer::Action::Builder do
let(:instance) { described_class.new }
context "basic `use`" do
View
6 .../lib/tent-server/action/posts/get_spec.rb → spec/unit/action/posts/get_spec.rb
@@ -1,10 +1,10 @@
require 'spec_helper'
-class Tent::Server::Post; end
+class TentServer::Post; end
-describe Tent::Server::Action::Posts::Get do
+describe TentServer::Action::Posts::Get do
let(:app) { lambda { |env| env } }
- let(:post_class) { Tent::Server::Post }
+ let(:post_class) { TentServer::Post }
context "get single post" do
let(:instance) { described_class.new(app, :get_one) }
View
4 spec/lib/tent-server/api_spec.rb → spec/unit/api_spec.rb
@@ -1,8 +1,8 @@
require 'spec_helper'
-describe Tent::Server::API do
+describe TentServer::API do
def app
- Tent::Server::API
+ TentServer::API
end
describe "GET /foo" do
View
3 tent-server.gemspec
@@ -5,7 +5,7 @@ require 'tent-server/version'
Gem::Specification.new do |gem|
gem.name = "tent-server"
- gem.version = Tent::Server::VERSION
+ gem.version = TentServer::VERSION
gem.authors = ["Jonathan Rudenberg", "Jesse Stuart"]
gem.email = ["jonathan@titanous.com", "jessestuart@gmail.com"]
gem.description = %q{TODO: Write a gem description}
@@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
gem.require_paths = ["lib"]
gem.add_runtime_dependency 'grape'
+ gem.add_runtime_dependency 'data_mapper'
gem.add_development_dependency 'rack-test'
gem.add_development_dependency 'rspec'

0 comments on commit ab52270

Please sign in to comment.