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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da3fccf529bfb396a0869dd0d2a2dbb8363fdacb
4
- data.tar.gz: 3687b1b6c7260ce2721a1402360382fda31446ff
3
+ metadata.gz: 94051ab670e25620fd2a2ca240eb7f9a9f0e7ea9
4
+ data.tar.gz: 30c18a94ac2f8747e6862a25fec44461e3065e89
5
5
  SHA512:
6
- metadata.gz: 75f1c4776e997f00b615fa285edfffe54e8cd306291344b07d685558adda3c3f2c9445724e5b68baa957959cb4c41873f623c70656751e4e1427a62ce5cb88f6
7
- data.tar.gz: 087cdc8c1bbf11fd397b36150a073dab0edbc282adc2711227e97f1a67fae381fce0ca954e528c1240ffb0d7261e27513aafda836a1484a00a34215b2abb82d3
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() nested? ? parent_resource.send(nested_name || resource_name.pluralize) : klass end
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() active_class.find(params[:id]) end
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
@@ -1,3 +1,3 @@
1
1
  module InvisibleController
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  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.1
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-09-30 00:00:00.000000000 Z
11
+ date: 2016-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails