resource_controller_extensions 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Blake Watters
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,31 @@
1
+ = resource_controller_extensions
2
+
3
+ This plugin provides support for adding reasonable default action handlers for
4
+ several types of Resources that you may wants to export via ResourceController:
5
+ * XML - For XML web services
6
+ * JSON - For JSON web services
7
+ * FBML - For Facebook FBML based pages.
8
+
9
+ Installation:
10
+ $ sudo gem install resource_controller_extensions
11
+
12
+ If you want to load XML, JSON, and FBML support, simply load the Gem in your config/environment file:
13
+
14
+ config.gem 'resource_controller_extensions', :lib => 'resource_controller_extensions'
15
+
16
+ To selectively enable one or more handlers, load the Gem and require the handlers in an after_initialize block:
17
+
18
+ config.gem 'resource_controller_extensions', :lib => false
19
+
20
+ # Pull in JSON and XML support for ResourceController
21
+ config.after_initialize do
22
+ require 'resource_controller_extensions/xml'
23
+ require 'resource_controller_extensions/json'
24
+ require 'resource_controller_extensions/fbml'
25
+ end
26
+
27
+ And enjoy!
28
+
29
+ == Copyright
30
+
31
+ Copyright (c) 2009 Blake Watters. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "resource_controller_extensions"
8
+ gem.summary = %Q{Provides sensible defaults action for XML, JSON, and FBML to Resource Controller.}
9
+ gem.email = "blake@twotoasters.com"
10
+ gem.homepage = "http://github.com/twotoasters/resource_controller_extensions"
11
+ gem.authors = ["Blake Watters"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION.yml')
45
+ config = YAML.load(File.read('VERSION.yml'))
46
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "resource_controller_extensions #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
56
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ # Don't require anything by default. Include the support
2
+ # you need by require'ing the handlers individually in environment.rb
3
+ # or by require'ing resource_controller_extensions to pull all of them.
@@ -0,0 +1,3 @@
1
+ require 'resource_controller_extensions/xml'
2
+ require 'resource_controller_extensions/json'
3
+ require 'resource_controller_extensions/fbml'
@@ -0,0 +1,51 @@
1
+ module ResourceControllerExtensions
2
+ module FBML
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ base.class_eval do
6
+ class << self
7
+ alias_method_chain :init_default_actions, :fbml
8
+ end
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+ def init_default_actions_with_fbml(klass)
14
+ init_default_actions_without_fbml(klass)
15
+ klass.class_eval do
16
+ index.wants.fbml
17
+ new_action.wants.fbml
18
+ edit.wants.fbml
19
+
20
+ show do
21
+ wants.fbml
22
+
23
+ failure.wants.fbml { render :text => "Member object not found." }
24
+ end
25
+
26
+ create do
27
+ flash "Successfully created!"
28
+ wants.fbml { redirect_to object_url }
29
+
30
+ failure.wants.fbml { render :action => "new" }
31
+ end
32
+
33
+ update do
34
+ flash "Successfully updated!"
35
+ wants.fbml { redirect_to object_url }
36
+
37
+ failure.wants.fbml { render :action => "edit" }
38
+ end
39
+
40
+ destroy do
41
+ flash "Successfully removed!"
42
+ wants.fbml { redirect_to collection_url }
43
+ failure.wants.fbml { redirect_to object_url }
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ ResourceController::Controller.send :include, ResourceControllerExtensions::FBML
@@ -0,0 +1,31 @@
1
+ module ResourceControllerExtensions
2
+ module JSON
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ base.class_eval do
6
+ class << self
7
+ alias_method_chain :init_default_actions, :json
8
+ end
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+ def init_default_actions_with_json(klass)
14
+ init_default_actions_without_json(klass)
15
+ klass.class_eval do
16
+ index.wants.json { render :json => collection.to_json, :status => :ok }
17
+ show.wants.json { render :json => object}
18
+ edit.wants.json { render :json => object}
19
+
20
+ create.wants.json { render :json => object, :status => :created, :location => object_url }
21
+ create.failure.wants.json { render :json => object.errors, :status => :unprocessable_entity }
22
+ destroy.wants.json { head :ok }
23
+ update.wants.json { head :ok }
24
+ update.failure.wants.json { render :json => object.errors, :status => :unprocessable_entity }
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ ResourceController::Controller.send :include, ResourceControllerExtensions::JSON
@@ -0,0 +1,32 @@
1
+ module ResourceControllerExtensions
2
+ module XML
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ base.class_eval do
6
+ class << self
7
+ alias_method_chain :init_default_actions, :xml
8
+ end
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+ def init_default_actions_with_xml(klass)
14
+ init_default_actions_without_xml(klass)
15
+ klass.class_eval do
16
+ index.wants.xml { render :xml => collection.to_xml, :status => :ok }
17
+ show.wants.xml { render :xml => object}
18
+ edit.wants.xml { render :xml => object}
19
+ new_action.wants.xml { render :xml => object }
20
+
21
+ create.wants.xml { render :xml => object, :status => :created, :location => object_url }
22
+ create.failure.wants.xml { render :xml => object.errors, :status => :unprocessable_entity }
23
+ destroy.wants.xml { head :ok }
24
+ update.wants.xml { head :ok }
25
+ update.failure.wants.xml { render :xml => object.errors, :status => :unprocessable_entity }
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ ResourceController::Controller.send :include, ResourceControllerExtensions::XML
@@ -0,0 +1,54 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{resource_controller_extensions}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Blake Watters"]
12
+ s.date = %q{2010-02-26}
13
+ s.email = %q{blake@twotoasters.com}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "init.rb",
26
+ "lib/resource_controller_extensions.rb",
27
+ "lib/resource_controller_extensions/fbml.rb",
28
+ "lib/resource_controller_extensions/json.rb",
29
+ "lib/resource_controller_extensions/xml.rb",
30
+ "resource_controller_extensions.gemspec",
31
+ "test/resource_controller_extensions_test.rb",
32
+ "test/test_helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/twotoasters/resource_controller_extensions}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.5}
38
+ s.summary = %q{Provides sensible defaults action for XML, JSON, and FBML to Resource Controller.}
39
+ s.test_files = [
40
+ "test/resource_controller_extensions_test.rb",
41
+ "test/test_helper.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ else
50
+ end
51
+ else
52
+ end
53
+ end
54
+
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class ResourceControllerExtensionsTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'resource_controller_extensions'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resource_controller_extensions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Blake Watters
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-26 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: blake@twotoasters.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - init.rb
33
+ - lib/resource_controller_extensions.rb
34
+ - lib/resource_controller_extensions/fbml.rb
35
+ - lib/resource_controller_extensions/json.rb
36
+ - lib/resource_controller_extensions/xml.rb
37
+ - resource_controller_extensions.gemspec
38
+ - test/resource_controller_extensions_test.rb
39
+ - test/test_helper.rb
40
+ has_rdoc: true
41
+ homepage: http://github.com/twotoasters/resource_controller_extensions
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --charset=UTF-8
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.3.5
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Provides sensible defaults action for XML, JSON, and FBML to Resource Controller.
68
+ test_files:
69
+ - test/resource_controller_extensions_test.rb
70
+ - test/test_helper.rb