roar 0.0.1.alpha1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +8 -0
  3. data/README.textile +297 -0
  4. data/Rakefile +16 -0
  5. data/lib/roar/client/entity_proxy.rb +58 -0
  6. data/lib/roar/client/proxy.rb +14 -0
  7. data/lib/roar/client/transport.rb +29 -0
  8. data/lib/roar/model.rb +36 -0
  9. data/lib/roar/model/representable.rb +31 -0
  10. data/lib/roar/rails.rb +21 -0
  11. data/lib/roar/rails/controller_methods.rb +71 -0
  12. data/lib/roar/rails/representer_methods.rb +52 -0
  13. data/lib/roar/rails/test_case.rb +43 -0
  14. data/lib/roar/representer.rb +72 -0
  15. data/lib/roar/representer/feature/http_verbs.rb +63 -0
  16. data/lib/roar/representer/feature/hypermedia.rb +43 -0
  17. data/lib/roar/representer/feature/model_representing.rb +88 -0
  18. data/lib/roar/representer/json.rb +32 -0
  19. data/lib/roar/representer/xml.rb +43 -0
  20. data/lib/roar/version.rb +1 -1
  21. data/roar.gemspec +10 -1
  22. data/test/Gemfile +6 -0
  23. data/test/dummy/Rakefile +7 -0
  24. data/test/dummy/app/controllers/albums_controller.rb +27 -0
  25. data/test/dummy/app/controllers/application_controller.rb +4 -0
  26. data/test/dummy/app/helpers/application_helper.rb +2 -0
  27. data/test/dummy/app/models/album.rb +6 -0
  28. data/test/dummy/app/models/song.rb +2 -0
  29. data/test/dummy/app/representers/representer/xml/album.rb +19 -0
  30. data/test/dummy/app/representers/representer/xml/song.rb +9 -0
  31. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  32. data/test/dummy/app/views/musician/featured.html.erb +1 -0
  33. data/test/dummy/app/views/musician/featured_with_block.html.erb +4 -0
  34. data/test/dummy/app/views/musician/hamlet.html.haml +1 -0
  35. data/test/dummy/config.ru +4 -0
  36. data/test/dummy/config/application.rb +20 -0
  37. data/test/dummy/config/boot.rb +10 -0
  38. data/test/dummy/config/database.yml +22 -0
  39. data/test/dummy/config/environment.rb +5 -0
  40. data/test/dummy/config/environments/development.rb +16 -0
  41. data/test/dummy/config/environments/production.rb +46 -0
  42. data/test/dummy/config/environments/test.rb +32 -0
  43. data/test/dummy/config/locales/en.yml +5 -0
  44. data/test/dummy/config/routes.rb +7 -0
  45. data/test/dummy/db/development.sqlite3 +0 -0
  46. data/test/dummy/db/migrate/20110514114753_create_albums.rb +14 -0
  47. data/test/dummy/db/migrate/20110514121228_create_songs.rb +14 -0
  48. data/test/dummy/db/schema.rb +29 -0
  49. data/test/dummy/db/test.sqlite3 +0 -0
  50. data/test/dummy/module - (2011-05-14 15:26:19) +5 -0
  51. data/test/dummy/public/404.html +26 -0
  52. data/test/dummy/public/422.html +26 -0
  53. data/test/dummy/public/500.html +26 -0
  54. data/test/dummy/public/favicon.ico +0 -0
  55. data/test/dummy/script/rails +6 -0
  56. data/test/dummy/tmp/app/cells/blog/post/latest.html.erb +7 -0
  57. data/test/dummy/tmp/app/cells/blog/post_cell.rb +7 -0
  58. data/test/fake_server.rb +80 -0
  59. data/test/http_verbs_test.rb +46 -0
  60. data/test/hypermedia_test.rb +35 -0
  61. data/test/integration_test.rb +122 -0
  62. data/test/json_representer_test.rb +101 -0
  63. data/test/model_representing_test.rb +121 -0
  64. data/test/model_test.rb +50 -0
  65. data/test/order_representers.rb +34 -0
  66. data/test/proxy_test.rb +89 -0
  67. data/test/rails/controller_methods_test.rb +147 -0
  68. data/test/rails/rails_representer_methods_test.rb +32 -0
  69. data/test/representable_test.rb +49 -0
  70. data/test/representer_test.rb +25 -0
  71. data/test/ruby_representation_test.rb +144 -0
  72. data/test/test_helper.rb +45 -0
  73. data/test/test_helper_test.rb +59 -0
  74. data/test/transport_test.rb +34 -0
  75. data/test/xml_hypermedia_test.rb +47 -0
  76. data/test/xml_representer_test.rb +238 -0
  77. 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
@@ -1,3 +1,3 @@
1
1
  module Roar
2
- VERSION = "0.0.1.alpha1"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -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
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "sinatra"
4
+ gem "sinatra-contrib", :path => "./sinatra-contrib"
5
+ gem "sinatra-activerecord"
6
+ gem "roar", :path => ".."
@@ -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,4 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ layout 'application'
4
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,6 @@
1
+ class Album < ActiveRecord::Base
2
+ has_many :songs
3
+ validates_presence_of :year
4
+
5
+ accepts_nested_attributes_for :songs, :allow_destroy => true
6
+ end
@@ -0,0 +1,2 @@
1
+ class Song < ActiveRecord::Base
2
+ 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,9 @@
1
+ module Representer
2
+ module XML
3
+ class Song < Roar::Representer::XML
4
+ self.representation_name= :song
5
+
6
+ property :title
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1 @@
1
+ <%= render_cell :bassist, :provoke %>
@@ -0,0 +1,4 @@
1
+ <% flag = false %>
2
+ <%= render_cell :bassist, :play do |cell|
3
+ flag = cell.class
4
+ end %> from <%= flag %>
@@ -0,0 +1 @@
1
+ = render_cell :bassist, :provoke
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -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,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -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,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -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
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,7 @@
1
+ Dummy::Application.routes.draw do
2
+ match ':controller(/:action(/:id(.:format)))'
3
+ root :to => 'musician#index'
4
+ resources :albums
5
+ resources :songs
6
+ get "articles/starts_with/{query}", :to => "albums#search",:as => :album_search
7
+ end
@@ -0,0 +1,14 @@
1
+ class CreateAlbums < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :albums do |t|
4
+ t.string :title
5
+ t.string :year
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :albums
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ class CreateSongs < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :songs do |t|
4
+ t.string :title
5
+ t.integer :album_id
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :songs
13
+ end
14
+ end