find_as_hashes 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 80e69ce59791677832699286e87e673a6e51b11e
4
+ data.tar.gz: c707a4fc1f7825d27e47df7cd09d70fb7455ef19
5
+ SHA512:
6
+ metadata.gz: c6f24e484e55bddcda944a9c6a4167eab36544f8d37a0681df573deff5ae56e26cfce61b042423c4cf943c8c9e2b2ecdb3be475b0f157914022cc552ce20f662
7
+ data.tar.gz: 4c7863791ad209c7af7ca2b456ae3e391dd18a22af612b4d15fd9fee1cd71f283787d18140484ba0981056b5c963c2cddd514316e7adbe49475b5e7de987cd74
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  *.gem
2
2
  .bundle
3
3
  pkg/*
4
+ gemfiles/*.gemfile.lock
data/.travis.yml CHANGED
@@ -1,9 +1,30 @@
1
1
  rvm:
2
- - 1.8.7
3
2
  - 1.9.2
4
3
  - 1.9.3
5
- - ree
4
+ - 2.1.2
6
5
  - ruby-head
6
+
7
+ env:
8
+ - "RAILS_VERSION=3.1"
9
+ - "RAILS_VERSION=4.0"
10
+
11
+ gemfile:
12
+ - gemfiles/rails_3.gemfile
13
+ - gemfiles/rails_4.gemfile
14
+
15
+ matrix:
16
+ exclude:
17
+ - rvm: 1.9.2
18
+ env: "RAILS_VERSION=4.0"
19
+ - rvm: 1.9.2
20
+ gemfile: gemfiles/rails_4.gemfile
21
+ - rvm: 2.1.2
22
+ env: "RAILS_VERSION=3.1"
23
+ - rvm: 2.1.2
24
+ gemfile: gemfiles/rails_3.gemfile
25
+ allow_failures:
26
+ - rvm: ruby-head
27
+
7
28
  notifications:
8
29
  # overriding this so that TST Media's email account doesn't get spammed
9
30
  # feel free to add yourselves if you want in on this action
data/Appraisals ADDED
@@ -0,0 +1,7 @@
1
+ appraise "rails-3" do
2
+ gem "rails", "3.1.0"
3
+ end
4
+
5
+ appraise "rails-4" do
6
+ gem "rails", "4.0.0"
7
+ end
data/Gemfile.lock CHANGED
@@ -1,40 +1,58 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- find_as_hashes (0.4.0)
4
+ find_as_hashes (0.5.0)
5
5
  activerecord
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- activemodel (3.1.0)
11
- activesupport (= 3.1.0)
12
- bcrypt-ruby (~> 3.0.0)
13
- builder (~> 3.0.0)
14
- i18n (~> 0.6)
15
- activerecord (3.1.0)
16
- activemodel (= 3.1.0)
17
- activesupport (= 3.1.0)
18
- arel (~> 2.2.1)
19
- tzinfo (~> 0.3.29)
20
- activeresource (3.1.0)
21
- activemodel (= 3.1.0)
22
- activesupport (= 3.1.0)
23
- activesupport (3.1.0)
24
- multi_json (~> 1.0)
10
+ activemodel (4.0.5)
11
+ activesupport (= 4.0.5)
12
+ builder (~> 3.1.0)
13
+ activerecord (4.0.5)
14
+ activemodel (= 4.0.5)
15
+ activerecord-deprecated_finders (~> 1.0.2)
16
+ activesupport (= 4.0.5)
17
+ arel (~> 4.0.0)
18
+ activerecord-deprecated_finders (1.0.3)
19
+ activeresource (4.0.0)
20
+ activemodel (~> 4.0)
21
+ activesupport (~> 4.0)
22
+ rails-observers (~> 0.1.1)
23
+ activesupport (4.0.5)
24
+ i18n (~> 0.6, >= 0.6.9)
25
+ minitest (~> 4.2)
26
+ multi_json (~> 1.3)
27
+ thread_safe (~> 0.1)
28
+ tzinfo (~> 0.3.37)
25
29
  ansi (1.4.3)
26
- arel (2.2.3)
27
- bcrypt-ruby (3.0.1)
28
- builder (3.0.4)
30
+ appraisal (1.0.0)
31
+ bundler
32
+ rake
33
+ thor (>= 0.14.0)
34
+ arel (4.0.2)
35
+ builder (3.1.4)
29
36
  fakeweb (1.3.0)
30
- i18n (0.6.1)
31
- multi_json (1.0.3)
32
- rake (0.9.2)
33
- shoulda (2.11.3)
34
- sqlite3 (1.3.4)
35
- turn (0.8.2)
36
- ansi (>= 1.2.2)
37
- tzinfo (0.3.35)
37
+ i18n (0.6.9)
38
+ minitest (4.7.5)
39
+ multi_json (1.10.1)
40
+ rails-observers (0.1.2)
41
+ activemodel (~> 4.0)
42
+ rake (10.3.2)
43
+ shoulda (3.5.0)
44
+ shoulda-context (~> 1.0, >= 1.0.1)
45
+ shoulda-matchers (>= 1.4.1, < 3.0)
46
+ shoulda-context (1.2.1)
47
+ shoulda-matchers (2.6.1)
48
+ activesupport (>= 3.0.0)
49
+ sqlite3 (1.3.9)
50
+ thor (0.19.1)
51
+ thread_safe (0.3.4)
52
+ turn (0.9.7)
53
+ ansi
54
+ minitest (~> 4)
55
+ tzinfo (0.3.39)
38
56
 
39
57
  PLATFORMS
40
58
  ruby
@@ -42,6 +60,7 @@ PLATFORMS
42
60
  DEPENDENCIES
43
61
  activeresource
44
62
  activesupport
63
+ appraisal
45
64
  bundler
46
65
  fakeweb
47
66
  find_as_hashes!
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Sport Ngin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown CHANGED
@@ -1,4 +1,5 @@
1
- [![TravisCI](https://secure.travis-ci.org/tstmedia/find_as_hashes.png "TravisCI")](http://travis-ci.org/tstmedia/find_as_hashes "Travis-CI FindAsHashes")
1
+ [![TravisCI](https://travis-ci.org/sportngin/find_as_hashes.png)](https://travis-ci.org/sportngin/find_as_hashes)
2
+ [![Code Climate](https://codeclimate.com/github/sportngin/find_as_hashes.png)](https://codeclimate.com/github/sportngin/find_as_hashes)
2
3
 
3
4
  # ActiveRecord
4
5
 
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ require "bundler/setup"
1
2
  require "bundler/gem_tasks"
2
3
  require "rake/testtask"
3
4
 
@@ -3,13 +3,14 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
  require "find_as_hashes/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "find_as_hashes"
7
- s.version = FindAsHashes::VERSION
8
- s.authors = ["Patrick Byrne"]
9
- s.email = ["patrick.byrne@tstmedia.com"]
10
- s.homepage = "https://github.com/sportngin/find_as_hashes"
11
- s.summary = %q{Provides ActiveRecord methods to return results as attribute hashes rather than instantiated ActiveRecord objects.}
12
- s.description = %q{Provides ActiveRecord methods to return results as attribute hashes rather than instantiated ActiveRecord objects. Useful when working with very large sets of results to improve performance.}
6
+ s.name = "find_as_hashes"
7
+ s.version = FindAsHashes::VERSION
8
+ s.authors = ["Patrick Byrne"]
9
+ s.email = ["patrick.byrne@tstmedia.com"]
10
+ s.homepage = "https://github.com/tstmedia/find_as_hashes"
11
+ s.summary = %q{Provides ActiveRecord methods to return results as attribute hashes rather than instantiated ActiveRecord objects.}
12
+ s.description = %q{Provides ActiveRecord methods to return results as attribute hashes rather than instantiated ActiveRecord objects. Useful when working with very large sets of results to improve performance.}
13
+ s.license = "MIT"
13
14
 
14
15
  s.files = `git ls-files`.split("\n")
15
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -26,4 +27,5 @@ Gem::Specification.new do |s|
26
27
  s.add_development_dependency "activesupport"
27
28
  s.add_development_dependency "sqlite3"
28
29
  s.add_development_dependency "activeresource"
30
+ s.add_development_dependency "appraisal"
29
31
  end
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "3.1.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "4.0.0"
6
+
7
+ gemspec :path => "../"
@@ -21,12 +21,16 @@ module ActiveResource
21
21
  find_as_hashes(:last, *args)
22
22
  end
23
23
 
24
- def instantiate_collection_with_check(collection, prefix_options = {})
24
+ def instantiate_collection_with_check(collection, original_params = {}, prefix_options = {})
25
25
  if @skip_instantiate
26
26
  @skip_instantiate = nil
27
27
  collection
28
28
  else
29
- instantiate_collection_without_check(collection, prefix_options)
29
+ if ActiveResource::VERSION::MAJOR >= 4
30
+ instantiate_collection_without_check(collection, original_params, prefix_options)
31
+ else
32
+ instantiate_collection_without_check(collection, prefix_options)
33
+ end
30
34
  end
31
35
  end
32
36
 
@@ -6,7 +6,7 @@ module FindAsHashes
6
6
 
7
7
  module Relation
8
8
  def all_as_hashes
9
- connection.select_all(self.joins(self.includes_values).to_sql)
9
+ connection.select_all(self.joins(self.includes_values).to_sql).to_a
10
10
  end
11
11
 
12
12
  def first_as_hash
@@ -16,9 +16,12 @@ module FindAsHashes
16
16
  end
17
17
 
18
18
  module Base
19
- delegate :all_as_hashes, :first_as_hash, :to => :scoped
19
+ if ActiveRecord::VERSION::MAJOR >= 4
20
+ delegate :all_as_hashes, :first_as_hash, :to => :all
21
+ else
22
+ delegate :all_as_hashes, :first_as_hash, :to => :scoped
23
+ end
20
24
  end
21
-
22
25
  end
23
26
 
24
27
  ActiveRecord::Relation.send :include, FindAsHashes::Relation
@@ -1,3 +1,3 @@
1
1
  module FindAsHashes
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -42,7 +42,11 @@ class ActiveResourceTest < ActiveSupport::TestCase
42
42
  should "return a single hash" do
43
43
  assert_equal Hash, @hash.class
44
44
  assert_equal Resource::User, @record.class
45
- assert_equal @hash["user"]["name"], User.first.name
45
+ if ActiveResource::VERSION::MAJOR >= 4
46
+ assert_equal @hash["name"], User.first.name
47
+ else
48
+ assert_equal @hash["user"]["name"], User.first.name
49
+ end
46
50
  end
47
51
  end
48
52
 
@@ -55,7 +59,11 @@ class ActiveResourceTest < ActiveSupport::TestCase
55
59
  should "return a single hash" do
56
60
  assert_equal Hash, @hash.class
57
61
  assert_equal Resource::User, @record.class
58
- assert_equal @hash["user"]["name"], User.last.name
62
+ if ActiveResource::VERSION::MAJOR >= 4
63
+ assert_equal @hash["name"], User.last.name
64
+ else
65
+ assert_equal @hash["user"]["name"], User.last.name
66
+ end
59
67
  end
60
68
  end
61
69
  end
@@ -1,12 +1,11 @@
1
1
  require File.dirname(__FILE__) + "/test_helper"
2
2
 
3
- class FindAsHashesTest < ActiveRecord::TestCase
3
+ class FindAsHashesTest < ActiveSupport::TestCase
4
4
  context "#all_as_hashes" do
5
5
  context "on a relation" do
6
6
  setup do
7
- relation = User.where(:active => true)
8
- @records = relation.all
9
- @hashes = relation.all_as_hashes
7
+ @records = User.where(:active => true)
8
+ @hashes = @records.all_as_hashes
10
9
  end
11
10
 
12
11
  should "return an array of attribute hashes" do
data/test/test_helper.rb CHANGED
@@ -30,7 +30,7 @@ class Role < ActiveRecord::Base
30
30
  has_many :user
31
31
  end
32
32
 
33
- # Rails 3.0 has Fixtures, Rails 3.1 has ActiveRecord::Fixtures
34
- fixtures_class = defined?(ActiveRecord::Fixtures) ? ActiveRecord::Fixtures : Fixtures
33
+ # Rails 3 has Fixtures, Rails 4 has ActiveRecord::FixtureSet
34
+ fixtures_class = defined?(ActiveRecord::FixtureSet) ? ActiveRecord::FixtureSet : ActiveRecord::Fixtures
35
35
  fixtures_class.create_fixtures "test/fixtures", :roles
36
36
  fixtures_class.create_fixtures "test/fixtures", :users
metadata CHANGED
@@ -1,158 +1,153 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: find_as_hashes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
5
- prerelease:
4
+ version: 0.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Patrick Byrne
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-19 00:00:00.000000000 Z
11
+ date: 2014-06-26 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: turn
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: shoulda
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: fakeweb
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - ">="
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: activesupport
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - ">="
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - ">="
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: sqlite3
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
- - - ! '>='
115
+ - - ">="
132
116
  - !ruby/object:Gem::Version
133
117
  version: '0'
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
- - - ! '>='
122
+ - - ">="
140
123
  - !ruby/object:Gem::Version
141
124
  version: '0'
142
125
  - !ruby/object:Gem::Dependency
143
126
  name: activeresource
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
- - - ! '>='
129
+ - - ">="
148
130
  - !ruby/object:Gem::Version
149
131
  version: '0'
150
132
  type: :development
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
- - - ! '>='
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: appraisal
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
156
151
  - !ruby/object:Gem::Version
157
152
  version: '0'
158
153
  description: Provides ActiveRecord methods to return results as attribute hashes rather
@@ -164,13 +159,17 @@ executables: []
164
159
  extensions: []
165
160
  extra_rdoc_files: []
166
161
  files:
167
- - .gitignore
168
- - .travis.yml
162
+ - ".gitignore"
163
+ - ".travis.yml"
164
+ - Appraisals
169
165
  - Gemfile
170
166
  - Gemfile.lock
167
+ - MIT-LICENSE
171
168
  - README.markdown
172
169
  - Rakefile
173
170
  - find_as_hashes.gemspec
171
+ - gemfiles/rails_3.gemfile
172
+ - gemfiles/rails_4.gemfile
174
173
  - lib/active_resource/find_as_hashes.rb
175
174
  - lib/find_as_hashes.rb
176
175
  - lib/find_as_hashes/version.rb
@@ -179,29 +178,29 @@ files:
179
178
  - test/fixtures/roles.yml
180
179
  - test/fixtures/users.yml
181
180
  - test/test_helper.rb
182
- homepage: https://github.com/sportngin/find_as_hashes
183
- licenses: []
181
+ homepage: https://github.com/tstmedia/find_as_hashes
182
+ licenses:
183
+ - MIT
184
+ metadata: {}
184
185
  post_install_message:
185
186
  rdoc_options: []
186
187
  require_paths:
187
188
  - lib
188
189
  required_ruby_version: !ruby/object:Gem::Requirement
189
- none: false
190
190
  requirements:
191
- - - ! '>='
191
+ - - ">="
192
192
  - !ruby/object:Gem::Version
193
193
  version: '0'
194
194
  required_rubygems_version: !ruby/object:Gem::Requirement
195
- none: false
196
195
  requirements:
197
- - - ! '>='
196
+ - - ">="
198
197
  - !ruby/object:Gem::Version
199
198
  version: '0'
200
199
  requirements: []
201
200
  rubyforge_project:
202
- rubygems_version: 1.8.24
201
+ rubygems_version: 2.2.2
203
202
  signing_key:
204
- specification_version: 3
203
+ specification_version: 4
205
204
  summary: Provides ActiveRecord methods to return results as attribute hashes rather
206
205
  than instantiated ActiveRecord objects.
207
206
  test_files: