rails-counting 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1f5fd21093ac1c91d1a1159e0b9f2c6edd9c951a
4
+ data.tar.gz: 2a00d95e7c3e992a756adc2de8351ce5c7994034
5
+ SHA512:
6
+ metadata.gz: 131415c4d158d2b8af48e931962ba15bc872f17e43fb8bd6debcd524699b5cc19076dfacebb684ab5ef34cb678dec82725b5dad45b514713a0aea9058cff686a
7
+ data.tar.gz: 96ad4ccb1fe5fb10f28a2871b09e09ef001d54602ea236f1094d09f9a697d5f03de666662a3a98560f408657771821a41c1b023da9ad82050eb8e5cd6c300f02
@@ -0,0 +1,38 @@
1
+ require "active_record/relation"
2
+ require "active_support/concern"
3
+ require "active_support/core_ext/module/aliasing"
4
+ require "rails-counting/version"
5
+
6
+ module ActiveRecord
7
+ module Counting
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ alias_method_chain :count, :counting
12
+ end
13
+
14
+ def count_with_counting(*args, &block)
15
+ if @counting_values.blank?
16
+ count_without_counting *args, &block
17
+ else
18
+ @counting_values.reduce self do |arel, lambda|
19
+ lambda.call arel
20
+ end.count_without_counting *args, &block
21
+ end
22
+ end
23
+
24
+ def counting(&block)
25
+ spawn.counting! &block
26
+ end
27
+
28
+ def counting!(&block)
29
+ @counting_values ||= []
30
+ @counting_values << block
31
+ self
32
+ end
33
+ end
34
+
35
+ class Relation
36
+ include ::ActiveRecord::Counting
37
+ end
38
+ end
@@ -0,0 +1,9 @@
1
+ module RailsCounting
2
+ class Version
3
+ class << self
4
+ def to_s
5
+ "0.0.1"
6
+ end
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-counting
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mike Virata-Stone
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ description: This gem can define custom behavior when calling count on an AREL relation. This
42
+ is especially useful when using relation.select('column AS something'), which currently
43
+ will cause SQL errors.
44
+ email: mike@virata-stone.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - lib/rails-counting.rb
50
+ - lib/rails-counting/version.rb
51
+ homepage: https://github.com/mikestone/rails-counting
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.0.3
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Define custom behavior when counting in AREL.
75
+ test_files: []