better_ar 0.1.1 → 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: 926017a90171c61733ce212549ece6340d95fff4
4
- data.tar.gz: e9344fe60c016fd8119d8452103a6b98b5e1fbbb
3
+ metadata.gz: c1b12ec6ea364b851a57f1eaea76dd5e9400d1d5
4
+ data.tar.gz: 61340f6365bca431263862be69a6806feab5cc9b
5
5
  SHA512:
6
- metadata.gz: b3a7949ca8b5fda7c98d916e40a950748e976b3e5bf2075c49e6b23e82312aa1f921c9be709f29b9f4da9b55ce51ff8673dccc1089d32441ac8e9dede5b77d27
7
- data.tar.gz: 53efcc54e276a00f4ea3145767d83a413d913bef2a5e93e6d481fb0226319a4b8af06978928f7349a1685008fd8aeda6b7c6e7fa9b06ddfd375df1ae89fbf939
6
+ metadata.gz: 46ff9adae2d5bc65c65a7b46b826d2bbcb2b2b1fdddd9e528b2f809966f2f053457a8e4240ed804f70996e8b15b715e8ffaaa3029f87969a9f89f70b2a0b716f
7
+ data.tar.gz: b71c56097afe92358badbe84a93352a397004df78d04a10a28c5734cc7a4ec0663b60291c5fa105af54b0f71ed5809f70a8d434cb5d1cd14604e8e082024f861
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in better_ar.gemspec
4
4
  gemspec
5
+
6
+ gem 'byebug'
7
+ gem 'm'
data/better_ar.gemspec CHANGED
@@ -19,8 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_development_dependency 'activerecord', ['~> 3.2.9']
22
+ s.add_development_dependency 'activerecord', ['~> 4.0.1']
23
23
  s.add_development_dependency 'rake'
24
24
  s.add_development_dependency 'sqlite3'
25
- s.add_development_dependency 'debugger'
26
25
  end
@@ -1,13 +1,5 @@
1
1
  module BetterAr
2
2
  module AssociationCollection
3
-
4
- def self.included(base)
5
- base.class_eval do
6
- alias_method_chain :first, :better_ar
7
- alias_method_chain :count, :better_ar
8
- end
9
- end
10
-
11
3
  # Allows for the same interface as {BetterAr::Relation#first} on association collections
12
4
  #
13
5
  # example:
@@ -16,11 +8,11 @@ module BetterAr
16
8
  # @param [Hash]
17
9
  # Optional
18
10
  # @returns [ActiveRecord::Base]
19
- def first_with_better_ar(opts = {})
11
+ def first(opts = {})
20
12
  if opts.empty?
21
- first_without_better_ar
13
+ super
22
14
  elsif opts.key?(:conditions)
23
- first_without_better_ar(opts)
15
+ super(opts)
24
16
  else
25
17
  scoped.first(opts)
26
18
  end
@@ -34,16 +26,24 @@ module BetterAr
34
26
  # @param [Hash]
35
27
  # Optional
36
28
  # @returns [Integer]
37
- def count_with_better_ar(opts = {}, attr = nil)
38
- if opts.empty?
39
- count_without_better_ar
40
- elsif opts.key?(:conditions)
41
- count_without_better_ar(opts, attr)
29
+ def count(column_name = nil, count_options = {})
30
+ if column_name.is_a?(Hash)
31
+ count_options = column_name
32
+ column_name = nil
33
+ end
34
+
35
+ if count_options.empty?
36
+ super
37
+ elsif count_options.key?(:conditions)
38
+ super(column_name, count_options)
42
39
  else
43
- scoped.count(opts)
40
+ scope.where(count_options).count
44
41
  end
45
42
  end
46
43
  end
47
44
  end
48
45
 
49
- ActiveRecord::Associations::CollectionAssociation.send(:include, BetterAr::AssociationCollection)
46
+
47
+ ActiveSupport.on_load(:active_record) do
48
+ ActiveRecord::Associations::CollectionAssociation.send(:prepend, BetterAr::AssociationCollection)
49
+ end
@@ -13,16 +13,25 @@ module BetterAr
13
13
  # @param [Hash]
14
14
  # Optional follows same convention as {#all}
15
15
  # @return [Integer]
16
- def count(opts = {}, extra = {})
17
- if opts.nil? || opts.empty?
18
- super(nil, extra)
19
- elsif opts.key?(:conditions)
20
- super(opts, extra)
16
+ def count(column_name = nil, count_options = {})
17
+ if column_name.is_a?(Hash)
18
+ count_options = column_name
19
+ column_name = nil
20
+ end
21
+
22
+ if count_options.empty?
23
+ super
24
+ elsif count_options.key?(:conditions)
25
+ super(column_name, count_options)
21
26
  else
22
- all(opts).count
27
+ all(count_options).count
23
28
  end
24
29
  end
25
30
  end
26
31
  end
27
32
 
28
- ActiveRecord::Relation.send(:include, BetterAr::Calculations)
33
+ ActiveSupport.on_load(:active_record) do
34
+ class << ActiveRecord::Base
35
+ prepend BetterAr::Calculations
36
+ end
37
+ end
@@ -55,7 +55,7 @@ module BetterAr
55
55
  # @return [ActiveRecord::Base]
56
56
  def first(opts = {})
57
57
  if opts.empty?
58
- super()
58
+ super
59
59
  elsif opts.key?(:conditions)
60
60
  super(opts)
61
61
  else
@@ -93,4 +93,10 @@ module BetterAr
93
93
  end
94
94
  end
95
95
 
96
- ActiveRecord::Relation.send(:include, BetterAr::FinderMethods)
96
+ ActiveSupport.on_load(:active_record) do
97
+ class << ActiveRecord::Base
98
+ prepend BetterAr::FinderMethods
99
+ end
100
+
101
+ ActiveRecord::Associations::CollectionProxy::ActiveRecord_Associations_CollectionProxy_Record.send(:prepend, BetterAr::FinderMethods)
102
+ end
@@ -1,3 +1,3 @@
1
1
  module BetterAr
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/better_ar.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  module BetterAr; end
2
2
 
3
+ require 'active_support'
4
+ require 'active_support/core_ext'
5
+ require 'active_record/deprecated_finders'
6
+ require 'active_record'
3
7
  require 'better_ar/finder_methods'
4
8
  require 'better_ar/calculations'
5
9
  require 'better_ar/association_collection'
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'test_helper'
2
2
 
3
3
  describe 'ActiveRecord::Relation Finder Methods' do
4
4
  after do
@@ -44,7 +44,7 @@ describe 'ActiveRecord::Relation Finder Methods' do
44
44
  it 'calls #first on .all' do
45
45
  expected = User.create(:age => 10)
46
46
  User.create(:age => 11)
47
- User.first(:age => 10).must_equal expected
47
+ User.first(:age => 10).age.must_equal expected.age
48
48
  end
49
49
  end
50
50
 
@@ -1,9 +1,7 @@
1
1
  require 'rubygems'
2
+ require 'byebug'
2
3
  require 'minitest/autorun'
3
- require 'active_support/core_ext'
4
- require 'active_record'
5
4
  require 'better_ar'
6
- require 'debugger'
7
5
 
8
6
  class Object
9
7
  def must_be_like other
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_ar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Cardarella
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.9
19
+ version: 4.0.1
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 3.2.9
26
+ version: 4.0.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: debugger
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  description: Better Active Record finders
70
56
  email:
71
57
  - bcardarella@gmail.com
@@ -87,8 +73,8 @@ files:
87
73
  - lib/better_ar/calculations.rb
88
74
  - lib/better_ar/finder_methods.rb
89
75
  - lib/better_ar/version.rb
90
- - test/helper.rb
91
76
  - test/test_finder_methods.rb
77
+ - test/test_helper.rb
92
78
  homepage: https://github.com/bcardarella/better_ar
93
79
  licenses: []
94
80
  metadata: {}
@@ -113,5 +99,5 @@ signing_key:
113
99
  specification_version: 4
114
100
  summary: Better Active Record finders
115
101
  test_files:
116
- - test/helper.rb
117
102
  - test/test_finder_methods.rb
103
+ - test/test_helper.rb