dmichael-set-notation-helper 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,7 +1,7 @@
1
1
  SetNotationHelper
2
2
  =================
3
3
 
4
- A library providing set notation support for ActiveRecord models. Include this module in the models you want to support set notation finders and you are all set.
4
+ A library providing set notation support for ActiveRecord models. Include this module in the models you want to support set notation finders and you are all set, or install the gem and add it to your environment to add support for all your models.
5
5
 
6
6
  To use:
7
7
 
@@ -11,7 +11,7 @@ To use:
11
11
  Installation
12
12
  ------------
13
13
 
14
- sudo gem install set-notation-helper -s http://gems.github.com
14
+ sudo gem install dmichael-set-notation-helper -s http://gems.github.com
15
15
 
16
16
  Add the gem to your environment.rb file
17
17
 
@@ -28,7 +28,7 @@ If you are interested in matching for sets in the routes you can do something li
28
28
  /\{\s*([\d\-,\s*]*)\s*\}/
29
29
  ]
30
30
 
31
- set_regexes.each do |regex|
31
+ regexes.each do |regex|
32
32
  map.with_options( :controller => 'sounds', :action => 'index', :id => regex, :conditions => { :method => :get }) do |r|
33
33
  r.connect "/#{resource}/:id.:format"
34
34
  r.connect "/#{resource}/:id"
@@ -1,27 +1,8 @@
1
1
  module SetNotationHelper
2
2
 
3
3
  def self.included(base)
4
- base.class_eval do
5
- extend SetNotationHelper::ClassMethods
6
-
7
- # This scope accepts either a String in the form "{1,2,3}" **OR** an Integer
8
- named_scope :in_set, lambda { |*args|
9
- value = args.first
10
-
11
- # A string input is either a set or an integer in disguise
12
- unless value.is_a?(String) || value.is_a?(Integer)
13
- logger.error "[SetNotationHelper] You have given the helper something it cant use: #{value.class}. No filter applied!"
14
- return {}
15
- end
16
-
17
- if is_set?(value)
18
- { :conditions => "#{table_name}.id IN (#{ parse_set(value).to_a.join(',') })" }
19
- else
20
- { :conditions => "#{table_name}.id = #{ value.to_i }" }
21
- end
22
- }
23
-
24
- end
4
+ base.extend(ClassMethods)
5
+ # base.send :include, ClassMethods
25
6
  end
26
7
 
27
8
  def set_limit
@@ -29,6 +10,23 @@ module SetNotationHelper
29
10
  end
30
11
 
31
12
  module ClassMethods
13
+
14
+ # This scope accepts either a String in the form "{1,2,3}" **OR** an Integer
15
+ named_scope :in_set, lambda { |*args|
16
+ value = args.first
17
+
18
+ # A string input is either a set or an integer in disguise
19
+ unless value.is_a?(String) || value.is_a?(Integer)
20
+ logger.error "[SetNotationHelper] You have given the helper something it cant use: #{value.class}. No filter applied!"
21
+ return {}
22
+ end
23
+
24
+ if is_set?(value)
25
+ { :conditions => "#{table_name}.id IN (#{ parse_set(value).to_a.join(',') })" }
26
+ else
27
+ { :conditions => "#{table_name}.id = #{ value.to_i }" }
28
+ end
29
+ }
32
30
 
33
31
  def is_set_or_range?(input)
34
32
  if is_set?(input) or is_range?(input)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dmichael-set-notation-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.2"
4
+ version: "0.3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Michael