zobi 4.0.2 → 5.0.0.beta1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f51cb3ce3c2c79ea07404701681a4af63673814
4
- data.tar.gz: 7de5688023e861d0ac5f049ad8358e6f29ff276f
3
+ metadata.gz: e7041240f181625bb66d7c362635be76947693f8
4
+ data.tar.gz: 3cde43da32739b1140bbc15c554e6e3e25798d02
5
5
  SHA512:
6
- metadata.gz: 9c75084d6080751307ac85ccc446f6f7efcce7995b99093d8d9404caff51e51547ef5e44b1726b662d4a64bdbcef5398dd64bce2a78e94df911b9bf70c76d966
7
- data.tar.gz: 8776ace9dab152adb558e87d4d7114a4aafdd3500e556b75d64136d7383577e54dcb0252f1e580184989261049fd1e914db69d7a79c58855889f05c07a421ff2
6
+ metadata.gz: 5bedfd22dd1f6542f7e6a8ada8fb2913c741401178c64f5c79ed75707d53a1f105b0ddf9b032b7c714c53db400074cab740bb761673419c333f46c7c8b054beb
7
+ data.tar.gz: ad2c3746ba5295d0deb6e64bf2dbcb3957226091a1dc1cc62119a519d9f0d0720cc0d812d4e7726bf137ca7b34d122b117dacd2aaa493027a5c606f85909a9ee
data/README.md CHANGED
@@ -5,7 +5,6 @@ Zobi
5
5
  Zobi helps you to orchestrate your controller behaviors using the following gems :
6
6
 
7
7
  - [**devise**](https://github.com/plataformatec/devise)
8
- - [**inherited_resources**](https://github.com/josevalim/inherited_resources)
9
8
  - [**has_scope**](https://github.com/plataformatec/has_scope)
10
9
  - [**kaminari**](https://github.com/amatsuda/kaminari)
11
10
  - [**pundit**](https://github.com/elabs/pundit)
@@ -17,7 +16,7 @@ How to use it?
17
16
  Add it in your `Gemfile` and run `bundle install`:
18
17
 
19
18
  ```ruby
20
- gem 'zobi', '~> 4.0.1'
19
+ gem 'zobi', '~> 4.0.2'
21
20
  ```
22
21
 
23
22
  Next, include Zobi module in your controller and set modules you want to
@@ -33,20 +32,26 @@ Available modules
33
32
 
34
33
  ### Inherited
35
34
 
36
- This module uses
37
- [inherited_resources](https://github.com/josevalim/inherited_resources) gem
38
- (for version >= 1.4.0).
35
+ This module historically use
36
+ [inherited_resources](https://github.com/josevalim/inherited_resources) gem, which is now deprecated.
39
37
 
40
- This module deals with String Parameters using Parameters classes.
41
-
42
- A Parameters inherits from Zobi::ParametersSanitizer, and should define the list
43
- of parameters and nested parameters to accept.
38
+ Now it only defines create/update/destroy methods to easily build CRUD backend.
44
39
 
45
40
  If your controller is namespaced, you should define the `resource_type` method to
46
41
  override its generic behavior.
47
42
 
48
- If your model is namespaced, you should define the defaults resource_class for
49
- Inherited Resource, ie : `defaults resource_class: ::User::Address`
43
+ If your model is namespaced, you should define the defaults resource_class:
44
+
45
+ ```
46
+ def resource_class
47
+ ::User::Address`
48
+ end
49
+ ```
50
+
51
+ This module also deals with Strong Parameters using Parameters classes.
52
+
53
+ A Parameters inherits from Zobi::ParametersSanitizer, and should define the list
54
+ of parameters and nested parameters to accept.
50
55
 
51
56
  Here is an example :
52
57
 
data/lib/zobi.rb CHANGED
@@ -6,7 +6,8 @@ module Zobi
6
6
  BEHAVIORS = [:inherited, :scoped, :included, :paginated, :controlled_access, :decorated].freeze
7
7
 
8
8
  def self.extended base
9
- base.helper_method :collection, :resource
9
+ base.helper_method :collection, :resource, :resource_class,
10
+ :collection_path, :new_resource_path, :edit_resource_path, :resource_path
10
11
  end
11
12
 
12
13
  def behaviors *behaviors
@@ -27,9 +28,19 @@ module Zobi
27
28
  module InstanceMethods
28
29
 
29
30
  def zobi_resource_class
30
- return resource_class if self.class.behavior_included?(:inherited)
31
- self.class.name.demodulize.gsub('Controller', '').singularize.constantize
31
+ @_zobi_resource_class ||= zobi_resource_name.classify.constantize
32
32
  end
33
+ alias_method :resource_class, :zobi_resource_class
34
+
35
+ def zobi_resource_name
36
+ @_zobi_resource_name ||= self.class.to_s.demodulize.gsub(/Controller$/, '').singularize
37
+ end
38
+ alias_method :resource_name, :zobi_resource_name
39
+
40
+ def zobi_resource_key
41
+ @_zobi_resource_key ||= zobi_resource_name.underscore
42
+ end
43
+ alias_method :resource_key, :zobi_resource_key
33
44
 
34
45
  def collection
35
46
  return @collection if @collection
@@ -41,5 +52,20 @@ module Zobi
41
52
  @collection = (c.is_a?(Class) ? c.all : c)
42
53
  end
43
54
 
55
+ def collection_path
56
+ url_for controller: zobi_resource_key.pluralize, action: :index
57
+ end
58
+
59
+ def new_resource_path
60
+ url_for controller: zobi_resource_key.pluralize, action: :new
61
+ end
62
+
63
+ def edit_resource_path r
64
+ url_for controller: zobi_resource_key.pluralize, action: :edit, id: r.id
65
+ end
66
+
67
+ def resource_path r
68
+ url_for controller: zobi_resource_key.pluralize, action: :show, id: r.id
69
+ end
44
70
  end
45
71
  end
@@ -8,7 +8,7 @@ module Zobi
8
8
  def self.included base
9
9
  base.send :include, Pundit
10
10
  base.class_eval do
11
- before_filter :authorize_resource
11
+ before_action :authorize_resource
12
12
 
13
13
  def policy_scope scope
14
14
  Pundit.policy_scope!(controlled_access_user, scope)
@@ -8,14 +8,56 @@ module Zobi
8
8
  #
9
9
  module Inherited
10
10
  def self.included(klass)
11
- klass.inherit_resources
12
- klass.send('include', Inherited::Hidden)
11
+ klass.send 'include', Inherited::Hidden
12
+ klass.send 'respond_to', :html
13
+ end
14
+
15
+ def create
16
+ r = zobi_resource_class.create permitted_params[zobi_resource_key]
17
+ instance_variable_set "@#{resource_key}", r
18
+ args = route_namespace
19
+ args << r
20
+ block_given? ? yield(r) : respond_with(*args)
21
+ end
22
+ alias_method :create!, :create
23
+
24
+ def update
25
+ resource.update_attributes permitted_params[zobi_resource_key]
26
+ args = route_namespace
27
+ args << resource
28
+ block_given? ? yield(resource) : respond_with(*args)
29
+ end
30
+ alias_method :update!, :update
31
+
32
+ def destroy
33
+ resource.destroy
34
+ block_given? ? yield(resource) : redirect_to(collection_path)
35
+ end
36
+ alias_method :destroy!, :destroy
37
+
38
+ protected
39
+
40
+ def resource
41
+ r = instance_variable_get "@#{resource_key}"
42
+ return r if r.present?
43
+ instance_variable_set(
44
+ "@#{resource_key}",
45
+ (params[:id].present? ?
46
+ resource_class.find(params[:id]) :
47
+ resource_class.new
48
+ )
49
+ )
50
+ return instance_variable_get "@#{resource_key}"
51
+ end
52
+
53
+ def route_namespace
54
+ self.class.name.split('::')[0...-1].map(&:downcase)
13
55
  end
14
56
 
15
57
  private
16
58
 
17
59
  def inherited_collection c
18
- end_of_association_chain
60
+ c
19
61
  end
20
62
 
21
63
  module Hidden
data/lib/zobi/scoped.rb CHANGED
@@ -6,7 +6,7 @@ module Zobi
6
6
  module Scoped
7
7
  def self.included(klass)
8
8
  klass.helper_method :filters_list
9
- klass.before_filter :default_order
9
+ klass.before_action :default_order
10
10
  end
11
11
 
12
12
  protected
data/lib/zobi/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Zobi
3
- VERSION = "4.0.2"
3
+ VERSION = "5.0.0.beta1"
4
4
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zobi
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.2
4
+ version: 5.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - klacointe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-29 00:00:00.000000000 Z
11
+ date: 2016-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.0'
83
- - !ruby/object:Gem::Dependency
84
- name: inherited_resources
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '1.4'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '1.4'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: has_scope
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -220,8 +206,8 @@ dependencies:
220
206
  - - "~>"
221
207
  - !ruby/object:Gem::Version
222
208
  version: '1.1'
223
- description: Keep your rails controllers DRY while using devise, inherited_resources,
224
- has_scope, kaminari, pundit and draper
209
+ description: Keep your rails controllers DRY while using devise, has_scope, kaminari,
210
+ pundit and draper
225
211
  email: kevinlacointe@gmail.com
226
212
  executables: []
227
213
  extensions: []
@@ -242,7 +228,7 @@ files:
242
228
  - lib/zobi/responders/pagination_responder.rb
243
229
  - lib/zobi/scoped.rb
244
230
  - lib/zobi/version.rb
245
- homepage: https://github.com/af83/zobi
231
+ homepage: https://github.com/klacointe/zobi
246
232
  licenses:
247
233
  - MIT
248
234
  metadata: {}
@@ -257,12 +243,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
257
243
  version: '0'
258
244
  required_rubygems_version: !ruby/object:Gem::Requirement
259
245
  requirements:
260
- - - ">="
246
+ - - ">"
261
247
  - !ruby/object:Gem::Version
262
- version: '0'
248
+ version: 1.3.1
263
249
  requirements: []
264
250
  rubyforge_project:
265
- rubygems_version: 2.2.2
251
+ rubygems_version: 2.5.1
266
252
  signing_key:
267
253
  specification_version: 4
268
254
  summary: Keep your rails controllers DRY.