arel_or 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,3 @@
1
+ We use fake_arel in our rails2 project... but need the or fuctionality in rails3.
2
+
3
+ This may not work.
@@ -0,0 +1,31 @@
1
+ module Or
2
+ def self.included(base)
3
+ base.class_eval do
4
+ __or_fn = lambda do |*scopes|
5
+ where = []
6
+ joins = []
7
+ includes = []
8
+
9
+ # for some reason, flatten is actually executing the scope
10
+ scopes = scopes[0] if scopes.size == 1
11
+ scopes.each do |s|
12
+ s = s.proxy_options
13
+ begin
14
+ where << merge_conditions(s[:conditions])
15
+ rescue NoMethodError
16
+ # I am ActiveRecord::Base. Only my subclasses define merge_conditions:
17
+ where << subclasses.first.merge_conditions(s[:conditions])
18
+ end
19
+ #where << merge_conditions(s[:conditions])
20
+ joins << s[:joins] unless s[:joins].nil?
21
+ includes << s[:include] unless s[:include].nil?
22
+ end
23
+ scoped = self
24
+ scoped = scoped.includes(includes.uniq.flatten) unless includes.blank?
25
+ scoped = scoped.joins(joins.uniq.flatten) unless joins.blank?
26
+ scoped.where(where.join(" OR "))
27
+ end
28
+ named_scope :or, __or_fn
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module ArelOr
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel_or
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Phil Smy
@@ -31,9 +31,11 @@ extra_rdoc_files: []
31
31
  files:
32
32
  - .gitignore
33
33
  - Gemfile
34
+ - README
34
35
  - Rakefile
35
36
  - arel_or.gemspec
36
37
  - lib/arel_or.rb
38
+ - lib/arel_or/or.rb
37
39
  - lib/arel_or/version.rb
38
40
  has_rdoc: true
39
41
  homepage: ""