by_star 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -391,8 +391,14 @@ You can specify a field also:
391
391
  If your database uses something other than `created_at` for storing a timestamp, you can specify the field option like this:
392
392
 
393
393
  Post.by_month("January", :field => :something_else)
394
-
394
+
395
395
  All methods support this extra option.
396
+
397
+ Or if you're doing it all the time on your model, then it's best to use `by_star_field` at the top of your model:
398
+
399
+ class Post < ActiveRecord::Base
400
+ by_star_field :something_else
401
+ end
396
402
 
397
403
  ## Ordering records
398
404
 
@@ -415,6 +421,7 @@ Unfortunately I forget who exactly prompted me to write the plugin, but I would
415
421
  * Thomase Sinclair (anathematic)
416
422
  * Sam Elliott (lenaryg)
417
423
  * The dude(s) & gal(s) who created Chronic
424
+ * Erik Fonselius
418
425
 
419
426
  ## Suggestions?
420
427
 
data/Rakefile CHANGED
@@ -13,6 +13,7 @@ begin
13
13
  gem.authors = ["Ryan Bigg", "Mislav Marohnić"]
14
14
  gem.add_development_dependency "rspec"
15
15
  gem.add_dependency('chronic', '~> 0.2.3')
16
+ gem.files << "lib/**/*"
16
17
  end
17
18
  Jeweler::GemcutterTasks.new
18
19
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.1
1
+ 0.7.2
data/by_star.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{by_star}
8
- s.version = "0.7.1"
8
+ s.version = "0.7.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ryan Bigg", "Mislav Marohni\304\207"]
12
- s.date = %q{2010-04-08}
12
+ s.date = %q{2010-05-05}
13
13
  s.description = %q{ActiveRecord extension for easier date scopes and time ranges}
14
14
  s.email = %q{radarlistener@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -69,3 +69,4 @@ Gem::Specification.new do |s|
69
69
  s.add_dependency(%q<chronic>, ["~> 0.2.3"])
70
70
  end
71
71
  end
72
+
data/lib/by_star.rb CHANGED
@@ -12,6 +12,12 @@ module ByStar
12
12
  def self.included(base)
13
13
  base.extend ClassMethods
14
14
  base.send(:include, InstanceMethods)
15
+ base.class_eval do
16
+ def self.by_star_field(value=nil)
17
+ @by_star_field ||= value
18
+ @by_star_field || "#{self.table_name}.created_at"
19
+ end
20
+ end
15
21
  end
16
22
 
17
23
  module ClassMethods
data/lib/neighbours.rb CHANGED
@@ -1,13 +1,15 @@
1
1
  module ByStar
2
2
  module Neighbours
3
3
  # Find the previous record to this.
4
- def previous(field="created_at")
5
- self.class.past(self.send(field)) { { :order => "#{field} DESC" }}.first
4
+ def previous(field=nil)
5
+ field = field || self.class.by_star_field
6
+ self.class.past(self.send(field.split(".").last)) { { :order => "#{field} DESC" }}.first
6
7
  end
7
8
 
8
9
  # Find the next record to this.
9
- def next(field="created_at")
10
- self.class.future(self.send(field)) { { :order => "#{field} ASC" }}.first
10
+ def next(field=nil)
11
+ field = field || self.class.by_star_field
12
+ self.class.future(self.send(field.split(".").last)) { { :order => "#{field} ASC" }}.first
11
13
  end
12
14
  end
13
15
  end
data/lib/shared.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module Shared
2
- def conditions_for_range(start_time, end_time, field="created_at")
3
- field = table_name << '.' << (field ? field.to_s : "created_at")
2
+ def conditions_for_range(start_time, end_time, field=nil)
3
+ field = table_name << '.' << field.to_s if field
4
+ field ||= by_star_field
4
5
  ["#{field} >= ? AND #{field} <= ?", start_time.utc, end_time.utc]
5
6
  end
6
7
 
data/lib/vanilla.rb CHANGED
@@ -186,7 +186,7 @@ module ByStar
186
186
  private
187
187
 
188
188
  def by_direction(condition, time, options = {}, &block)
189
- field = options.delete(:field) || "#{self.table_name}.created_at"
189
+ field = options.delete(:field) || by_star_field
190
190
  ensure_valid_options(options)
191
191
  result = scoped({ :conditions => ["#{field} #{condition} ?", time.utc] }.merge(options))
192
192
  result = result.scoped(block.call) if block_given?
data/spec/by_star_spec.rb CHANGED
@@ -79,6 +79,10 @@ describe Post do
79
79
  it "should be able to use an alternative field (symbol)" do
80
80
  Event.by_year(nil, :field => :start_time).size.should eql(8)
81
81
  end
82
+
83
+ it "should not have to specify the field when using by_star_field" do
84
+ Event.by_year.size.should eql(8)
85
+ end
82
86
 
83
87
  it "should be able to use an alternative field (symbol) with directional searching" do
84
88
  stub_time
@@ -12,6 +12,7 @@ class Tag < ActiveRecord::Base
12
12
  end
13
13
 
14
14
  class Event < ActiveRecord::Base
15
+ by_star_field :start_time
15
16
  named_scope :secret, :conditions => { :public => false }
16
17
  end
17
18
 
data/spec/spec_helper.rb CHANGED
@@ -16,15 +16,16 @@ zone = "UTC"
16
16
  Time.zone = zone
17
17
  ActiveRecord::Base.default_timezone = zone
18
18
 
19
+ # bootstraping the plugin through init.rb
20
+ # tests how it would load in a real application
21
+ load File.dirname(__FILE__) + "/../rails/init.rb"
22
+
19
23
  YAML::load_file(File.dirname(__FILE__) + "/database.yml").each do |key, connection|
20
24
  ActiveRecord::Base.establish_connection(connection)
21
25
  load File.dirname(__FILE__) + "/fixtures/schema.rb"
22
26
  load File.dirname(__FILE__) + "/fixtures/models.rb"
23
27
  end
24
28
 
25
- # bootstraping the plugin through init.rb
26
- # tests how it would load in a real application
27
- load File.dirname(__FILE__) + "/../rails/init.rb"
28
29
  # Print the location of puts/p calls so you can find them later
29
30
  # def puts str
30
31
  # super caller.first if caller.first.index("shoulda.rb") == -1
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 1
9
- version: 0.7.1
8
+ - 2
9
+ version: 0.7.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ryan Bigg
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-08 00:00:00 +10:00
18
+ date: 2010-05-05 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency