dry_controller 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dry_controller/version.rb +1 -1
- data/lib/dry_controller.rb +7 -3
- metadata +1 -1
data/lib/dry_controller.rb
CHANGED
@@ -15,9 +15,7 @@ module DryController
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
class << self
|
18
|
+
module ClassMethods
|
21
19
|
|
22
20
|
def default_actions(*args)
|
23
21
|
args.each do |meth|
|
@@ -37,9 +35,13 @@ module DryController
|
|
37
35
|
|
38
36
|
def resource_class
|
39
37
|
resource_name.classify.constantize
|
38
|
+
rescue NameError => e
|
39
|
+
return false
|
40
40
|
end
|
41
41
|
|
42
42
|
def resource
|
43
|
+
return unless resource_class
|
44
|
+
|
43
45
|
unless obj = instance_variable_get("@#{resource_name}")
|
44
46
|
obj ||= if params[:id].present?
|
45
47
|
resource_class.where(id: params[:id]).first
|
@@ -59,6 +61,8 @@ module DryController
|
|
59
61
|
end
|
60
62
|
|
61
63
|
def collection
|
64
|
+
return unless resource_class
|
65
|
+
|
62
66
|
unless objects = instance_variable_get("@#{collection_name}")
|
63
67
|
objects = resource_class.all
|
64
68
|
instance_variable_set("@#{collection_name}", objects)
|