auto_demeter 0.0.7 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/README.md +0 -5
- data/auto_demeter.gemspec +1 -2
- data/lib/auto_demeter/methods.rb +11 -8
- data/lib/auto_demeter/version.rb +1 -1
- data/test/auto_demeter_test.rb +2 -0
- metadata +92 -108
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9c478f9df3c1b6f1c7e5b7d9aa38a96362326fdd7acdee6bef3de8817278690d
|
4
|
+
data.tar.gz: '00187a4d4ef1be491625b9709a41824fb385edb7c2aebebefd3de0034afd074a'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 17b1122f3f982ea564a70f9fa9d0bbe02ec8897440b793dd2e8392c897cfea73ae2191dfcd75a04b98e49ce25756bec294fb2f6c7ecf617b05b5f727bfc2fc60
|
7
|
+
data.tar.gz: 5fdc2cec66519a27f264ece2a9be9749e67ca057d69c4ccc398531c1f9770d6f3eed2e659dbfc0c7175fa7d62a487a1d4605e5d3785092f1cae4fa5897500012
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -52,8 +52,3 @@ without having to define manager_name on the association.
|
|
52
52
|
4. Push to the branch (`git push origin my-new-feature`)
|
53
53
|
5. Create new Pull Request
|
54
54
|
|
55
|
-
## Todo
|
56
|
-
|
57
|
-
1. Tests
|
58
|
-
2. More tests around the is and is_not mechanism
|
59
|
-
3. Potentially deprecate the is and is_not mechanism which should really be handled in a different gem.
|
data/auto_demeter.gemspec
CHANGED
@@ -19,15 +19,14 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_development_dependency 'sqlite3'
|
22
|
+
spec.add_development_dependency 'rake', '~> 12.3', '>=12.3.3'
|
22
23
|
|
23
24
|
if RUBY_VERSION >= '1.9'
|
24
25
|
spec.add_development_dependency 'bundler'
|
25
|
-
spec.add_development_dependency 'rake'
|
26
26
|
spec.add_development_dependency 'active_record'
|
27
27
|
spec.add_development_dependency 'simplecov'
|
28
28
|
else
|
29
29
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
30
|
-
spec.add_development_dependency 'rake', '~>0.9.2'
|
31
30
|
spec.add_development_dependency 'activerecord'
|
32
31
|
spec.add_development_dependency 'rcov'
|
33
32
|
end
|
data/lib/auto_demeter/methods.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
module AutoDemeter
|
2
2
|
private
|
3
3
|
def base_names
|
4
|
-
@base_names||=self.class.reflect_on_all_associations.find_all { |x| [:has_one, :belongs_to].include?(x.send(:macro)) }.map { |x| x.send(:name).to_s }
|
4
|
+
@base_names||=self.class.reflect_on_all_associations.find_all { |x| [:has_one, :belongs_to].include?(x.send(:macro)) }.map { |x| x.send(:name).to_s } rescue []
|
5
5
|
end
|
6
6
|
|
7
7
|
def children_names
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
if @children_names.nil?
|
9
|
+
class_name=base_names.map { |x| x.gsub(/^#{self.class.name.underscore}_/, '') }
|
10
|
+
class_name=class_name | base_names.map { |x| x.gsub(/^#{self.base_name.underscore}_/, '') } if self.respond_to?(:base_name) && self.class.name!=self.base_name
|
11
|
+
@children_names=base_names | class_name
|
12
|
+
end
|
13
|
+
@children_names
|
11
14
|
end
|
12
15
|
|
13
16
|
def reflected_children_regex
|
@@ -17,12 +20,12 @@ module AutoDemeter
|
|
17
20
|
public
|
18
21
|
def respond_through_association?(method_id)
|
19
22
|
if children_names && (match_data=method_id.to_s.match(reflected_children_regex)) && match_data[1].present?
|
20
|
-
association_name=self.methods.include?(match_data[1]) ? match_data[1] : "#{self.class.name.underscore}_#{match_data[1]}"
|
23
|
+
association_name=(self.methods.include?(match_data[1].intern) || self.methods.include?(match_data[1])) ? match_data[1] : "#{self.class.name.underscore}_#{match_data[1]}"
|
21
24
|
begin
|
22
25
|
if association=send(association_name)
|
23
26
|
association.respond_to?(match_data[2])
|
24
|
-
|
25
|
-
match_data[2]
|
27
|
+
elsif association.nil?
|
28
|
+
association_name.camelize.constantize.new.respond_to?(match_data[2])
|
26
29
|
end
|
27
30
|
rescue
|
28
31
|
false
|
@@ -46,7 +49,7 @@ module AutoDemeter
|
|
46
49
|
if association=send(association_name)
|
47
50
|
association.send(match_data[2], *args, &block)
|
48
51
|
else
|
49
|
-
|
52
|
+
nil
|
50
53
|
end
|
51
54
|
rescue Exception
|
52
55
|
raise e
|
data/lib/auto_demeter/version.rb
CHANGED
data/test/auto_demeter_test.rb
CHANGED
@@ -74,5 +74,7 @@ end)
|
|
74
74
|
assert_equal @paul.name, @luke_address.user_manager_name
|
75
75
|
assert_equal @paul.name, @luke_address.user_manager.name
|
76
76
|
assert_equal @paul.name, @luke_address.user.manager_name
|
77
|
+
@luke.address=nil
|
78
|
+
assert @luke.respond_to?(:address_postcode)
|
77
79
|
end
|
78
80
|
end
|
metadata
CHANGED
@@ -1,106 +1,100 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_demeter
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 7
|
10
|
-
version: 0.0.7
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.12
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Paul McKibbin
|
14
|
-
autorequire:
|
8
|
+
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2021-04-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: sqlite3
|
22
|
-
|
23
|
-
|
24
|
-
none: false
|
25
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
26
17
|
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
32
20
|
type: :development
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: bundler
|
36
21
|
prerelease: false
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
segments:
|
44
|
-
- 1
|
45
|
-
- 3
|
46
|
-
version: "1.3"
|
47
|
-
type: :development
|
48
|
-
version_requirements: *id002
|
49
|
-
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
50
28
|
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.3'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 12.3.3
|
37
|
+
type: :development
|
51
38
|
prerelease: false
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '12.3'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 12.3.3
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
63
54
|
type: :development
|
64
|
-
version_requirements: *id003
|
65
|
-
- !ruby/object:Gem::Dependency
|
66
|
-
name: activerecord
|
67
55
|
prerelease: false
|
68
|
-
|
69
|
-
|
70
|
-
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: active_record
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
71
65
|
- - ">="
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
segments:
|
75
|
-
- 0
|
76
|
-
version: "0"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
77
68
|
type: :development
|
78
|
-
version_requirements: *id004
|
79
|
-
- !ruby/object:Gem::Dependency
|
80
|
-
name: rcov
|
81
69
|
prerelease: false
|
82
|
-
|
83
|
-
|
84
|
-
requirements:
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
85
72
|
- - ">="
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: simplecov
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
91
82
|
type: :development
|
92
|
-
|
93
|
-
|
94
|
-
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
description: Create automated methods for all children or parents to allow a request
|
90
|
+
to be handled more easily than defining a long chain
|
91
|
+
email:
|
95
92
|
- pmckibbin@gmail.com
|
96
93
|
executables: []
|
97
|
-
|
98
94
|
extensions: []
|
99
|
-
|
100
95
|
extra_rdoc_files: []
|
101
|
-
|
102
|
-
|
103
|
-
- .gitignore
|
96
|
+
files:
|
97
|
+
- ".gitignore"
|
104
98
|
- Gemfile
|
105
99
|
- LICENSE.txt
|
106
100
|
- README.md
|
@@ -110,38 +104,28 @@ files:
|
|
110
104
|
- lib/auto_demeter/methods.rb
|
111
105
|
- lib/auto_demeter/version.rb
|
112
106
|
- test/auto_demeter_test.rb
|
113
|
-
homepage:
|
114
|
-
licenses:
|
107
|
+
homepage: ''
|
108
|
+
licenses:
|
115
109
|
- MIT
|
116
|
-
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
117
112
|
rdoc_options: []
|
118
|
-
|
119
|
-
require_paths:
|
113
|
+
require_paths:
|
120
114
|
- lib
|
121
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
-
|
123
|
-
requirements:
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
124
117
|
- - ">="
|
125
|
-
- !ruby/object:Gem::Version
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
version: "0"
|
130
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
-
none: false
|
132
|
-
requirements:
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
133
122
|
- - ">="
|
134
|
-
- !ruby/object:Gem::Version
|
135
|
-
|
136
|
-
segments:
|
137
|
-
- 0
|
138
|
-
version: "0"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
139
125
|
requirements: []
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
signing_key:
|
144
|
-
specification_version: 3
|
126
|
+
rubygems_version: 3.1.4
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
145
129
|
summary: Automated demeter methods
|
146
|
-
test_files:
|
130
|
+
test_files:
|
147
131
|
- test/auto_demeter_test.rb
|