effective_resources 0.3.1 → 0.3.2

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
  SHA1:
3
- metadata.gz: 488cbf22654ca463eac33ddf0959d478c99326f4
4
- data.tar.gz: 02805f17044dd8e11c008e4167c8952944ff55da
3
+ metadata.gz: 0c8221988f03d56ff83b0119d534ec05cc4da24b
4
+ data.tar.gz: 90b6ac23aec80640c67a189c389c397d5490562f
5
5
  SHA512:
6
- metadata.gz: 26985ddc593f52bec5d528ee17d81460e9b199e8298ae44d7890333fdde845f68ce5068accc83cbc6d8e1611da08560afb404e1ab65482f4950326d17c6a9c13
7
- data.tar.gz: 5d1253caca41eb0eb6407110b0c104cc7c8bd26d56f8537b4e3f8c6af52e8100dc09e73471e74c425baae44f6832494d1221740ff9b5f8372e2647d0588845d9
6
+ metadata.gz: f8a1bb0a89920994001dc31e28626c79c6ca34909c29d4d52a6b8b87edddf2c4a500982c70e5652643081a447b72daa81f2124adb38e8bf978ee95843e42d367
7
+ data.tar.gz: 878d4fb2251e0ce4ce0160dc7913e263123b71593a60b796d973443d8f7068b39e127ee96e7326465e80154b2f53d485e5b7e77839eb6c18df7d7c15e8571a2b
@@ -31,9 +31,6 @@ module Effective
31
31
  @nested_resources ||= klass.reflect_on_all_associations(:has_many).select { |ass| ass.options[:autosave] && ass.options[:class_name] != 'Effective::Attachment' }
32
32
  end
33
33
 
34
- def scopes
35
- end
36
-
37
34
  def associated(name)
38
35
  name = (name.to_s.end_with?('_id') ? name.to_s[0...-3] : name).to_sym
39
36
  klass.reflect_on_all_associations.find { |ass| ass.name == name }
@@ -6,6 +6,8 @@ module Effective
6
6
 
7
7
  def _initialize(obj)
8
8
  @input_name = _initialize_input_name(obj)
9
+ _initialize_names(@input_name)
10
+
9
11
  @relation = _initialize_relation(obj)
10
12
  @instance = obj if (klass && obj.instance_of?(klass))
11
13
  end
@@ -27,6 +29,20 @@ module Effective
27
29
  end.to_s.underscore
28
30
  end
29
31
 
32
+ def _initialize_names(input)
33
+ names = input.split('/')
34
+
35
+ 0.upto(names.length-1) do |index|
36
+ class_name = (names[index..-1].map { |name| name.classify } * '::')
37
+
38
+ if (@model_klass = class_name.safe_constantize).present?
39
+ @class_name = class_name
40
+ @namespaces = names[0...index]
41
+ break
42
+ end
43
+ end
44
+ end
45
+
30
46
  def _initialize_relation(input)
31
47
  return nil unless klass && klass.respond_to?(:where)
32
48
 
@@ -12,7 +12,7 @@ module Effective
12
12
  end
13
13
 
14
14
  def class_name # 'Effective::Post'
15
- @class_name ||= (@input_name.split(SPLIT) - namespaces).map { |name| name.classify } * '::'
15
+ @class_name
16
16
  end
17
17
 
18
18
  def class_path # 'effective'
@@ -24,11 +24,11 @@ module Effective
24
24
  end
25
25
 
26
26
  def namespace # 'admin/things'
27
- @namespace ||= (namespaces.join('/') if namespaces.present?)
27
+ (namespaces.join('/') if namespaces.present?)
28
28
  end
29
29
 
30
30
  def namespaces # ['admin', 'things']
31
- @namespaces ||= @input_name.split('/')[0...-1]
31
+ @namespaces
32
32
  end
33
33
 
34
34
  def human_name
@@ -48,8 +48,6 @@ module Effective
48
48
  :has_many
49
49
  elsif has_one(name)
50
50
  :has_one
51
- elsif name.end_with?('_address') && defined?(EffectiveAddresses) && instance.respond_to?(:effective_addresses)
52
- :effective_addresses
53
51
  elsif name == 'id' && defined?(EffectiveObfuscation) && klass.respond_to?(:deobfuscate)
54
52
  :effective_obfuscation
55
53
  elsif name == 'roles' && defined?(EffectiveRoles) && klass.respond_to?(:with_role)
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '0.3.1'.freeze
2
+ VERSION = '0.3.2'.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: 0.3.1
4
+ version: 0.3.2
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: 2017-03-27 00:00:00.000000000 Z
11
+ date: 2017-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails