effective_resources 1.8.6 → 1.8.7

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
  SHA256:
3
- metadata.gz: 3054f246623c2920a43e74b98bdb52aa03501ca936da01036523ac76e6f35049
4
- data.tar.gz: 2121fdfa7914e4b0c4c516a26d030f6ff3c1bda0d60ff54a5f683fe0c4280c51
3
+ metadata.gz: 79cab109b01cb0133d18f3530e8ed872c183c8e637c8279da87bbd068ddbee21
4
+ data.tar.gz: 20e8cb596ab2181fde595dc430c2e57fa1396b7d91490827d496e20438f59575
5
5
  SHA512:
6
- metadata.gz: c714c8640357cbb5c52aeca16a5cef0a6e0caf9eafe1a54cccf8c9aee79f27afb65ae022a8512c4297c379b96b9dc9c98275345709a24591aa8b1544051d64fc
7
- data.tar.gz: be065c497d1b2b664b9d82dedf8fa2e3fd77bc25f89b06d51a1841ce9069fdd41e933d681cf11a66a2f76d2846c09b9f1c2353e75d88c69d48d8df0cbdacde27
6
+ metadata.gz: b4ed96cdaf9a6fb68f51b3328fde6b38151f595f09e94fbc8943f034d0de2a9ae48a959f07c050fc77a8bfcaa8d1b6be0f671e7d23e762de51771cc58a6c8779
7
+ data.tar.gz: feaa6d1027ba1b6315a922b400feab502bc1f96e545092e4d9f9284f9cd935e80e918dd2b2e93fb5b0f2391b59978aaa908c1663ec112d10c9bd3cde819c830b
@@ -11,7 +11,6 @@ module Effective
11
11
  include Effective::CrudController::Submits
12
12
 
13
13
  included do
14
- define_actions_from_routes
15
14
  define_callbacks :resource_render, :resource_before_save, :resource_after_save, :resource_after_commit, :resource_error
16
15
  layout -> { resource_layout }
17
16
  end
@@ -19,22 +18,11 @@ module Effective
19
18
  module ClassMethods
20
19
  include Effective::CrudController::Dsl
21
20
 
22
- # This is used to define_actions_from_routes and for the buttons/submits/ons
21
+ # This is used for the buttons/submits/ons
23
22
  # It doesn't really work with the resource_scope correctly but the routes are important here
24
23
  def effective_resource
25
24
  @_effective_resource ||= Effective::Resource.new(controller_path)
26
25
  end
27
-
28
- # Automatically respond to any action defined via the routes file
29
- def define_actions_from_routes
30
- (effective_resource.member_actions - effective_resource.crud_actions).each do |action|
31
- define_method(action) { member_action(action) }
32
- end
33
-
34
- (effective_resource.collection_actions - effective_resource.crud_actions).each do |action|
35
- define_method(action) { collection_action(action) }
36
- end
37
- end
38
26
  end
39
27
 
40
28
  def resource # @thing
@@ -53,7 +41,7 @@ module Effective
53
41
  send(:instance_variable_set, "@#{resource_plural_name}", instance)
54
42
  end
55
43
 
56
- def effective_resource
44
+ def effective_resource(safe: false)
57
45
  @_effective_resource ||= begin
58
46
  relation = instance_exec(&resource_scope_relation) if respond_to?(:resource_scope_relation)
59
47
 
@@ -64,11 +52,28 @@ module Effective
64
52
  resource = Effective::Resource.new(controller_path, relation: relation)
65
53
 
66
54
  unless resource.relation.kind_of?(ActiveRecord::Relation) || resource.active_model?
67
- raise("unable to build resource_scope for #{resource.klass || 'unknown klass'}. Please name your controller to match an existing model, or manually define a resource_scope.")
55
+ raise("unable to build resource_scope for #{resource.klass || 'unknown klass'}. Please name your controller to match an existing model, or manually define a resource_scope.") unless safe
56
+ else
57
+ resource
68
58
  end
59
+ end
60
+ end
61
+
62
+ def action_missing(action, *args, &block)
63
+ effective_resource = self.effective_resource(safe: true)
64
+ return super if effective_resource.blank?
65
+
66
+ action = action.to_sym
69
67
 
70
- resource
68
+ if effective_resource.member_actions.include?(action)
69
+ return member_action(action)
71
70
  end
71
+
72
+ if effective_resource.collection_actions.include?(action)
73
+ return collection_action(action)
74
+ end
75
+
76
+ super
72
77
  end
73
78
 
74
79
  private
@@ -7,7 +7,7 @@ module EffectiveGem
7
7
  raise("expected self.config_keys method") unless respond_to?(:config_keys)
8
8
 
9
9
  config_keys.each do |key|
10
- self.class.define_method(key) { config()[key] }
10
+ self.singleton_class.define_method(key) { config()[key] }
11
11
  end
12
12
  end
13
13
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.8.6'.freeze
2
+ VERSION = '1.8.7'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.6
4
+ version: 1.8.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-11 00:00:00.000000000 Z
11
+ date: 2021-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails