newellista-searchlogic 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 2
3
3
  :minor: 0
4
- :patch: 2
4
+ :patch: 3
@@ -0,0 +1,63 @@
1
+ module Searchlogic
2
+ module NamedScopes
3
+ # Adds the ability to create alias scopes that allow you to alias a named
4
+ # scope or create a named scope procedure, while at the same time letting
5
+ # Searchlogic know that this is a safe method.
6
+ module AliasScope
7
+ # The searchlogic Search class takes a hash and chains the values together as named scopes.
8
+ # For security reasons the only hash keys that are allowed must be mapped to named scopes.
9
+ # You can not pass the name of a class method and expect that to be called. In some instances
10
+ # you might create a class method that essentially aliases a named scope or represents a
11
+ # named scope procedure. Ex:
12
+ #
13
+ # User.named_scope :teenager, :conditions => ["age >= ? AND age <= ?", 13, 19]
14
+ #
15
+ # This is obviously a very basic example, but there is logic that is duplicated here. For
16
+ # more complicated named scopes this might make more sense, but to make my point you could
17
+ # do something like this instead
18
+ #
19
+ # class User
20
+ # def teenager
21
+ # age_gte(13).age_lte(19)
22
+ # end
23
+ # end
24
+ #
25
+ # As I stated above, you could not use this method with the Searchlogic::Search class because
26
+ # there is no way to tell that this is actually a named scope. Instead, Searchlogic lets you
27
+ # do something like this:
28
+ #
29
+ # User.alias_scope :teenager, lambda { age_gte(13).age_lte(19) }
30
+ #
31
+ # It fits in better, at the same time Searchlogic will know this is an acceptable named scope.
32
+ def alias_scope(name, options = nil)
33
+ alias_scopes[name.to_sym] = options
34
+ (class << self; self end).instance_eval do
35
+ define_method name do |*args|
36
+ case options
37
+ when Symbol
38
+ send(options)
39
+ else
40
+ options.call(*args)
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ def alias_scopes # :nodoc:
47
+ @alias_scopes ||= {}
48
+ end
49
+
50
+ def alias_scope?(name) # :nodoc:
51
+ alias_scopes.key?(name.to_sym)
52
+ end
53
+
54
+ def condition?(name) # :nodoc:
55
+ super || alias_scope?(name)
56
+ end
57
+
58
+ def named_scope_options(name) # :nodoc:
59
+ super || alias_scopes[name.to_sym]
60
+ end
61
+ end
62
+ end
63
+ end
data/searchlogic.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{searchlogic}
5
- s.version = "2.0.2"
5
+ s.version = "2.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ben Johnson of Binary Logic"]
9
- s.date = %q{2009-06-20}
9
+ s.date = %q{2009-06-23}
10
10
  s.email = %q{bjohnson@binarylogic.com}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  "lib/searchlogic.rb",
24
24
  "lib/searchlogic/core_ext/object.rb",
25
25
  "lib/searchlogic/core_ext/proc.rb",
26
+ "lib/searchlogic/named_scopes/alias_scope.rb",
26
27
  "lib/searchlogic/named_scopes/associations.rb",
27
28
  "lib/searchlogic/named_scopes/conditions.rb",
28
29
  "lib/searchlogic/named_scopes/ordering.rb",
@@ -32,20 +33,23 @@ Gem::Specification.new do |s|
32
33
  "searchlogic.gemspec",
33
34
  "spec/core_ext/object_spec.rb",
34
35
  "spec/core_ext/proc_spec.rb",
36
+ "spec/named_scopes/alias_scope_spec.rb",
35
37
  "spec/named_scopes/associations_spec.rb",
36
38
  "spec/named_scopes/conditions_spec.rb",
37
39
  "spec/named_scopes/ordering_spec.rb",
38
40
  "spec/search_spec.rb",
39
41
  "spec/spec_helper.rb"
40
42
  ]
41
- s.homepage = %q{http://github.com/newellista/searchlogic}
43
+ s.has_rdoc = true
44
+ s.homepage = %q{http://github.com/binarylogic/searchlogic}
42
45
  s.rdoc_options = ["--charset=UTF-8"]
43
46
  s.require_paths = ["lib"]
44
- s.rubygems_version = %q{1.3.4}
47
+ s.rubygems_version = %q{1.3.1}
45
48
  s.summary = %q{Searchlogic provides common named scopes and object based searching for ActiveRecord.}
46
49
  s.test_files = [
47
50
  "spec/core_ext/object_spec.rb",
48
51
  "spec/core_ext/proc_spec.rb",
52
+ "spec/named_scopes/alias_scope_spec.rb",
49
53
  "spec/named_scopes/associations_spec.rb",
50
54
  "spec/named_scopes/conditions_spec.rb",
51
55
  "spec/named_scopes/ordering_spec.rb",
@@ -55,7 +59,7 @@ Gem::Specification.new do |s|
55
59
 
56
60
  if s.respond_to? :specification_version then
57
61
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
58
- s.specification_version = 3
62
+ s.specification_version = 2
59
63
 
60
64
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
61
65
  else
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe "AliasScope" do
4
+ it "should allow alias scopes" do
5
+ User.create(:username => "bjohnson")
6
+ User.create(:username => "thunt")
7
+ User.username_has("bjohnson").all.should == User.find_all_by_username("bjohnson")
8
+ end
9
+
10
+ it "should allow alias scopes from the search object" do
11
+ search = User.search
12
+ search.username_has = "bjohnson"
13
+ search.username_has.should == "bjohnson"
14
+ end
15
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newellista-searchlogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson of Binary Logic
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-20 00:00:00 -07:00
12
+ date: 2009-06-23 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -33,6 +33,7 @@ files:
33
33
  - lib/searchlogic.rb
34
34
  - lib/searchlogic/core_ext/object.rb
35
35
  - lib/searchlogic/core_ext/proc.rb
36
+ - lib/searchlogic/named_scopes/alias_scope.rb
36
37
  - lib/searchlogic/named_scopes/associations.rb
37
38
  - lib/searchlogic/named_scopes/conditions.rb
38
39
  - lib/searchlogic/named_scopes/ordering.rb
@@ -42,13 +43,14 @@ files:
42
43
  - searchlogic.gemspec
43
44
  - spec/core_ext/object_spec.rb
44
45
  - spec/core_ext/proc_spec.rb
46
+ - spec/named_scopes/alias_scope_spec.rb
45
47
  - spec/named_scopes/associations_spec.rb
46
48
  - spec/named_scopes/conditions_spec.rb
47
49
  - spec/named_scopes/ordering_spec.rb
48
50
  - spec/search_spec.rb
49
51
  - spec/spec_helper.rb
50
- has_rdoc: false
51
- homepage: http://github.com/newellista/searchlogic
52
+ has_rdoc: true
53
+ homepage: http://github.com/binarylogic/searchlogic
52
54
  post_install_message:
53
55
  rdoc_options:
54
56
  - --charset=UTF-8
@@ -71,11 +73,12 @@ requirements: []
71
73
  rubyforge_project:
72
74
  rubygems_version: 1.2.0
73
75
  signing_key:
74
- specification_version: 3
76
+ specification_version: 2
75
77
  summary: Searchlogic provides common named scopes and object based searching for ActiveRecord.
76
78
  test_files:
77
79
  - spec/core_ext/object_spec.rb
78
80
  - spec/core_ext/proc_spec.rb
81
+ - spec/named_scopes/alias_scope_spec.rb
79
82
  - spec/named_scopes/associations_spec.rb
80
83
  - spec/named_scopes/conditions_spec.rb
81
84
  - spec/named_scopes/ordering_spec.rb