respond_to_faster 0.1.0 → 0.2.0

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: b424a2e779015c87f2875079a8ec8df721c23ac3
4
- data.tar.gz: d9f71e62dad4f85912e22e4a1cb2922e4e99e3d7
3
+ metadata.gz: 3075ab9a3b42594397ce71908c6a9e324ae8ede6
4
+ data.tar.gz: 59ca831802f576914a254c1cb4fde907833a82c2
5
5
  SHA512:
6
- metadata.gz: 1e83e14ed3105dcdbd3c56279873311db4ae60426c64a21f0a7fd8066785a3ed0111fc2b3ace7556f069583568c4895809cfeb507fff4661c900d429beba16e8
7
- data.tar.gz: e7996d9d301c561e9e64a40cff73e8382eac3919f018f96913111e03a1cebf27ea44d72f34e9439a1c4df4e4afe1e2daef1e72ff1103d42d930e6e4ea6afed22
6
+ metadata.gz: cc1068552d098ce3aca0cafde960b3129f8039df0bbaf1df83bbcb22a4cc8640ca258a2cdb3e627b39d4008dd40f300f795092ffdce67903fa889ef775f42544
7
+ data.tar.gz: 6203af98ff0c87ba8aab51d74b926ae6dbac84a5350c186867352d2a72e81728f2ea1c68fa9394843253c42fdbcfe735b1e717dd72cb1a31d1a3b273d3e643d1
@@ -1,5 +1,12 @@
1
1
  # RespondToFaster Changelog
2
2
 
3
+ ## 0.2
4
+
5
+ ### 0.2.0
6
+ * Override `find_by_sql` instead of `init_with` [3d05c0e](https://github.com/shioyama/respond_to_faster/commit/3d05c0e9b50a07612ec1edf83fae7f0bcea724db)
7
+ * Put back `respond_to?` and `method_missing` for now [7f95710](https://github.com/shioyama/respond_to_faster/commit/7f95710e34f7068ac21fb55202dda0c69cbfcbfa)
8
+ * Handle case of no results [90084dd](https://github.com/shioyama/respond_to_faster/commit/90084ddee0ec25e8052628b563f1c352b742b883)
9
+
3
10
  ## 0.1
4
11
 
5
12
  ### 0.1.0
data/Gemfile CHANGED
@@ -19,5 +19,4 @@ group :development, :test do
19
19
 
20
20
  gem 'benchmark-ips'
21
21
  gem 'sqlite3'
22
- gem 'pry-byebug'
23
22
  end
@@ -1,12 +1,16 @@
1
1
  PATH
2
- remote: .
3
- specs:
4
- respond_to_faster (0.0.1)
5
- activerecord (>= 5.0, < 6.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
2
+ remote: ../../rails
9
3
  specs:
4
+ actioncable (5.2.0.beta2)
5
+ actionpack (= 5.2.0.beta2)
6
+ nio4r (~> 2.0)
7
+ websocket-driver (~> 0.6.1)
8
+ actionmailer (5.2.0.beta2)
9
+ actionpack (= 5.2.0.beta2)
10
+ actionview (= 5.2.0.beta2)
11
+ activejob (= 5.2.0.beta2)
12
+ mail (~> 2.5, >= 2.5.4)
13
+ rails-dom-testing (~> 2.0)
10
14
  actionpack (5.2.0.beta2)
11
15
  actionview (= 5.2.0.beta2)
12
16
  activesupport (= 5.2.0.beta2)
@@ -20,17 +24,52 @@ GEM
20
24
  erubi (~> 1.4)
21
25
  rails-dom-testing (~> 2.0)
22
26
  rails-html-sanitizer (~> 1.0, >= 1.0.3)
27
+ activejob (5.2.0.beta2)
28
+ activesupport (= 5.2.0.beta2)
29
+ globalid (>= 0.3.6)
23
30
  activemodel (5.2.0.beta2)
24
31
  activesupport (= 5.2.0.beta2)
25
32
  activerecord (5.2.0.beta2)
26
33
  activemodel (= 5.2.0.beta2)
27
34
  activesupport (= 5.2.0.beta2)
28
35
  arel (>= 9.0)
36
+ activestorage (5.2.0.beta2)
37
+ actionpack (= 5.2.0.beta2)
38
+ activerecord (= 5.2.0.beta2)
29
39
  activesupport (5.2.0.beta2)
30
40
  concurrent-ruby (~> 1.0, >= 1.0.2)
31
41
  i18n (~> 0.7)
32
42
  minitest (~> 5.1)
33
43
  tzinfo (~> 1.1)
44
+ rails (5.2.0.beta2)
45
+ actioncable (= 5.2.0.beta2)
46
+ actionmailer (= 5.2.0.beta2)
47
+ actionpack (= 5.2.0.beta2)
48
+ actionview (= 5.2.0.beta2)
49
+ activejob (= 5.2.0.beta2)
50
+ activemodel (= 5.2.0.beta2)
51
+ activerecord (= 5.2.0.beta2)
52
+ activestorage (= 5.2.0.beta2)
53
+ activesupport (= 5.2.0.beta2)
54
+ bundler (>= 1.3.0)
55
+ railties (= 5.2.0.beta2)
56
+ sprockets-rails (>= 2.0.0)
57
+ railties (5.2.0.beta2)
58
+ actionpack (= 5.2.0.beta2)
59
+ activesupport (= 5.2.0.beta2)
60
+ method_source
61
+ rake (>= 0.8.7)
62
+ thor (>= 0.18.1, < 2.0)
63
+
64
+ PATH
65
+ remote: .
66
+ specs:
67
+ respond_to_faster (0.1.0)
68
+ activerecord (>= 5.0, < 6.0)
69
+
70
+ GEM
71
+ remote: https://rubygems.org/
72
+ specs:
34
73
  arel (9.0.0)
35
74
  benchmark-ips (2.7.2)
36
75
  builder (3.2.3)
@@ -41,16 +80,42 @@ GEM
41
80
  database_cleaner (1.6.2)
42
81
  diff-lcs (1.3)
43
82
  erubi (1.7.0)
83
+ ffi (1.9.18)
84
+ formatador (0.2.5)
85
+ globalid (0.4.1)
86
+ activesupport (>= 4.2.0)
87
+ guard (2.14.1)
88
+ formatador (>= 0.2.4)
89
+ listen (>= 2.7, < 4.0)
90
+ lumberjack (~> 1.0)
91
+ nenv (~> 0.1)
92
+ notiffany (~> 0.0)
93
+ pry (>= 0.9.12)
94
+ shellany (~> 0.0)
95
+ thor (>= 0.18.1)
44
96
  i18n (0.9.1)
45
97
  concurrent-ruby (~> 1.0)
98
+ listen (3.1.5)
99
+ rb-fsevent (~> 0.9, >= 0.9.4)
100
+ rb-inotify (~> 0.9, >= 0.9.7)
101
+ ruby_dep (~> 1.2)
46
102
  loofah (2.1.1)
47
103
  crass (~> 1.0.2)
48
104
  nokogiri (>= 1.5.9)
105
+ lumberjack (1.0.12)
106
+ mail (2.7.0)
107
+ mini_mime (>= 0.1.1)
49
108
  method_source (0.9.0)
109
+ mini_mime (1.0.0)
50
110
  mini_portile2 (2.3.0)
51
111
  minitest (5.10.3)
112
+ nenv (0.3.0)
113
+ nio4r (2.1.0)
52
114
  nokogiri (1.8.1)
53
115
  mini_portile2 (~> 2.3.0)
116
+ notiffany (0.1.1)
117
+ nenv (~> 0.1)
118
+ shellany (~> 0.0)
54
119
  pry (0.11.3)
55
120
  coderay (~> 1.1.0)
56
121
  method_source (~> 0.9.0)
@@ -65,13 +130,10 @@ GEM
65
130
  nokogiri (>= 1.6)
66
131
  rails-html-sanitizer (1.0.3)
67
132
  loofah (~> 2.0)
68
- railties (5.2.0.beta2)
69
- actionpack (= 5.2.0.beta2)
70
- activesupport (= 5.2.0.beta2)
71
- method_source
72
- rake (>= 0.8.7)
73
- thor (>= 0.18.1, < 2.0)
74
133
  rake (10.5.0)
134
+ rb-fsevent (0.10.2)
135
+ rb-inotify (0.9.10)
136
+ ffi (>= 0.5.0, < 2)
75
137
  rspec (3.7.0)
76
138
  rspec-core (~> 3.7.0)
77
139
  rspec-expectations (~> 3.7.0)
@@ -85,22 +147,34 @@ GEM
85
147
  diff-lcs (>= 1.2.0, < 2.0)
86
148
  rspec-support (~> 3.7.0)
87
149
  rspec-support (3.7.0)
150
+ ruby_dep (1.5.0)
151
+ shellany (0.0.1)
152
+ sprockets (3.7.1)
153
+ concurrent-ruby (~> 1.0)
154
+ rack (> 1, < 3)
155
+ sprockets-rails (3.2.1)
156
+ actionpack (>= 4.0)
157
+ activesupport (>= 4.0)
158
+ sprockets (>= 3.0.0)
88
159
  sqlite3 (1.3.13)
89
160
  thor (0.20.0)
90
161
  thread_safe (0.3.6)
91
162
  tzinfo (1.2.4)
92
163
  thread_safe (~> 0.1)
164
+ websocket-driver (0.6.5)
165
+ websocket-extensions (>= 0.1.0)
166
+ websocket-extensions (0.1.3)
93
167
 
94
168
  PLATFORMS
95
169
  ruby
96
170
 
97
171
  DEPENDENCIES
98
- activerecord (>= 5.2.0.beta2, < 5.3)
99
172
  benchmark-ips
100
173
  bundler (~> 1.16)
101
174
  database_cleaner (~> 1.6)
175
+ guard
102
176
  pry-byebug
103
- railties (>= 5.2.0.beta2, < 5.3)
177
+ rails!
104
178
  rake (~> 10.0)
105
179
  respond_to_faster!
106
180
  rspec (~> 3.0)
data/README.md CHANGED
@@ -17,11 +17,11 @@ queries.
17
17
  Just add the gem to your Gemfile:
18
18
 
19
19
  ```ruby
20
- gem 'respond_to_faster', '~> 0.1.0'
20
+ gem 'respond_to_faster', '~> 0.2.0'
21
21
  ```
22
22
 
23
23
  That's it! Read on to learn about what RespondToFaster is doing under the hood
24
- (or checkout the source code, it's only 20 lines long!)
24
+ (or checkout the source code, it's only a dozen lines long!)
25
25
 
26
26
  ## Background
27
27
 
@@ -79,36 +79,25 @@ alternative.
79
79
 
80
80
  ## What this gem does
81
81
 
82
- So what this gem does is to *remove these overrides*, which have been around
83
- since the dawn of Ruby on Rails. Not just tweak them, or override them, but
84
- **remove them**.
82
+ The reality is that in the vast majority of cases, you don't need this
83
+ `method_missing` override. AR has grown over the years to the point where most
84
+ attribute methods are defined, so these fallbacks are not necessary.
85
85
 
86
- Here is the code that does this, just two lines:
87
-
88
- ```ruby
89
- ActiveModel::AttributeMethods.send(:remove_method, :respond_to?)
90
- ActiveModel::AttributeMethods.send(:remove_method, :method_missing)
91
- ```
92
-
93
- For the vast majority of cases, *this will have no impact on your ActiveRecord
94
- objects*. AR has grown over the years to the point where most attribute methods
95
- are defined, so these fallbacks are not necessary.
96
-
97
- The one exception is the example earlier with the custom aliased query. In this
98
- case, depending on the query, some custom attributes are needed on the objects
99
- returned, and ActiveRecord still relies on this (very slow) mechanism to make
100
- the magic work.
86
+ But there is one case where you do: so-called "virtual columns". This is the
87
+ type of query mentioned at the top of this readme. In this case, depending on
88
+ the query, some custom attributes are needed on the objects returned, and
89
+ ActiveRecord still relies on this (very slow) mechanism to make the magic work.
101
90
 
102
91
  But this is a high price to pay for some simple magic. This gem instead
103
- *defines the methods* on the singleton class of the objects returned, so that
104
- you never need to go to `method_missing`. This makes things **much faster**, as
105
- much as 5-10 times faster.
92
+ *defines the methods* on a module included into the singleton classes of the
93
+ objects returned, so that you never need to go to `method_missing`. This makes
94
+ calling these accessors things significantly faster, as much as 5-10 times
95
+ faster.
106
96
 
107
97
  ## Caveats
108
98
 
109
99
  If you don't use any custom querying with aliases like the one above, this gem
110
- might not do much for you. It should make `respond_to?` a bit faster, but you
111
- may not even notice that.
100
+ will not do much for you.
112
101
 
113
102
  However, if you've got some crazy heavy SQL logic somewhere deep in your
114
103
  application, and you're finding it takes forever, give this gem a shot and tell
@@ -2,22 +2,16 @@ require "active_record"
2
2
  require "respond_to_faster/version"
3
3
 
4
4
  module RespondToFaster
5
- def init_with(coder)
6
- super.tap do
7
- unless (uncached_attrs = attribute_names - self.class.attribute_names).empty?
8
- klass = self.class
9
- mod_name = "RespondToFaster_#{uncached_attrs.hash.abs}".freeze
10
- if klass.const_defined?(mod_name)
11
- singleton_class.include klass.const_get(mod_name)
12
- else
13
- uncached_attrs.each &singleton_class.method(:define_attribute_method)
14
- klass.const_set(mod_name, singleton_class.send(:generated_attribute_methods))
15
- end
5
+ def find_by_sql(sql, binds = [], preparable: nil, &block)
6
+ super.tap do |records|
7
+ record = records.first
8
+ unless record.nil? || (uncached_attrs = record.attribute_names - attribute_names).empty?
9
+ uncached_attrs.each &record.singleton_class.method(:define_method_attribute)
10
+ mod = record.singleton_class.send(:generated_attribute_methods)
11
+ records[1..-1].each { |record| record.singleton_class.include mod }
16
12
  end
17
13
  end
18
14
  end
19
15
  end
20
16
 
21
- ActiveRecord::Base.include RespondToFaster
22
- ActiveModel::AttributeMethods.send(:remove_method, :respond_to?)
23
- ActiveModel::AttributeMethods.send(:remove_method, :method_missing)
17
+ ActiveRecord::Base.extend RespondToFaster
@@ -1,3 +1,3 @@
1
1
  module RespondToFaster
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: respond_to_faster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Salzberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-19 00:00:00.000000000 Z
11
+ date: 2017-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.6.13
126
+ rubygems_version: 2.6.14
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: Faster response times for your ActiveRecord attribute methods.