roar 0.0.1.alpha1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +8 -0
- data/README.textile +297 -0
- data/Rakefile +16 -0
- data/lib/roar/client/entity_proxy.rb +58 -0
- data/lib/roar/client/proxy.rb +14 -0
- data/lib/roar/client/transport.rb +29 -0
- data/lib/roar/model.rb +36 -0
- data/lib/roar/model/representable.rb +31 -0
- data/lib/roar/rails.rb +21 -0
- data/lib/roar/rails/controller_methods.rb +71 -0
- data/lib/roar/rails/representer_methods.rb +52 -0
- data/lib/roar/rails/test_case.rb +43 -0
- data/lib/roar/representer.rb +72 -0
- data/lib/roar/representer/feature/http_verbs.rb +63 -0
- data/lib/roar/representer/feature/hypermedia.rb +43 -0
- data/lib/roar/representer/feature/model_representing.rb +88 -0
- data/lib/roar/representer/json.rb +32 -0
- data/lib/roar/representer/xml.rb +43 -0
- data/lib/roar/version.rb +1 -1
- data/roar.gemspec +10 -1
- data/test/Gemfile +6 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/controllers/albums_controller.rb +27 -0
- data/test/dummy/app/controllers/application_controller.rb +4 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/album.rb +6 -0
- data/test/dummy/app/models/song.rb +2 -0
- data/test/dummy/app/representers/representer/xml/album.rb +19 -0
- data/test/dummy/app/representers/representer/xml/song.rb +9 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/musician/featured.html.erb +1 -0
- data/test/dummy/app/views/musician/featured_with_block.html.erb +4 -0
- data/test/dummy/app/views/musician/hamlet.html.haml +1 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +20 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +22 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +16 -0
- data/test/dummy/config/environments/production.rb +46 -0
- data/test/dummy/config/environments/test.rb +32 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +7 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20110514114753_create_albums.rb +14 -0
- data/test/dummy/db/migrate/20110514121228_create_songs.rb +14 -0
- data/test/dummy/db/schema.rb +29 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/module - (2011-05-14 15:26:19) +5 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/tmp/app/cells/blog/post/latest.html.erb +7 -0
- data/test/dummy/tmp/app/cells/blog/post_cell.rb +7 -0
- data/test/fake_server.rb +80 -0
- data/test/http_verbs_test.rb +46 -0
- data/test/hypermedia_test.rb +35 -0
- data/test/integration_test.rb +122 -0
- data/test/json_representer_test.rb +101 -0
- data/test/model_representing_test.rb +121 -0
- data/test/model_test.rb +50 -0
- data/test/order_representers.rb +34 -0
- data/test/proxy_test.rb +89 -0
- data/test/rails/controller_methods_test.rb +147 -0
- data/test/rails/rails_representer_methods_test.rb +32 -0
- data/test/representable_test.rb +49 -0
- data/test/representer_test.rb +25 -0
- data/test/ruby_representation_test.rb +144 -0
- data/test/test_helper.rb +45 -0
- data/test/test_helper_test.rb +59 -0
- data/test/transport_test.rb +34 -0
- data/test/xml_hypermedia_test.rb +47 -0
- data/test/xml_representer_test.rb +238 -0
- metadata +181 -13
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'roar/representer'
|
2
|
+
require 'representable/json'
|
3
|
+
|
4
|
+
|
5
|
+
module Roar
|
6
|
+
module Representer
|
7
|
+
class JSON < Base
|
8
|
+
include Representable::JSON
|
9
|
+
|
10
|
+
def serialize
|
11
|
+
to_json
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.deserialize(json)
|
15
|
+
from_json(json)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Encapsulates a hypermedia link.
|
19
|
+
class Hyperlink < self
|
20
|
+
self.representation_name = :link
|
21
|
+
|
22
|
+
property :rel
|
23
|
+
property :href
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.links_definition_options
|
27
|
+
{:as => [Hyperlink]}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'roar/representer'
|
2
|
+
require 'representable/xml'
|
3
|
+
|
4
|
+
|
5
|
+
module Roar
|
6
|
+
# Basic work-flow
|
7
|
+
# in: * representer parses representation
|
8
|
+
# * recognized elements are stored as representer attributes
|
9
|
+
# out: * attributes in representer are assigned - either as hash in #to_xml, by calling #serialize(represented),
|
10
|
+
# by calling representer's accessors (eg in client?) or whatever else
|
11
|
+
# * representation is compiled from representer only
|
12
|
+
# TODO: make XML a module to include in Hyperlink < Base.
|
13
|
+
module Representer
|
14
|
+
class XML < Base
|
15
|
+
include Representable::XML
|
16
|
+
|
17
|
+
def serialize
|
18
|
+
to_xml.serialize
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.deserialize(xml)
|
22
|
+
from_xml(xml)
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
# Encapsulates a hypermedia <link ...>.
|
27
|
+
class Hyperlink < self
|
28
|
+
self.representation_name = :link
|
29
|
+
|
30
|
+
property :rel, :from => "@rel"
|
31
|
+
property :href, :from => "@href"
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def self.links_definition_options
|
36
|
+
{:tag => :link, :as => [Hyperlink]}
|
37
|
+
end
|
38
|
+
|
39
|
+
require 'roar/representer/feature/hypermedia'
|
40
|
+
include Feature::Hypermedia
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/roar/version.rb
CHANGED
data/roar.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = ["apotonick@gmail.com"]
|
11
11
|
s.homepage = "http://rubygems.org/gems/roar"
|
12
12
|
s.summary = %q{Resource-oriented architectures in Ruby.}
|
13
|
-
s.description = %q{RESTful, resource-oriented architectures in Ruby.}
|
13
|
+
s.description = %q{Streamlines the development of RESTful, resource-oriented architectures in Ruby.}
|
14
14
|
|
15
15
|
s.rubyforge_project = "roar"
|
16
16
|
|
@@ -18,4 +18,13 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_runtime_dependency "representable"
|
23
|
+
s.add_runtime_dependency "restfulie", "~> 1.0.0"
|
24
|
+
s.add_runtime_dependency "hooks", "~> 0.1.4"
|
25
|
+
s.add_runtime_dependency "test_xml"
|
26
|
+
|
27
|
+
s.add_development_dependency "minitest", "~> 1.6.0"
|
28
|
+
s.add_development_dependency "sinatra", "~> 1.2.6"
|
29
|
+
s.add_development_dependency "sinatra-reloader", "~> 0.5.0"
|
21
30
|
end
|
data/test/Gemfile
ADDED
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
5
|
+
require 'rake'
|
6
|
+
|
7
|
+
Rails::Application.load_tasks
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'roar/rails'
|
2
|
+
|
3
|
+
class AlbumsController < ActionController::Base
|
4
|
+
include Roar::Rails::ControllerMethods
|
5
|
+
|
6
|
+
respond_to :xml
|
7
|
+
represents Album
|
8
|
+
|
9
|
+
def show
|
10
|
+
@album = Album.find(params[:id])
|
11
|
+
respond_with @album
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
@album = Album.create(representation)
|
16
|
+
|
17
|
+
respond_with @album
|
18
|
+
end
|
19
|
+
|
20
|
+
def update
|
21
|
+
@album = Album.find(params[:id])
|
22
|
+
@album.songs.delete_all # make PUT behave REST-compliant.
|
23
|
+
@album.update_attributes(representation)
|
24
|
+
|
25
|
+
respond_with @album
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Representer
|
2
|
+
module XML
|
3
|
+
class Album < Roar::Representer::XML
|
4
|
+
self.representation_name= :album
|
5
|
+
|
6
|
+
property :id
|
7
|
+
property :year
|
8
|
+
collection :songs
|
9
|
+
|
10
|
+
link :self do
|
11
|
+
album_url(represented.id)
|
12
|
+
end
|
13
|
+
|
14
|
+
link "album-search" do
|
15
|
+
album_search_url
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render_cell :bassist, :provoke %>
|
@@ -0,0 +1 @@
|
|
1
|
+
= render_cell :bassist, :provoke
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require "active_model/railtie"
|
4
|
+
require "action_controller/railtie"
|
5
|
+
require "action_view/railtie"
|
6
|
+
require "active_record/railtie"
|
7
|
+
|
8
|
+
Bundler.require
|
9
|
+
|
10
|
+
|
11
|
+
#require "rails_app"
|
12
|
+
|
13
|
+
module Dummy
|
14
|
+
class Application < Rails::Application
|
15
|
+
config.encoding = "utf-8"
|
16
|
+
|
17
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
18
|
+
config.filter_parameters += [:password]
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3-ruby (not necessary on OS X Leopard)
|
3
|
+
development:
|
4
|
+
adapter: sqlite3
|
5
|
+
database: db/development.sqlite3
|
6
|
+
pool: 5
|
7
|
+
timeout: 5000
|
8
|
+
|
9
|
+
# Warning: The database defined as "test" will be erased and
|
10
|
+
# re-generated from your development database when you run "rake".
|
11
|
+
# Do not set this db to the same as development or production.
|
12
|
+
test:
|
13
|
+
adapter: sqlite3
|
14
|
+
database: db/test.sqlite3
|
15
|
+
pool: 5
|
16
|
+
timeout: 5000
|
17
|
+
|
18
|
+
production:
|
19
|
+
adapter: sqlite3
|
20
|
+
database: db/production.sqlite3
|
21
|
+
pool: 5
|
22
|
+
timeout: 5000
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the webserver when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_view.debug_rjs = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
3
|
+
|
4
|
+
# The production environment is meant for finished, "live" apps.
|
5
|
+
# Code is not reloaded between requests
|
6
|
+
config.cache_classes = true
|
7
|
+
|
8
|
+
# Full error reports are disabled and caching is turned on
|
9
|
+
config.consider_all_requests_local = false
|
10
|
+
config.action_controller.perform_caching = true
|
11
|
+
|
12
|
+
# Specifies the header that your server uses for sending files
|
13
|
+
config.action_dispatch.x_sendfile_header = "X-Sendfile"
|
14
|
+
|
15
|
+
# For nginx:
|
16
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
|
17
|
+
|
18
|
+
# If you have no front-end server that supports something like X-Sendfile,
|
19
|
+
# just comment this out and Rails will serve the files
|
20
|
+
|
21
|
+
# See everything in the log (default is :info)
|
22
|
+
# config.log_level = :debug
|
23
|
+
|
24
|
+
# Use a different logger for distributed setups
|
25
|
+
# config.logger = SyslogLogger.new
|
26
|
+
|
27
|
+
# Use a different cache store in production
|
28
|
+
# config.cache_store = :mem_cache_store
|
29
|
+
|
30
|
+
# Disable Rails's static asset server
|
31
|
+
# In production, Apache or nginx will already do this
|
32
|
+
config.serve_static_assets = false
|
33
|
+
|
34
|
+
# Enable serving of images, stylesheets, and javascripts from an asset server
|
35
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
36
|
+
|
37
|
+
# Disable delivery errors, bad email addresses will be ignored
|
38
|
+
# config.action_mailer.raise_delivery_errors = false
|
39
|
+
|
40
|
+
# Enable threaded mode
|
41
|
+
# config.threadsafe!
|
42
|
+
|
43
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
44
|
+
# the I18n.default_locale when a translation can not be found)
|
45
|
+
config.i18n.fallbacks = true
|
46
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Log error messages when you accidentally call methods on nil.
|
11
|
+
config.whiny_nils = true
|
12
|
+
|
13
|
+
# Show full error reports and disable caching
|
14
|
+
config.consider_all_requests_local = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Raise exceptions instead of rendering exception templates
|
18
|
+
config.action_dispatch.show_exceptions = false
|
19
|
+
|
20
|
+
# Disable request forgery protection in test environment
|
21
|
+
config.action_controller.allow_forgery_protection = false
|
22
|
+
|
23
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
24
|
+
# The :test delivery method accumulates sent emails in the
|
25
|
+
# ActionMailer::Base.deliveries array.
|
26
|
+
#config.action_mailer.delivery_method = :test
|
27
|
+
|
28
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
29
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
30
|
+
# like if you have constraints or database-specific column types
|
31
|
+
# config.active_record.schema_format = :sql
|
32
|
+
end
|
Binary file
|