aeonscope-btech_rest 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,17 @@
1
- v0.1.0 Initial version.
2
- v0.2.0 Fixed a bug where a resource with no namespace(s) would result in double slashed prefixes (i.e. "//").
3
- Added a resource breadcrumb helper.
4
- Added unobtrusive jQuery support.
1
+ = v0.1.0
2
+
3
+ * Initial version.
4
+
5
+ = v0.2.0
6
+
7
+ * Fixed a bug where a resource with no namespace(s) would result in double slashed prefixes (i.e. "//").
8
+ * Added a resource breadcrumb helper.
9
+ * Added unobtrusive jQuery support.
10
+
11
+ = v0.3.0
12
+
13
+ * Fixed the RDoc so it would generate properly on GitHub.
14
+ * Fixed the btech_rest.rb requirements so that they are platform agnostic.
15
+ * Added partial support for Rails 2.3 nested forms. You can at least build nested forms and this gem will handle them properly.
16
+
5
17
 
data/LICENSE.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008, 2009 "Berserk Technologies":http://www.berserktech.com
1
+ Copyright (c) 2008, 2009 Brooke Kuhlmann of {Berserk Technologies}[http://www.berserktech.com]
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -20,23 +20,23 @@ How is that for being {DRY}[http://en.wikipedia.org/wiki/DRY]? Read on to learn
20
20
 
21
21
  = License
22
22
 
23
- Copyright (c) 2008-2009 {Berserk Technologies}[http://www.berserktech.com].
24
- See the included {LICENSE}[link:LICENSE.rdoc] file for more info.
23
+ Copyright (c) 2008-2009 Brooke Kuhlmann of {Berserk Technologies}[http://www.berserktech.com].
24
+ See the included LICENSE for more info.
25
25
 
26
26
  = History
27
27
 
28
- See the {CHANGELOG}[link:CHANGELOG.rdoc] file for more info.
28
+ See the CHANGELOG file for more info.
29
29
 
30
30
  = Requirements
31
31
 
32
32
  1. Knowledge of the {Representational State Transfer (REST)}[http://en.wikipedia.com/wiki/REST]. Download and read {RESTful Rails}[http://www.b-simple.de/documents] if you need further info.
33
- 2. {mislav-will_paginate}[http://github.com/mislav/will_paginate/tree/master] gem. This is automatically installed/updated for you unless the correct version is detected.
33
+ 2. mislav-will_paginate[http://github.com/mislav/will_paginate/tree/master] gem. This is automatically installed/updated for you unless the correct version is detected.
34
34
 
35
35
  = Installation
36
36
 
37
37
  Type the following from the command line to install:
38
38
 
39
- * *MacOS/Linux*: sudo gem install btech_rest
39
+ * *UNIX*: sudo gem install btech_rest
40
40
  * *Windows*: gem install btech_rest
41
41
 
42
42
  Type the following from the command line to setup:
@@ -57,17 +57,17 @@ Example:
57
57
 
58
58
  To customize the RESTful behavior of your controller, use any combination of these three macros:
59
59
 
60
- * {belongs_to}[link:lib/class_method.rb] - Enables resource nesting where a controller can belong to a parent controller. This behavior is similar to the ActiveRecord {belongs_to}[http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/belongs_to] macro.
61
- * {resource_options}[link:lib/class_method.rb] - Allows you to customize the default behavior of your controller(s). There is a lot you can do with this, so follow the link and read the method comments to learn more.
62
- * {disabled_actions}[link:lib/class_method.rb] - Allows you to disable any of the default REST actions. Follow the link to learn more.
60
+ * *belongs_to* - Enables resource nesting where a controller can belong to a parent controller. This behavior is similar to the ActiveRecord {belongs_to}[http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/belongs_to] macro.
61
+ * *resource_options* - Allows you to customize the default behavior of your controller(s). There is a lot you can do with this, read the code documentation for more info.
62
+ * *disabled_actions* - Allows you to disable any of the default REST actions. Follow the link to learn more.
63
63
 
64
64
  Example:
65
65
 
66
66
  class Comments < ApplicationController
67
67
  include BTech::Rest
68
- belongs_to :posts
69
- resource_options :label => "My Wicked Comments"
70
- disabled_actions :show, :destroy
68
+ belongs_to :posts
69
+ resource_options :label => "My Wicked Comments"
70
+ disabled_actions :show, :destroy
71
71
  end
72
72
 
73
73
  Here is the breakdown, line-by-line, of the example shown above:
@@ -79,31 +79,31 @@ Here is the breakdown, line-by-line, of the example shown above:
79
79
 
80
80
  Using the post and comment controller relationship as defined above, we can break this relationship down even further. The post (parent) resource would have the following values (in this case, all default values):
81
81
 
82
- * +parent_key+ = N/A
83
- * +parent_value+ = N/A
84
- * +parent_resource_method+ = N/A
85
- * +name+ = "posts"
86
- * +label+ = "Posts"
87
- * +controller+ = PostsController
88
- * +model+ = Post
89
- * +record+ = #<Post id: 1, label: "Test", content: "Test", created_at: "2008-10-31 23:59:28", updated_at: "2008-10-31 23:59:28">
90
- * +namespaces+ = []
91
- * +show_partial+ = "/posts/show"
92
- * +new_or_edit_partial+ = "/posts/new_or_edit"
82
+ * *parent_key* = N/A
83
+ * *parent_value* = N/A
84
+ * *parent_resource_method* = N/A
85
+ * *name* = "posts"
86
+ * *label* = "Posts"
87
+ * *controller* = PostsController
88
+ * *model* = Post
89
+ * *record* = #<Post id: 1, label: "Test", content: "Test", created_at: "2008-10-31 23:59:28", updated_at: "2008-10-31 23:59:28">
90
+ * *namespaces* = []
91
+ * *show_partial* = "/posts/show"
92
+ * *new_or_edit_partial* = "/posts/new_or_edit"
93
93
 
94
94
  The comment (child) resource would have the following values:
95
95
 
96
- * +parent_key+ = post_id
97
- * +parent_value+ = 1
98
- * +parent_resource_method+ = N/A
99
- * +name+ = "comments"
100
- * +label+ = "My Wicked Comments"
101
- * +controller+ = CommentsController
102
- * +model+ = Comment
103
- * +record+ = #<Post id: 1, post_id: nil, label: "Test", content: "Test", created_at: "2008-10-31 23:59:28", updated_at: "2008-10-31 23:59:28">
104
- * +namespaces+ = []
105
- * +show_partial+ = "/comments/show"
106
- * +new_or_edit_partial+ = "/comments/new_or_edit"
96
+ * *parent_key* = post_id
97
+ * *parent_value* = 1
98
+ * *parent_resource_method* = N/A
99
+ * *name* = "comments"
100
+ * *label* = "My Wicked Comments"
101
+ * *controller* = CommentsController
102
+ * *model* = Comment
103
+ * *record* = #<Post id: 1, post_id: nil, label: "Test", content: "Test", created_at: "2008-10-31 23:59:28", updated_at: "2008-10-31 23:59:28">
104
+ * *namespaces* = []
105
+ * *show_partial* = "/comments/show"
106
+ * *new_or_edit_partial* = "/comments/new_or_edit"
107
107
 
108
108
  = Contact/Feedback/Issues
109
109
 
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "btech_rest"
8
+ gem.summary = "Easily adhere to DRY principals and add default REST functionality to your controllers."
9
+ gem.required_ruby_version = ">= 1.8.6"
10
+ gem.add_dependency "mislav-will_paginate", ">= 2.3.7"
11
+ gem.rdoc_options << "CHANGELOG.rdoc"
12
+ gem.authors = ["Brooke Kuhlmann"]
13
+ gem.email = "aeonscope@gmail.com"
14
+ gem.homepage = "http://github.com/aeonscope/btech-rest"
15
+ # gem.install_message = "Now you're being resourcefull!"
16
+ end
17
+ rescue LoadError
18
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
19
+ end
20
+
21
+ require 'rake/rdoctask'
22
+ Rake::RDocTask.new do |rdoc|
23
+ rdoc.rdoc_dir = 'rdoc'
24
+ rdoc.title = 'btech-rest'
25
+ rdoc.options << '--line-numbers' << '--inline-source'
26
+ rdoc.rdoc_files.include('README*')
27
+ rdoc.rdoc_files.include('lib/**/*.rb')
28
+ end
29
+
30
+ require 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/*_test.rb'
34
+ test.verbose = false
35
+ end
36
+
37
+ begin
38
+ require 'rcov/rcovtask'
39
+ Rcov::RcovTask.new do |test|
40
+ test.libs << 'test'
41
+ test.pattern = 'test/**/*_test.rb'
42
+ test.verbose = true
43
+ end
44
+ rescue LoadError
45
+ task :rcov do
46
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
47
+ end
48
+ end
49
+
50
+
51
+ task :default => :test
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 2
3
- :patch: 2
2
+ :minor: 3
3
+ :patch: 0
4
4
  :major: 0
data/lib/actions.rb CHANGED
@@ -11,7 +11,7 @@ module BTech
11
11
  records = parent.instance_eval("#{@resources.last[:parent_resource_method] || @resources.last[:name]}").paginate :page => params[:page], :per_page => 10
12
12
  else
13
13
  # Records for single resource.
14
- records_name = @resources.last[:model].name.underscore.pluralize
14
+ records_name = get_model_name.pluralize
15
15
  records = @resources.last[:model].all.paginate(:page => params[:page], :per_page => 10)
16
16
  end
17
17
  instance_variable_set "@#{records_name}", records
@@ -20,7 +20,7 @@ module BTech
20
20
  # Default show action. Feel free to override.
21
21
  def show
22
22
  build_resources
23
- render :partial => @resources.last[:show_partial], :layout => true, :locals => {model_to_sym(@resources.last[:model]) => get_record, :resources => @resources}
23
+ render :partial => @resources.last[:show_partial], :layout => true, :locals => {get_model_symbol => get_record, :resources => @resources}
24
24
  end
25
25
 
26
26
  # Default new action. Feel free to override.
@@ -38,7 +38,7 @@ module BTech
38
38
  # Default create action. Feel free to override.
39
39
  def create
40
40
  build_resources
41
- if get_record.update_attributes params[model_to_sym(@resources.last[:model])]
41
+ if get_record.update_attributes params[get_model_symbol]
42
42
  redirect_to build_resource_url(@resources)
43
43
  else
44
44
  render_new_or_edit
@@ -48,7 +48,7 @@ module BTech
48
48
  # Default update action. Feel free to override.
49
49
  def update
50
50
  build_resources
51
- if get_record.update_attributes params[model_to_sym(@resources.last[:model])]
51
+ if get_record.update_attributes params[get_model_symbol]
52
52
  redirect_to build_resource_url(@resources)
53
53
  else
54
54
  render_new_or_edit
@@ -67,7 +67,7 @@ module BTech
67
67
 
68
68
  # Convenience method for rendering the new or edit partial.
69
69
  def render_new_or_edit
70
- render :partial => @resources.last[:new_or_edit_partial], :layout => true, :locals => {model_to_sym(@resources.last[:model]) => get_record, :resources => @resources}
70
+ render :partial => @resources.last[:new_or_edit_partial], :layout => true, :locals => {get_model_symbol => get_record, :resources => @resources}
71
71
  end
72
72
 
73
73
  # Builds the RESTful parent URL based on an array of resources.
@@ -102,8 +102,19 @@ module BTech
102
102
 
103
103
  private
104
104
 
105
+ # Answers the name of the current model.
106
+ def get_model_name
107
+ @resources.last[:model].name.underscore
108
+ end
109
+
110
+ # Answers the symbol of the current model.
111
+ def get_model_symbol
112
+ get_model_name.to_sym
113
+ end
114
+
115
+ # Answers the current record (a.k.a. the record of the last resource).
105
116
  def get_record
106
- instance_variable_get "@#{@resources.last[:model].name.underscore}"
117
+ instance_variable_get "@#{get_model_name}"
107
118
  end
108
119
 
109
120
  # Builds all resources for the controller(s).
@@ -115,14 +126,9 @@ module BTech
115
126
  @resources.reverse!
116
127
  end
117
128
  # Convenience for holding the current record and for form manipulation.
118
- instance_variable_set "@#{@resources.last[:model].name.underscore}", @resources.last[:record]
129
+ instance_variable_set "@#{get_model_name}", @resources.last[:record]
119
130
  end
120
131
 
121
- # Converts a model name to a symbol.
122
- def model_to_sym model
123
- model.name.underscore.to_sym
124
- end
125
-
126
132
  # Convenience method for answering back a properly camelized controller name.
127
133
  def camelize_controller_name name
128
134
  name = name.gsub(/^(\w)/) {|c| c.capitalize}
data/lib/btech_rest.rb CHANGED
@@ -1,6 +1,6 @@
1
- require File.dirname(__FILE__) + "/class_methods.rb"
2
- require File.dirname(__FILE__) + "/actions.rb"
3
- require File.dirname(__FILE__) + "/resource_helper.rb"
1
+ require File.join(File.dirname(__FILE__), "class_methods.rb")
2
+ require File.join(File.dirname(__FILE__), "actions.rb")
3
+ require File.join(File.dirname(__FILE__), "resource_helper.rb")
4
4
 
5
5
  module BTech
6
6
  module Rest
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aeonscope-btech_rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-10 00:00:00 -07:00
12
+ date: 2009-04-11 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -29,12 +29,13 @@ executables: []
29
29
  extensions: []
30
30
 
31
31
  extra_rdoc_files:
32
- - README.rdoc
33
32
  - LICENSE.rdoc
33
+ - README.rdoc
34
34
  files:
35
35
  - CHANGELOG.rdoc
36
36
  - LICENSE.rdoc
37
37
  - README.rdoc
38
+ - Rakefile
38
39
  - VERSION.yml
39
40
  - lib/actions.rb
40
41
  - lib/btech_rest.rb
@@ -46,9 +47,8 @@ has_rdoc: true
46
47
  homepage: http://github.com/aeonscope/btech-rest
47
48
  post_install_message:
48
49
  rdoc_options:
49
- - CHANGELOG.rdoc
50
- - --inline-source
51
50
  - --charset=UTF-8
51
+ - CHANGELOG.rdoc
52
52
  require_paths:
53
53
  - lib
54
54
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -70,5 +70,6 @@ rubygems_version: 1.2.0
70
70
  signing_key:
71
71
  specification_version: 2
72
72
  summary: Easily adhere to DRY principals and add default REST functionality to your controllers.
73
- test_files: []
74
-
73
+ test_files:
74
+ - test/btech_rest_test.rb
75
+ - test/test_helper.rb