cherring-rangetastic 0.2.0 → 0.3.0

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/README.markdown CHANGED
@@ -27,8 +27,14 @@ Now you can also access this with the following syntax for any field ending with
27
27
 
28
28
  Order.fulfilled.ordered_between(1.week.ago, 10.minutes.ago)
29
29
 
30
- But if that field isn't on the Model or isn't an _on field then it will raise the standard NoMethodError.
30
+ In this new version of rangetastic you can also query on _at fields. If you have an _at field such as created_at you can now
31
+
32
+ Order.fulfilled.created_between(1.week.ago, 10.minutes.ago)
33
+
34
+ However if you have an _on field and _at field the on field will take precedence over the at. If you want to access the _at field over _on field you will need to use the .between and whitelisted fields method specified first.
35
+
36
+ But if your field isn't on the Model or isn't an _on or an _at field then it will raise the standard NoMethodError.
31
37
 
32
38
  And if you (or someone nasty!) try to use a field that is not whitelisted, it will raise ActiveRecord::StatementInvalid
33
39
 
34
- Thanks to spraints for some inspiration.
40
+ Thanks to [spraints](http://github.com/spraints) for some inspiration.
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('rangetastic', '0.2.0') do |p|
5
+ Echoe.new('rangetastic', '0.3.0') do |p|
6
6
  p.description = "Chain a date range to any named_scope on any date field with specified white listed fields"
7
7
  p.url = "http://github.com/cherring/rangetastic"
8
8
  p.author = "Chris Herring"
data/lib/rangetastic.rb CHANGED
@@ -15,15 +15,25 @@ module Rangetastic
15
15
 
16
16
  private
17
17
  def method_missing(symbol, *args, &block)
18
- if (columns_hash.has_key? field(symbol)) || @fields.has_key?(field(symbol))
19
- make_scope(symbol, field(symbol), *args)
18
+ if (field(symbol) || @fields.include?(field_to_query))
19
+ make_scope(symbol, field_to_query, *args)
20
20
  else
21
21
  super
22
22
  end
23
23
  end
24
24
 
25
25
  def field(symbol)
26
- "#{symbol.to_s.gsub("_between","")}_on"
26
+ if columns_hash.has_key? "#{symbol.to_s.gsub("_between","")}_on"
27
+ @field = "#{symbol.to_s.gsub("_between","")}_on"
28
+ elsif columns_hash.has_key? "#{symbol.to_s.gsub("_between","")}_at"
29
+ @field = "#{symbol.to_s.gsub("_between","")}_at"
30
+ else
31
+ @field = nil
32
+ end
33
+ end
34
+
35
+ def field_to_query
36
+ @field
27
37
  end
28
38
 
29
39
  def make_scope(scope, field, *args)
data/rangetastic.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rangetastic}
5
- s.version = "0.2.0"
5
+ s.version = "0.3.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Chris Herring"]
9
- s.date = %q{2009-07-03}
9
+ s.date = %q{2009-07-25}
10
10
  s.description = %q{Chain a date range to any named_scope on any date field with specified white listed fields}
11
11
  s.email = %q{chris.herring.iphone@gmail.com}
12
12
  s.extra_rdoc_files = ["lib/rangetastic.rb", "README.markdown"]
@@ -1,6 +1,6 @@
1
1
  class Order < ActiveRecord::Base
2
2
 
3
- acts_as_rangetastic :fields => ["fulfilled_on","ordered_on","shipped_on"]
3
+ acts_as_rangetastic :fields => ["fulfilled_on","ordered_on","shipped_at"]
4
4
 
5
5
  named_scope :fulfilled, :conditions => ["fulfilled_on is not null"]
6
6
 
@@ -13,7 +13,7 @@ CREATE TABLE orders (
13
13
  id integer NOT NULL default nextval('orders_id_seq'),
14
14
  ordered_on timestamp,
15
15
  fulfilled_on timestamp,
16
- shipped_on timestamp,
16
+ shipped_at timestamp,
17
17
  created_at timestamp without time zone,
18
18
  updated_at timestamp without time zone
19
19
  );
@@ -30,7 +30,7 @@ describe Order do
30
30
  Order.fulfilled.ordered_between(10.days.ago, 1.day.ago).size.should == 5
31
31
  end
32
32
 
33
- %w(ordered shipped fulfilled).each do |field|
33
+ %w(ordered shipped fulfilled created updated).each do |field|
34
34
  it "should be able to access #{field}_between" do
35
35
  lambda{ Order.send("#{field}_between", 1.day.ago, Date.today) }.should_not raise_error(NoMethodError)
36
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cherring-rangetastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Herring
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-03 00:00:00 -07:00
12
+ date: 2009-07-25 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15