active_record_not 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module ActiveRecordNot
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module ActiveRecordNot
4
+ def not(args)
5
+ left = self
6
+ last_left_constraint = left.constraints.last
7
+
8
+ case args
9
+ when Symbol
10
+ constrainted_not = left.unscoped.send(args) # eg. User.not(:active), where User#active is a scope
11
+ when Hash
12
+ constrainted_not = left.unscoped.where(args).constraints.last.not # eg. User.not(active: true), so syntax like #where
13
+ when ActiveRecord::Relation
14
+ constrainted_not = args.constraints.last.not # eg. User.not(User.active), where User#active is a scope
15
+ end
16
+
17
+ merged_not = last_left_constraint.nil? ? constrainted_not : last_left_constraint.and(constrainted_not)
18
+
19
+ right = left.where(args)
20
+ right.where_values = [merged_not]
21
+ right
22
+ end
23
+ end
24
+
25
+ ActiveRecord::Relation.send(:include, ActiveRecordNot)
26
+ ActiveRecord::Querying.send(:delegate, :not, :to => :scoped)
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_record_not
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alex Ghiculescu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Adds NOT logic to ActiveRecord
31
+ email:
32
+ - alexghiculescu@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/active_record_not/version.rb
38
+ - lib/active_record_not.rb
39
+ homepage: http://rubygems.org/gems/active_record_not
40
+ licenses: []
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 1.8.24
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: ! 'Chain scopes with #not'
63
+ test_files: []