simplecrud 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +11 -5
- data/lib/simple_crud/base_controller.rb +26 -12
- data/lib/simple_crud/helper/decorator_helper.rb +13 -0
- data/lib/simple_crud/{accessors.rb → helper/model_helper.rb} +26 -7
- data/lib/simple_crud/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ee8c4571e58e02d7ebff90f2fea6787878b4ab1
|
4
|
+
data.tar.gz: b352c35cac42d5a42a74ea194bc1d4546b18fde6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aad8b99db80acbcf5597520b7f60db7d4aa1f68621bff6e9e0c16b897cee47436417ddcd0745324db82554214454a9d5dc8b0e6d92bdd2a786301605e472d65f
|
7
|
+
data.tar.gz: 114ad4d05e5520549851e1ef0b06289c1280bebca6408628837976772070c23b51f3bcca8515349c91f59e419fd55a48f37f193a8ad0c1ba347c2fa33948b845
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
simplecrud CHANGELOG
|
2
|
+
====================
|
3
|
+
|
4
|
+
This file is used to list changes made in each version of the simplecrud gem.
|
5
|
+
|
6
|
+
0.1.0
|
7
|
+
-----
|
8
|
+
- Initial release of simplecrud
|
9
|
+
|
10
|
+
0.1.1
|
11
|
+
-----
|
12
|
+
- Added validation on permission method
|
13
|
+
- Reordered model helper methods
|
14
|
+
- Added `models_path` method
|
15
|
+
- Fixed destroy action on BaseController
|
16
|
+
- Added internationalization messages
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ This is the easy way to create CRUDs for Rails controllers.
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem '
|
10
|
+
gem 'simplecrud'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -16,7 +16,7 @@ And then execute:
|
|
16
16
|
|
17
17
|
Or install it yourself as:
|
18
18
|
|
19
|
-
$ gem install
|
19
|
+
$ gem install simplecrud
|
20
20
|
|
21
21
|
Add an initializer to your rails app:
|
22
22
|
|
@@ -35,7 +35,7 @@ class DeviceController < SimpleCrud::BaseController
|
|
35
35
|
end
|
36
36
|
```
|
37
37
|
|
38
|
-
You will have available the expected `@device` or `@devices` instance var in
|
38
|
+
You will have available the expected `@device` or `@devices` instance var in
|
39
39
|
the views.
|
40
40
|
|
41
41
|
Case the name of your controller doesn't match the name of the model associated
|
@@ -43,12 +43,18 @@ you could use also:
|
|
43
43
|
|
44
44
|
```ruby
|
45
45
|
class MyCustomController < SimpleCrud::BaseController
|
46
|
-
crud_for Device
|
46
|
+
crud_for Device
|
47
47
|
end
|
48
48
|
```
|
49
49
|
|
50
50
|
To check the real code injected into the controllers check the source code: `lib/simple_crud/base_controller`
|
51
51
|
|
52
|
+
Available hooks
|
53
|
+
---------------
|
54
|
+
|
55
|
+
- `after_save`
|
56
|
+
- `after_update_attributes`
|
57
|
+
- `after_destroy`
|
52
58
|
|
53
59
|
## Development
|
54
60
|
|
@@ -58,7 +64,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
58
64
|
|
59
65
|
## Contributing
|
60
66
|
|
61
|
-
1. Fork it ( https://github.com/
|
67
|
+
1. Fork it ( https://github.com/dsaenztagarro/simple_crud/fork )
|
62
68
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
63
69
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
64
70
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -1,8 +1,11 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative 'helper/model_helper'
|
2
|
+
require_relative 'helper/decorator_helper'
|
2
3
|
|
3
4
|
module SimpleCrud
|
4
5
|
class BaseController < ::ApplicationController
|
5
|
-
include
|
6
|
+
include ModelHelper
|
7
|
+
include DecoratorHelper
|
8
|
+
|
6
9
|
before_filter :find_model, :only => [:show, :edit, :update, :destroy]
|
7
10
|
respond_to :html, :json
|
8
11
|
|
@@ -23,7 +26,7 @@ module SimpleCrud
|
|
23
26
|
# GET /models
|
24
27
|
# GET /models.json
|
25
28
|
def index
|
26
|
-
|
29
|
+
models_set model_klass.all
|
27
30
|
respond_with models
|
28
31
|
end
|
29
32
|
|
@@ -36,7 +39,7 @@ module SimpleCrud
|
|
36
39
|
# GET /models/new
|
37
40
|
# GET /models/new.json
|
38
41
|
def new
|
39
|
-
|
42
|
+
model_set model_klass.new
|
40
43
|
respond_with model
|
41
44
|
end
|
42
45
|
|
@@ -47,11 +50,13 @@ module SimpleCrud
|
|
47
50
|
# POST /models
|
48
51
|
# POST /models.json
|
49
52
|
def create
|
50
|
-
|
53
|
+
model_set model_klass.new(model_params)
|
51
54
|
|
52
55
|
respond_to do |wants|
|
53
|
-
|
54
|
-
|
56
|
+
result = model.save
|
57
|
+
call_hook :after_save, result
|
58
|
+
if result
|
59
|
+
flash[:notice] = t 'messages.record_created', model: t("models.#{model_name}")
|
55
60
|
wants.html { redirect_to(model) }
|
56
61
|
wants.json { render :json => model, :status => :created, :location => model }
|
57
62
|
else
|
@@ -65,8 +70,10 @@ module SimpleCrud
|
|
65
70
|
# PUT /models/1.json
|
66
71
|
def update
|
67
72
|
respond_to do |wants|
|
68
|
-
|
69
|
-
|
73
|
+
result = model.update_attributes(model_params)
|
74
|
+
call_hook :after_update_attributes, result
|
75
|
+
if result
|
76
|
+
flash[:notice] = t 'messages.record_updated', model: t("models.#{model_name}")
|
70
77
|
wants.html { redirect_to(model) }
|
71
78
|
wants.json { head :ok }
|
72
79
|
else
|
@@ -79,10 +86,12 @@ module SimpleCrud
|
|
79
86
|
# DELETE /models/1
|
80
87
|
# DELETE /models/1.json
|
81
88
|
def destroy
|
82
|
-
model.destroy
|
89
|
+
result = model.destroy
|
90
|
+
call_hook :after_destroy, result
|
91
|
+
flash[:notice] = t 'messages.record_destroyed', model: t("models.#{model_name}")
|
83
92
|
|
84
93
|
respond_to do |wants|
|
85
|
-
wants.html { redirect_to(
|
94
|
+
wants.html { redirect_to(models_path) }
|
86
95
|
wants.json { head :ok }
|
87
96
|
end
|
88
97
|
end
|
@@ -90,7 +99,12 @@ module SimpleCrud
|
|
90
99
|
private
|
91
100
|
|
92
101
|
def find_model
|
93
|
-
|
102
|
+
model_set model_klass.find(params[:id])
|
103
|
+
end
|
104
|
+
|
105
|
+
def call_hook(method, *args)
|
106
|
+
send(method, *args) if respond_to? method
|
94
107
|
end
|
108
|
+
|
95
109
|
end
|
96
110
|
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
module SimpleCrud
|
2
|
-
module
|
2
|
+
module ModelHelper
|
3
3
|
def model_klass
|
4
4
|
self.class.model_klass
|
5
5
|
end
|
6
6
|
|
7
|
+
# model related methods
|
8
|
+
|
7
9
|
def model
|
8
10
|
instance_variable_get model_var
|
9
11
|
end
|
10
12
|
|
11
|
-
def
|
13
|
+
def model_set(value)
|
12
14
|
instance_variable_set model_var, value
|
13
15
|
end
|
14
16
|
|
@@ -16,19 +18,17 @@ module SimpleCrud
|
|
16
18
|
model_klass.to_s.underscore.downcase
|
17
19
|
end
|
18
20
|
|
19
|
-
def model_params
|
20
|
-
send "#{model_name}_params"
|
21
|
-
end
|
22
|
-
|
23
21
|
def model_var
|
24
22
|
"@#{model_name}"
|
25
23
|
end
|
26
24
|
|
25
|
+
# models related methods
|
26
|
+
|
27
27
|
def models
|
28
28
|
instance_variable_get models_var
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
31
|
+
def models_set(value)
|
32
32
|
instance_variable_set models_var, value
|
33
33
|
end
|
34
34
|
|
@@ -39,5 +39,24 @@ module SimpleCrud
|
|
39
39
|
def models_var
|
40
40
|
"@#{models_name}"
|
41
41
|
end
|
42
|
+
|
43
|
+
def models_path
|
44
|
+
send "#{models_name}_path"
|
45
|
+
end
|
46
|
+
|
47
|
+
# strong parameter methods
|
48
|
+
|
49
|
+
def model_params
|
50
|
+
method = permission_method
|
51
|
+
if respond_to?(method, :include_private)
|
52
|
+
send method
|
53
|
+
else
|
54
|
+
raise ArgumentError, 'Unimplemented permission method'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def permission_method
|
59
|
+
"#{model_name}_params"
|
60
|
+
end
|
42
61
|
end
|
43
62
|
end
|
data/lib/simple_crud/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplecrud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Saenz Tagarro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -46,6 +46,7 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
|
+
- CHANGELOG.md
|
49
50
|
- CODE_OF_CONDUCT.md
|
50
51
|
- Gemfile
|
51
52
|
- LICENSE.txt
|
@@ -54,8 +55,9 @@ files:
|
|
54
55
|
- bin/console
|
55
56
|
- bin/setup
|
56
57
|
- lib/simple_crud.rb
|
57
|
-
- lib/simple_crud/accessors.rb
|
58
58
|
- lib/simple_crud/base_controller.rb
|
59
|
+
- lib/simple_crud/helper/decorator_helper.rb
|
60
|
+
- lib/simple_crud/helper/model_helper.rb
|
59
61
|
- lib/simple_crud/version.rb
|
60
62
|
- simple_crud.gemspec
|
61
63
|
homepage: https://github.com/dsaenztagarro/simplecrud
|
@@ -78,8 +80,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
80
|
version: '0'
|
79
81
|
requirements: []
|
80
82
|
rubyforge_project:
|
81
|
-
rubygems_version: 2.4.
|
83
|
+
rubygems_version: 2.4.8
|
82
84
|
signing_key:
|
83
85
|
specification_version: 4
|
84
86
|
summary: CRUD Rails Controllers made easy
|
85
87
|
test_files: []
|
88
|
+
has_rdoc:
|