boochtek-rails-crud_actions 0.0.3 → 0.0.4

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.
data/init.rb CHANGED
@@ -1 +1 @@
1
- require File.join(File.dirname(__FILE__), 'lib', 'crud_actions')
1
+ require File.join(File.dirname(__FILE__), 'lib', 'rails-crud_actions')
@@ -1,93 +1,104 @@
1
1
  $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
+
5
+ # This implementation partly based on http://blog.boldr.fr/posts/datamapper-0-9-avec-rails
6
+ # TODO: after_filters for finding default views.
7
+ # TODO: Filtering of items visible to a user.
8
+ # TODO: Complex filtering of index, for searching. (Similar to Justin's solution.)
9
+ # TODO: User-specifed model or collection.
10
+ # TODO: Pagination.
11
+ # TODO: Automatic rendering of a default page. (Separate module/gem.)
12
+
13
+
4
14
  module BoochTek
5
15
  module Rails
6
16
  module CrudActions
7
- VERSION = '0.0.3'
8
- class << self
9
- def included(base)
10
- base.extend ClassMethods
17
+ VERSION = '0.0.4'
18
+
19
+ def self.included(base)
20
+ base.class_eval do
21
+ extend ClassMethods
22
+ include InstanceMethods
23
+ before_filter :new_item, :only => [:new, :create]
24
+ before_filter :find_item, :only => [:show, :edit, :update, :delete, :destroy]
25
+ before_filter :find_items, :only => [:index]
26
+ before_filter :fill_item, :only => [:create, :update]
11
27
  end
12
28
  end
13
29
 
14
30
  module ClassMethods
15
31
  def crud_model=(model)
16
- @@current_model = (model.class == Class) ? model : model.constantize
32
+ @crud_model = (model.class == Class) ? model : model.constantize
17
33
  end
18
- end
19
- # This implementation based on http://blog.boldr.fr/posts/datamapper-0-9-avec-rails
20
- #before_filter :new_item, :only => [:new, :create]
21
- #before_filter :find_item, :only => [:show, :edit, :update, :delete, :destroy]
22
- #before_filter :find_items, :only => [:index]
23
- #before_filter :fill_item, :only => [:create, :update]
24
- # TODO: after_filters for finding default views.
25
- # TODO: Filtering of items visible to a user.
26
- # TODO: Complex filtering of index, for searching. (Similar to Justin's solution.)
27
- # TODO: User-specifed model or collection.
28
- # TODO: Pagination.
29
- # TODO: Automatic rendering of a default page. (Separate module/gem.)
30
- def index
31
- end
32
34
 
33
- def show
35
+ def crud_model
36
+ @crud_model ||= controller_name.singularize.camelize.constantize
37
+ end
34
38
  end
35
39
 
36
- def new
37
- end
40
+ module InstanceMethods
41
+ def index
42
+ end
38
43
 
39
- def edit
40
- end
44
+ def show
45
+ end
41
46
 
42
- def delete
43
- end
47
+ def new
48
+ end
44
49
 
45
- def create
46
- save_or_render 'new'
47
- end
50
+ def edit
51
+ end
48
52
 
49
- def update
50
- save_or_render 'edit'
51
- end
53
+ def delete
54
+ end
52
55
 
53
- def destroy
54
- @current_item.destroy
55
- respond_to do |format|
56
- format.html { redirect_to(self.send("#{current_model.table_name.singularize}_index_url")) }
57
- format.xml { head :ok }
56
+ def create
57
+ save_or_render 'new'
58
58
  end
59
- end
60
59
 
61
- protected
60
+ def update
61
+ save_or_render 'edit'
62
+ end
62
63
 
63
- def new_item
64
- @current_item = current_model.new
65
- end
64
+ def destroy
65
+ @current_item.destroy
66
+ respond_to do |format|
67
+ format.html { redirect_to(self.send("#{current_model.table_name.singularize}_index_url")) }
68
+ format.xml { head :ok }
69
+ end
70
+ end
66
71
 
67
- def find_item
68
- @current_item = current_model[params[:id]]
69
- end
72
+ protected
70
73
 
71
- def find_items
72
- @current_items = current_model.all
73
- end
74
+ def new_item
75
+ @current_item = current_model.new
76
+ end
74
77
 
75
- def fill_item
76
- @current_item.attributes = params[:item]
77
- end
78
+ def find_item
79
+ @current_item = current_model[params[:id]]
80
+ end
78
81
 
79
- def save_or_render(action)
80
- if @current_item.save
81
- redirect_to @current_item
82
- else
83
- render :action => action
82
+ def find_items
83
+ @current_items = current_model.all
84
84
  end
85
- end
86
85
 
87
- def current_model
88
- @@current_model ||= controller_name.singularize.camelize.constantize
89
- end
86
+ def fill_item
87
+ @current_item.attributes = params[:item]
88
+ end
90
89
 
90
+ def save_or_render(action)
91
+ if @current_item.save
92
+ redirect_to @current_item
93
+ else
94
+ render :action => action
95
+ end
96
+ end
97
+
98
+ def current_model
99
+ self.class.crud_model
100
+ end
101
+ end
91
102
  end
92
103
  end
93
104
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rails-crud_actions}
5
- s.version = "0.0.3"
5
+ s.version = "0.0.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Craig Buchek"]
9
- s.date = %q{2009-01-25}
9
+ s.date = %q{2009-01-27}
10
10
  s.description = %q{Provides default CRUD actions for a Rails controller.}
11
11
  s.email = ["craig@boochtek.com"]
12
12
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boochtek-rails-crud_actions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Buchek
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-25 00:00:00 -08:00
12
+ date: 2009-01-27 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency