simplecrud 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e51ecbb8e056b19772256fb49a80ac976feedbd4
4
- data.tar.gz: a33d0d4cb900b9ea5f094d67b807067e581b0dce
3
+ metadata.gz: 4ee8c4571e58e02d7ebff90f2fea6787878b4ab1
4
+ data.tar.gz: b352c35cac42d5a42a74ea194bc1d4546b18fde6
5
5
  SHA512:
6
- metadata.gz: 3489c918382c61d6b77bd63ec030d746a767f7428bd68831feaf7211711335cb0b20e6c2edca1e2279f3d878ad135e24179487328c2061f77155106927516a67
7
- data.tar.gz: ddf1e353bb8d9958bb1ebc24793676a9c4f3ca2c74cda47d88ee083d366371cb8758503b5e3f7253cf71d51f45f5874b76746dc018935725a2b2186b74a7c595
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 'simple_crud'
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 simple_crud
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/[my-github-username]/simple_crud/fork )
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 'accessors'
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 Accessors
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
- models! model_klass.all
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
- model! model_klass.new
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
- model! model_klass.new(model_params)
53
+ model_set model_klass.new(model_params)
51
54
 
52
55
  respond_to do |wants|
53
- if model.save
54
- flash[:notice] = 'model_klass was successfully created.'
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
- if model.update_attributes(params[:model])
69
- flash[:notice] = 'model_klass was successfully updated.'
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(models_url) }
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
- model! model_klass.find(params[:id])
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
@@ -0,0 +1,13 @@
1
+ require 'active_support/concern'
2
+
3
+ module SimpleCrud
4
+ module DecoratorHelper
5
+ extend ActiveSupport::Concern
6
+
7
+ class_methods do
8
+ def decorate_with(method, opts = {})
9
+
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,14 +1,16 @@
1
1
  module SimpleCrud
2
- module Accessors
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 model!(value)
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 models!(value)
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
@@ -1,3 +1,3 @@
1
1
  module SimpleCrud
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
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.0
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-06-07 00:00:00.000000000 Z
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.7
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: