invisible_controller 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/invisible_controller/base.rb +15 -3
- data/lib/invisible_controller/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94051ab670e25620fd2a2ca240eb7f9a9f0e7ea9
|
4
|
+
data.tar.gz: 30c18a94ac2f8747e6862a25fec44461e3065e89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d245741469f9b6073eb8b8f34e59b15da63fd0dd6285dea6120c40736f2ae4b99864c1482b01ad27e512c16d0858e20c781d14fb16cbd90da410f1b554283ab
|
7
|
+
data.tar.gz: 6a202b8eda9a86603caa47153e4a0cb4db7ba8aa5baff67ef1aef3b1930d7ebd7eb86881217eea80fa52b83556b32fffce0bd7ae5ab418caba62c1df3a1dc3cc
|
@@ -72,10 +72,20 @@ module InvisibleController
|
|
72
72
|
#belongs_to Functionality
|
73
73
|
def nested?() parent_name.split('.')[0].singularize != resource_name.singularize end
|
74
74
|
def parent_name() request.path.split('/')[1].singularize end
|
75
|
+
def has_one?
|
76
|
+
return false unless parent_resource
|
77
|
+
parent_resource.class.reflect_on_association(resource_name.singularize).present?
|
78
|
+
end
|
75
79
|
|
76
|
-
def parent_resource() @parent_resource ||= parent_name.classify.constantize.find(parent_id) end
|
80
|
+
def parent_resource() @parent_resource ||= parent_id.present? ? parent_name.classify.constantize.find(parent_id) : nil end
|
77
81
|
def parent_id() params["#{parent_name}_id"] end
|
78
|
-
def active_class()
|
82
|
+
def active_class()
|
83
|
+
if nested?
|
84
|
+
return has_one? ? parent_resource : parent_resource.send(nested_name || resource_name.pluralize)
|
85
|
+
else
|
86
|
+
return klass
|
87
|
+
end
|
88
|
+
end
|
79
89
|
def scoped() ((params.keys || []) & (self.class.instance_variable_get("@scopes") || []))[0] end
|
80
90
|
def current_scope() scoped || :all end
|
81
91
|
def scope_args() params[current_scope] end
|
@@ -88,7 +98,9 @@ module InvisibleController
|
|
88
98
|
return active_class.new(processed_params) if new? || create?
|
89
99
|
define_singleton_resource
|
90
100
|
end
|
91
|
-
def define_singleton_resource()
|
101
|
+
def define_singleton_resource()
|
102
|
+
has_one? ? active_class.send(resource_name) : active_class.find(params[:id])
|
103
|
+
end
|
92
104
|
def klass() resource_name.classify.constantize rescue Class end
|
93
105
|
def permitted_params() params.permit( resource_name.to_sym => (@resource || klass).whitelisted ) end
|
94
106
|
def processed_params() permitted_params[resource_name] end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: invisible_controller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Moody
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|