-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
boots into console with scopes fixed and included core-extension modu…
…les cleanly namespaced
- Loading branch information
1 parent
ec047fe
commit 524e046
Showing
24 changed files
with
290 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
require 'date_time_extras' | ||
require 'string_extras' | ||
|
||
class AutoImporter | ||
|
||
attr_accessor :import, :messages, :email | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,41 @@ | ||
class Customer < ActiveRecord::Base | ||
default_scope :order => 'last_name, zip' | ||
default_scope { order('last_name, zip') } | ||
|
||
scope :subscriber_during, ->(seasons) { | ||
joins(:vouchertypes).where('vouchertypes.subscription = ? AND vouchertypes.season IN (?)', true, seasons) | ||
} | ||
|
||
named_scope :subscriber_during, lambda { |seasons| | ||
{ :joins => :vouchertypes, | ||
:conditions => ['vouchertypes.subscription = ? AND vouchertypes.season IN (?)', | ||
true, seasons] }} | ||
|
||
|
||
named_scope :purchased_any_vouchertypes, lambda { |vouchertype_ids| | ||
{ :joins => :vouchertypes, | ||
:conditions => ['vouchertypes.id IN (?)', vouchertype_ids], | ||
:select => 'DISTINCT customers.*'}} | ||
scope :purchased_any_vouchertypes, ->(vouchertype_ids) { | ||
joins(:vouchertypes).where('vouchertypes.id IN (?)', vouchertype_ids).select('distinct customers.*') | ||
} | ||
|
||
def self.purchased_no_vouchertypes(vouchertype_ids) | ||
Customer.all - Customer.purchased_any_vouchertypes(vouchertype_ids) | ||
end | ||
|
||
|
||
named_scope :seen_any_of, lambda { |show_ids| | ||
{ :joins => [:vouchers,:showdates], | ||
:conditions => ['items.customer_id = customers.id AND | ||
items.showdate_id = showdates.id AND | ||
items.type = "Voucher" AND | ||
showdates.show_id IN (?)', show_ids], | ||
:select => 'DISTINCT customers.*' | ||
}} | ||
scope :seen_any_of, ->(show_ids) { | ||
joins(:vouchers, :showdates). | ||
where('items.customer_id = customers.id AND items.showdate_id = showdates.id AND | ||
items.type = "Voucher" AND showdates.show_id IN (?)', show_ids). | ||
select('DISTINCT customers.*') | ||
} | ||
|
||
def self.seen_none_of(show_ids) ; Customer.all - Customer.seen_any_of(show_ids) ; end | ||
|
||
named_scope :with_open_subscriber_vouchers, lambda { |vtypes| | ||
{ :joins => ',items', | ||
:conditions => ['items.customer_id = customers.id AND | ||
items.type = "Voucher" AND | ||
scope :with_open_subscriber_vouchers, ->(vtypes) { | ||
joins(:items). | ||
where('items.customer_id = customers.id AND items.type = "Voucher" AND | ||
(items.showdate_id = 0 OR items.showdate_id IS NULL) AND | ||
items.vouchertype_id IN (?)', vtypes], | ||
:select => 'DISTINCT customers.*' | ||
}} | ||
|
||
|
||
named_scope :donated_during, lambda { |start_date, end_date, amount| | ||
{ :joins => ',items,orders', | ||
:select => 'DISTINCT customers.*', | ||
:conditions => ['items.customer_id = customers.id AND | ||
items.amount >= ? AND | ||
items.type = "Donation" AND | ||
orders.sold_on BETWEEN ? AND ?', | ||
amount, start_date, end_date] }} | ||
|
||
items.vouchertype_id IN (?)', vtypes). | ||
select('DISTINCT customers.*') | ||
} | ||
|
||
scope :donated_during, ->(start_date, end_date, amount) { | ||
joins(:items, :orders). | ||
where(%q{items.customer_id = customers.id AND items.amount >= ? AND items.type = "Donation" | ||
AND orders.sold_on BETWEEN ? AND ?}, | ||
amount, start_date, end_date). | ||
select('distinct customers.*') | ||
} | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env ruby | ||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) | ||
load Gem.bin_path('bundler', 'bundle') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env ruby | ||
begin | ||
load File.expand_path('../spring', __FILE__) | ||
rescue LoadError => e | ||
raise unless e.message.include?('spring') | ||
end | ||
APP_PATH = File.expand_path('../../config/application', __FILE__) | ||
require_relative '../config/boot' | ||
require 'rails/commands' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env ruby | ||
begin | ||
load File.expand_path('../spring', __FILE__) | ||
rescue LoadError => e | ||
raise unless e.message.include?('spring') | ||
end | ||
require_relative '../config/boot' | ||
require 'rake' | ||
Rake.application.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env ruby | ||
require 'pathname' | ||
|
||
# path to your application root. | ||
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) | ||
|
||
Dir.chdir APP_ROOT do | ||
# This script is a starting point to setup your application. | ||
# Add necessary setup steps to this file: | ||
|
||
puts "== Installing dependencies ==" | ||
system "gem install bundler --conservative" | ||
system "bundle check || bundle install" | ||
|
||
# puts "\n== Copying sample files ==" | ||
# unless File.exist?("config/database.yml") | ||
# system "cp config/database.yml.sample config/database.yml" | ||
# end | ||
|
||
puts "\n== Preparing database ==" | ||
system "bin/rake db:setup" | ||
|
||
puts "\n== Removing old logs and tempfiles ==" | ||
system "rm -f log/*" | ||
system "rm -rf tmp/cache" | ||
|
||
puts "\n== Restarting application server ==" | ||
system "touch tmp/restart.txt" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# This file loads spring without using Bundler, in order to be fast. | ||
# It gets overwritten when you run the `spring binstub` command. | ||
|
||
unless defined?(Spring) | ||
require 'rubygems' | ||
require 'bundler' | ||
|
||
lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) | ||
spring = lockfile.specs.detect { |spec| spec.name == "spring" } | ||
if spring | ||
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path | ||
gem 'spring', spring.version | ||
require 'spring/binstub' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# This file is used by Rack-based servers to start the application. | ||
|
||
require ::File.expand_path('../config/environment', __FILE__) | ||
run Rails.application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module CoreExtensions | ||
module Date | ||
module Season | ||
def self.included(base) ; base.extend(ClassMethods) ; end | ||
def at_beginning_of_season(arg=nil) | ||
self.to_time.at_beginning_of_season(arg).to_date | ||
end | ||
def at_end_of_season(arg=nil) | ||
self.to_time.at_end_of_season(arg).to_date | ||
end | ||
def within_season?(arg) | ||
self.to_time.within_season?(arg) | ||
end | ||
module ClassMethods | ||
def from_year_month_day(hash) | ||
now = Time.now | ||
Date.new((hash[:year] || now.year).to_i, (hash[:month] || now.month).to_i, (hash[:day] || now.day).to_i) | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.