cherring-rangetastic 0.1.1

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/MIT-License ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2009 Chris Herring
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,10 @@
1
+ lib/rangetastic.rb
2
+ MIT-License
3
+ Rakefile
4
+ README.markdown
5
+ spec/fixtures/models.rb
6
+ spec/fixtures/structure.sql
7
+ spec/rangetastic_spec.rb
8
+ spec/spec_helper.rb
9
+ spec/test_helper.rb
10
+ Manifest
data/README.markdown ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('rangetastic', '0.1.1') do |p|
6
+ p.description = "Chain a date range to any named_scope on any date field with specified white listed fields"
7
+ p.url = "http://github.com/cherring/rangetastic"
8
+ p.author = "Chris Herring"
9
+ p.email = "chris.herring.iphone@gmail.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,19 @@
1
+ module Rangetastic
2
+
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ def acts_as_rangetastic(options = {:fields => []})
9
+ named_scope :between, lambda{ |start_date, end_date, fieldname|
10
+ field = options[:fields].include?(fieldname) ? fieldname : raise(ActiveRecord::StatementInvalid)
11
+ { :conditions => ["#{field} >= ? AND #{field} <= ?", start_date, end_date] }
12
+ }
13
+ end
14
+ end
15
+ end
16
+
17
+ ActiveRecord::Base.class_eval do
18
+ include Rangetastic
19
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rangetastic}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Chris Herring"]
9
+ s.date = %q{2009-06-29}
10
+ s.description = %q{Chain a date range to any named_scope on any date field with specified white listed fields}
11
+ s.email = %q{chris.herring.iphone@gmail.com}
12
+ s.extra_rdoc_files = ["lib/rangetastic.rb", "README.markdown"]
13
+ s.files = ["lib/rangetastic.rb", "MIT-License", "Rakefile", "README.markdown", "spec/fixtures/models.rb", "spec/fixtures/structure.sql", "spec/rangetastic_spec.rb", "spec/spec_helper.rb", "spec/test_helper.rb", "Manifest", "rangetastic.gemspec"]
14
+ s.homepage = %q{http://github.com/cherring/rangetastic}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rangetastic", "--main", "README.markdown"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{rangetastic}
18
+ s.rubygems_version = %q{1.3.4}
19
+ s.summary = %q{Chain a date range to any named_scope on any date field with specified white listed fields}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ class Order < ActiveRecord::Base
2
+
3
+ acts_as_rangetastic :fields => ["fulfilled_on","ordered_on","shipped_on"]
4
+
5
+ named_scope :fulfilled, :conditions => ["fulfilled_on is not null"]
6
+
7
+ end
@@ -0,0 +1,20 @@
1
+ DROP TABLE IF EXISTS orders;
2
+
3
+ DROP SEQUENCE IF EXISTS orders_id_seq;
4
+
5
+ CREATE SEQUENCE orders_id_seq
6
+ START WITH 1
7
+ INCREMENT BY 1
8
+ NO MAXVALUE
9
+ NO MINVALUE
10
+ CACHE 1;
11
+
12
+ CREATE TABLE orders (
13
+ id integer NOT NULL default nextval('orders_id_seq'),
14
+ ordered_on timestamp,
15
+ fulfilled_on timestamp,
16
+ shipped_on timestamp,
17
+ created_at timestamp without time zone,
18
+ updated_at timestamp without time zone
19
+ );
20
+
@@ -0,0 +1,29 @@
1
+ require 'spec/spec_helper'
2
+ require 'rangetastic'
3
+ include Rangetastic
4
+
5
+ describe Order do
6
+
7
+ it "should have 25 orders" do
8
+ Order.count.should == 25
9
+ end
10
+
11
+ it "should respond to between" do
12
+ Order.respond_to?(:between).should == true
13
+ end
14
+
15
+ it "should have 5 orders fulfilled that were ordered no more than 10 days ago" do
16
+ Order.fulfilled.between(10.days.ago, 1.day.ago,"ordered_on").size.should == 5
17
+ end
18
+
19
+ it "should raise an error if the field is not in fields => []" do
20
+ lambda{ Order.fulfilled.between(1.week.ago, 1.day.ago, "not_a_field") }.should raise_error(ActiveRecord::StatementInvalid)
21
+ end
22
+
23
+ it "should be able to filter on any field that is in fields => []" do
24
+ %w(ordered_on fulfilled_on shipped_on).each do |field|
25
+ lambda{ Order.fulfilled.between(1.week.ago, 1.day.ago, field) }.should_not raise_error(ActiveRecord::StatementInvalid)
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,18 @@
1
+ # Inspiration gained from Thinking Sphinx's test suite via Ryan Bigg's by_star test suite.
2
+
3
+ $:.unshift File.dirname(__FILE__) + '/../lib'
4
+
5
+ require 'rubygems'
6
+ require 'activerecord'
7
+ require 'rangetastic'
8
+ require 'spec/fixtures/models'
9
+ require 'spec/test_helper'
10
+
11
+ FileUtils.mkdir_p "#{Dir.pwd}/tmp"
12
+
13
+ ActiveRecord::Base.logger = Logger.new(StringIO.new)
14
+
15
+ Spec::Runner.configure do |config|
16
+ test = TestHelper.new
17
+ test.setup_postgresql
18
+ end
@@ -0,0 +1,42 @@
1
+ class TestHelper
2
+ attr_accessor :host, :username, :password
3
+ attr_reader :path
4
+
5
+ def initialize
6
+ @host = "localhost"
7
+ @username = "chris" #Insert username for db here
8
+ @password = ""
9
+
10
+ @path = File.expand_path(File.dirname(__FILE__))
11
+ end
12
+
13
+ def setup_postgresql
14
+ ActiveRecord::Base.establish_connection(
15
+ :adapter => 'postgresql',
16
+ :database => 'rangetastic',
17
+ :username => @username,
18
+ :password => @password,
19
+ :host => @host
20
+ )
21
+ ActiveRecord::Base.logger = Logger.new(File.open("tmp/activerecord.log", "a"))
22
+
23
+ structure = File.open("spec/fixtures/structure.sql") { |f| f.read.chomp }
24
+ structure.split(';').each { |table|
25
+ ActiveRecord::Base.connection.execute table
26
+ }
27
+
28
+ 10.times do
29
+ Order.create(:ordered_on => 2.weeks.ago, :fulfilled_on => 2.days.ago)
30
+ end
31
+
32
+ 10.times do
33
+ Order.create(:ordered_on => 3.weeks.ago, :fulfilled_on => 2.days.ago)
34
+ end
35
+
36
+ 5.times do
37
+ Order.create(:ordered_on => 1.weeks.ago, :fulfilled_on => 2.days.ago)
38
+ end
39
+
40
+ end
41
+
42
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cherring-rangetastic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Herring
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-29 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Chain a date range to any named_scope on any date field with specified white listed fields
17
+ email: chris.herring.iphone@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - lib/rangetastic.rb
24
+ - README.markdown
25
+ files:
26
+ - lib/rangetastic.rb
27
+ - MIT-License
28
+ - Rakefile
29
+ - README.markdown
30
+ - spec/fixtures/models.rb
31
+ - spec/fixtures/structure.sql
32
+ - spec/rangetastic_spec.rb
33
+ - spec/spec_helper.rb
34
+ - spec/test_helper.rb
35
+ - Manifest
36
+ - rangetastic.gemspec
37
+ has_rdoc: false
38
+ homepage: http://github.com/cherring/rangetastic
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --line-numbers
42
+ - --inline-source
43
+ - --title
44
+ - Rangetastic
45
+ - --main
46
+ - README.markdown
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "1.2"
60
+ version:
61
+ requirements: []
62
+
63
+ rubyforge_project: rangetastic
64
+ rubygems_version: 1.2.0
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Chain a date range to any named_scope on any date field with specified white listed fields
68
+ test_files: []
69
+