cacheable_delegator 1.2.0 → 1.2.1

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Yjc0MjE1Y2JmODg4NDYyYTkxOGZkMjQ0MTQxYmZkOGE3MGY4MDUwNA==
4
+ MjRjYTRkYjIwNmIzYmQ1NTY4OTFlNzIzNDc5ZDJkYWZlYjg5MGJkNA==
5
5
  data.tar.gz: !binary |-
6
- NWI1NTlhMDBmNTY4NDAyNGM4M2VjZmEwMzQyOTI5OGFkYjhlYjcwYw==
6
+ NDVjODg0N2EwYzQzZjliMmU1MmVjYWY3MmVkMGMwYjFkY2E1YzIzNA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- M2ZmOWQyNDQ3Yjg4MjE4YjYyNzFiOGU5ZmI4N2VkOTIzMDk4NjhlOGQ3YzEz
10
- Mjg4M2NlNDZiZmFjZmRhZmMzMGZkOTE2OTllMTAyNjcwMzY5MmVjZTc4MWMw
11
- OWQ3NGY2MGZiYWNjNTAwMDc2MGNmNGYzNTY4NWZiZTQ2ODdjNmQ=
9
+ N2U0MThmYjY5ZGQ5ZmZkYTEyNjJlNWJiZmIxYjc4OTEwZmIxODRhODhhNDBi
10
+ ZGQ2OWU0Y2ZjYTEwNTk4ZGEyNmZkZDdkZjAyZDJjNzU4ZWFiODRkNmQyMTA0
11
+ NjBhMzI3NTc5MzcxZGZhZDU1NzIwNTExZmY0OWM0YTliNjkyYWU=
12
12
  data.tar.gz: !binary |-
13
- MWE1ODZlNjEzMzdiYWRjNWQ4YzcyMzhlM2NjYjMyYmJhNzIwZjY5N2ZlZjBj
14
- ZWM2NTc1NTFjZDUxMTc2Njk3OTE1MDE2ZmVmNTFhYzdmMTJiYjc0MmIzODY5
15
- Mjk2NjFkMTIwODJmNjIzNDQxYzU3YzM4OTcwYjg3NThlMzQ1ZTc=
13
+ ZjZkYzAxZjgyN2RlNjhmOTczNmRlNzI0MTUwMWVkNDAwYThlOTJhYjY2ZjZk
14
+ Mzc0ODIyZjA1YWMzZmFlYmZmMDdlNjU3ODRjMTY5NThlMGZjMTAyZmQxMmI1
15
+ MzEzMzBkOGU2NWQ1OTQxZjZjZmZhMTE0OWRiMDQ2MmY2NWE2MWU=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.2.1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "cacheable_delegator"
8
- s.version = "1.2.0"
8
+ s.version = "1.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dan Nguyen"]
@@ -120,7 +120,7 @@ module CacheableDelegator
120
120
  col_str = col_name.to_s
121
121
  is_bespoke = opts.delete :bespoke
122
122
  if !(self.source_class.method_defined?(col_str) || self.source_class.new.respond_to?(col_str)) && is_bespoke != true
123
- raise ArgumentError, "Since :bespoke != true, instance of #{self.source_class} was expected to respond_to? :#{col_str}"
123
+ raise NonExistentInstanceMethod, "Since :bespoke != true, instance of #{self.source_class} was expected to respond_to? :#{col_str}"
124
124
  end
125
125
 
126
126
  custom_columns[col_name.to_s] = opts
@@ -206,3 +206,5 @@ module CacheableDelegator
206
206
 
207
207
  end
208
208
 
209
+
210
+ class NonExistentInstanceMethod < ArgumentError; end
@@ -47,7 +47,7 @@ describe CacheableDelegator do
47
47
  end
48
48
 
49
49
  it 'by default, should raise error if source_class does not respond_to custom column name' do
50
- expect{ MyCachedRecord.add_custom_column :not_foo_of_record }.to raise_error ArgumentError
50
+ expect{ MyCachedRecord.add_custom_column :not_foo_of_record }.to raise_error NonExistentInstanceMethod
51
51
  end
52
52
 
53
53
 
@@ -81,6 +81,38 @@ describe CacheableDelegator do
81
81
 
82
82
  end
83
83
 
84
+ context 'enforcement of responds_to' do
85
+ it 'should allow adding of columns based on defined instance method' do
86
+ MyCachedRecord.add_custom_column :superfluous_instance_method
87
+ MyCachedRecord.upgrade_schema!
88
+
89
+ expect(MyCachedRecord.column_names.include?('superfluous_instance_method')).to be_true
90
+ end
91
+
92
+ context 'respond_to_missing? works' do
93
+ it 'should allow reference to dynamically defined methods' do
94
+ MyCachedRecord.add_custom_column :dynamic_foo
95
+ MyCachedRecord.upgrade_schema!
96
+
97
+ expect(MyCachedRecord.column_names.include?('dynamic_foo')).to be_true
98
+ end
99
+
100
+ end
101
+
102
+ context 'non-existent' do
103
+ it 'should raise error of undefined instance methods' do
104
+ expect{ MyCachedRecord.add_custom_column :non_existent_method }.to raise_error NonExistentInstanceMethod
105
+ end
106
+
107
+ it 'should not raise error if bespoke is true' do
108
+ MyCachedRecord.add_custom_column :non_existent_method, bespoke: true
109
+ MyCachedRecord.upgrade_schema!
110
+ expect(MyCachedRecord.column_names.include?('non_existent_method')).to be_true
111
+ end
112
+ end
113
+ end
114
+
115
+
84
116
  it 'should allow exclusion of specified columns'
85
117
 
86
118
 
data/spec/spec_records.rb CHANGED
@@ -49,11 +49,35 @@ class MyRecord < ActiveRecord::Base
49
49
  'special foo'
50
50
  end
51
51
 
52
+ def superfluous_instance_method
53
+ 'hello'
54
+ end
52
55
 
53
56
  def foo_array
54
57
  [awesome_value, 'foo!', awesome_value]
55
58
  end
56
59
 
60
+
61
+
62
+ DELEGATING_REGEX ||= /^dynamic_(\w+)/
63
+
64
+ def method_missing(foo, *args, &block)
65
+ if foomatch = foo.to_s.match(DELEGATING_REGEX)
66
+ foo = foomatch[1].to_s
67
+ self.send(foo, *args, &block)
68
+ else
69
+ super
70
+ end
71
+ end
72
+
73
+ def respond_to?(method, f=false)
74
+ method =~ DELEGATING_REGEX || super
75
+ end
76
+
77
+
78
+ def respond_to_missing?(method, *)
79
+ method =~ DELEGATING_REGEX || super
80
+ end
57
81
  end
58
82
 
59
83
  class MyCover < ActiveRecord::Base
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cacheable_delegator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Nguyen