load_resources 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +17 -3
- data/lib/load_resources/version.rb +1 -1
- data/lib/load_resources.rb +65 -26
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a01fda3fb1c32b4134da3536cbe4bf69453bcfaa
|
4
|
+
data.tar.gz: 374cfe9390e363e49072248b18aa1d208f2dc9c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b66151e0becfae73a78a2031709d9a41efcd95180737a47a35b3bf376313ed0bcdbeddb48c355a508e6f6c807dc37d067d02af975ee88d1089227970e84825ee
|
7
|
+
data.tar.gz: 7dc5626057f9f8ede759cbd381a9c9f8c9af732dc986e4a1f18987a11c47d65da96f110001e98b66ffd82aa8bf24c5ba3f9369ff2a4dcc8e49a20a718cfdcad1
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# LoadResources
|
2
2
|
|
3
|
-
TODO: Write a gem description
|
4
|
-
|
5
3
|
## Installation
|
6
4
|
|
7
5
|
Add this line to your application's Gemfile:
|
@@ -19,8 +17,24 @@ Or install it yourself as:
|
|
19
17
|
$ gem install load_resources
|
20
18
|
|
21
19
|
## Usage
|
20
|
+
Include load resources in controller
|
21
|
+
include LoadResources
|
22
|
+
|
23
|
+
for all crud actions
|
24
|
+
|
25
|
+
automatic_resource :user
|
26
|
+
|
27
|
+
for specify actions
|
28
|
+
automatic_resource :resource_name, only: [:new, :create]
|
29
|
+
automatic_resource :resource_name, except: [:new, :create]
|
30
|
+
|
31
|
+
|
32
|
+
TODO
|
33
|
+
for non crud actions.
|
34
|
+
|
35
|
+
automatic_resource :resource_name, only: [:nova_action], options: [:new, :all, :find ou find: {key: find_id}, conditions: {name: 'seila'} ]
|
36
|
+
automatic_resource [:resource_name, :resource_name2], only: [:nova_action], options: [:new, :all, :find ou find: {key: find_id}, conditions: {name: 'seila'} ]
|
22
37
|
|
23
|
-
TODO: Write usage instructions here
|
24
38
|
|
25
39
|
## Contributing
|
26
40
|
|
data/lib/load_resources.rb
CHANGED
@@ -2,45 +2,84 @@ require "load_resources/version"
|
|
2
2
|
|
3
3
|
module LoadResources
|
4
4
|
extend ActiveSupport::Concern
|
5
|
+
include ActiveSupport::Callbacks
|
5
6
|
|
6
|
-
included
|
7
|
-
|
8
|
-
before_action :new_resource, only: [:new, :create]
|
9
|
-
before_action :load_resources, only: :index
|
7
|
+
def self.included(base)
|
8
|
+
base.extend ClassMethods
|
10
9
|
end
|
11
10
|
|
12
|
-
|
11
|
+
module ClassMethods
|
12
|
+
def automatic_resource(resource_name, actions = nil, class_name = nil)
|
13
|
+
actions ||= default_actions
|
14
|
+
new_resource_callback(resource_name, actions)
|
15
|
+
collection_resource_callback(resource_name, actions)
|
16
|
+
single_resource_callback(resource_name, actions)
|
17
|
+
end
|
13
18
|
|
14
|
-
|
19
|
+
def collection_resource_callback(resource_name, actions)
|
20
|
+
collection_actions = (actions & collection_resource_actions)
|
21
|
+
if collection_actions.present?
|
22
|
+
before_action(only: collection_actions) do
|
23
|
+
load_resources(resource_name)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def new_resource_callback(resource_name, actions)
|
29
|
+
new_instance_actions = (actions & new_resource_actions)
|
30
|
+
if new_instance_actions.present?
|
31
|
+
before_action(only: new_instance_actions) do
|
32
|
+
new_resource(resource_name)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def single_resource_callback(resource_name, actions)
|
38
|
+
single_actions = (actions & single_resource_actions)
|
39
|
+
if single_actions.present?
|
40
|
+
before_action(only: single_actions) do
|
41
|
+
load_resource(resource_name)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def single_resource_actions
|
49
|
+
[:show, :edit, :destroy, :update]
|
50
|
+
end
|
15
51
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
# automatic_resource :crud,
|
20
|
-
# poder especificar o tipo do resource se é um new, um find simples, all, ou a conditions
|
21
|
-
# automatic_resource :resource_name, only: [:nova_action], options: [:new, :all, :find ou find: {key: find_id}, conditions: {name: 'seila'} ]
|
22
|
-
# automatic_resource [:resource_name, :resource_name2], only: [:nova_action], options: [:new, :all, :find ou find: {key: find_id}, conditions: {name: 'seila'} ]
|
52
|
+
def new_resource_actions
|
53
|
+
[:new, :create]
|
54
|
+
end
|
23
55
|
|
24
|
-
|
25
|
-
|
56
|
+
def collection_resource_actions
|
57
|
+
[:index]
|
58
|
+
end
|
59
|
+
|
60
|
+
def default_actions
|
61
|
+
[:index, :new, :edit, :create, :update, :destroy]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def variable_name(resource_name)
|
66
|
+
("@#{resource_name.to_s}")
|
26
67
|
end
|
27
68
|
|
28
|
-
def
|
29
|
-
|
30
|
-
instance_variable_set resource_instance_name, resource_class.new
|
69
|
+
def load_resources(resource_name)
|
70
|
+
instance_variable_set variable_name(resource_name), resource_class(resource_name).all
|
31
71
|
end
|
32
72
|
|
33
|
-
def
|
34
|
-
|
35
|
-
instance_variable_set resource_instance_name,
|
36
|
-
clazz.find_by(id: params[:id])
|
73
|
+
def new_resource(resource_name)
|
74
|
+
instance_variable_set variable_name(resource_name), resource_class(resource_name).new
|
37
75
|
end
|
38
76
|
|
39
|
-
def
|
40
|
-
|
77
|
+
def load_resource(resource_name)
|
78
|
+
instance_variable_set variable_name(resource_name), resource_class(resource_name).find_by(id: params[:id])
|
41
79
|
end
|
42
80
|
|
43
|
-
def resource_class
|
44
|
-
Object.const_get(
|
81
|
+
def resource_class(resource_name)
|
82
|
+
Object.const_get(resource_name.to_s.classify)
|
45
83
|
end
|
84
|
+
|
46
85
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: load_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Renan Oronfle
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
G/deCkh3WDUtBeEKSz3F0EeN+83rUs3YsHC8BLBWYijdvcBPipD8GZgTqnKW9aSY
|
31
31
|
h+9WLcjUsXPxXVT9F0v/eS3W3q334RUrEpGGbTFJyt+W4K+t
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2016-02-
|
33
|
+
date: 2016-02-19 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: bundler
|
metadata.gz.sig
CHANGED
Binary file
|