natural_resource 0.1.6 → 0.2.0

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: 4160dd4a90f6e97e0c23fc6a7e9b44f135e11d05
4
- data.tar.gz: da74cd716e9e047331ea9bf69f327b4cc59b6fff
3
+ metadata.gz: 1f70756513dff84d30377ac73a1868d4a2b62b07
4
+ data.tar.gz: 1e3b32e36b2b58c5484354ca7287e4986a915938
5
5
  SHA512:
6
- metadata.gz: b034a650597e61a9359d9838bd3bcf505621cd56c1e44a3d15b4bf9b9910e3230b933e5a9743a0c7a670c5b6011b35e1dd301d64ff9de7f93446797f76a63f95
7
- data.tar.gz: b1d38f50be7708cf95979571eff8aeb80366f3bf392533c1e413eb6160eedc11153f31a02b30b3bb17d4058cda4b52009beb051b9168212f5fffe3e45e4368ae
6
+ metadata.gz: 2cc835adeb493b048ff20840ada36b6782dd98cb745b06ef3b9f8dbe5cc899387977f7cebd25df1726e339c69abdd326387ae266bd7197657cf0d1bb2d15a2c4
7
+ data.tar.gz: 8c9bd2eae9d044a4f305c083efbe11f44374d0c9d3c4d9c4ba24001e6efc10513a2475ca7246e5f3f232099a9ed844c8fea77a38f4e7d1c6aa83098c9717fd62
@@ -10,7 +10,7 @@ module NaturalResource
10
10
  include Pundit
11
11
 
12
12
  class_methods do
13
- def resource(resource_name)
13
+ def resource(resource_name, display_notices: true)
14
14
  after_action :verify_authorized, except: :index
15
15
  after_action :verify_policy_scoped
16
16
 
@@ -30,19 +30,19 @@ module NaturalResource
30
30
  # POST /:controller_name
31
31
  define_method :create do
32
32
  resource.update! resource_params
33
- redirect_to success_path, {notice: "#{resource} was created."}
33
+ success_redirect(:created)
34
34
  end
35
35
 
36
36
  # PUT /:controller_name/:id
37
37
  define_method :update do
38
38
  resource.tap { |r| r.update! resource_params }.touch
39
- redirect_to success_path, {notice: "#{resource} was updated."}
39
+ success_redirect(:updated)
40
40
  end
41
41
 
42
42
  # DELETE /:controller_name/:id
43
43
  define_method :destroy do
44
44
  resource.destroy
45
- redirect_to success_path, {notice: "#{resource} was deleted."}
45
+ success_redirect(:deleted)
46
46
  end
47
47
 
48
48
  private
@@ -79,6 +79,13 @@ module NaturalResource
79
79
  define_method :success_path do
80
80
  url_for(action: :index)
81
81
  end
82
+
83
+ define_method :success_redirect do |action|
84
+ redirect_options = {}
85
+ redirect_options.merge!({notice: "#{resource} was #{action}."}) if display_notices
86
+
87
+ redirect_to success_path, redirect_options
88
+ end
82
89
  end
83
90
  end
84
91
 
@@ -1,3 +1,3 @@
1
1
  module NaturalResource
2
- VERSION = "0.1.6"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: natural_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert White
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-05 00:00:00.000000000 Z
11
+ date: 2016-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails