piggybak 0.2.0 → 0.2.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/README.md CHANGED
@@ -99,17 +99,15 @@ Recipes
99
99
  end
100
100
 
101
101
 
102
- Roadmap / TODOs
102
+ TODOs
103
103
  ========
104
104
 
105
- * Figure out how to make entire payments section read only, except for ability to refund
106
- * Add refunds: Add actionable link under payments
107
- * Handle state options in admin: selected state or free text
108
-
109
- * Create rake task for copying over views, and make sure app views will override gems
110
- * Test email send functionality
111
- * Test a different user model
112
- * Add unit testing
105
+ * Bug: Handle state options in admin: selected state or free text
106
+ * Feature: Figure out how to make entire payments section read only, except for ability to refund
107
+ * Feature: Add refunds: Add actionable link under payments, include on payments page only
108
+ * Feature: Create rake task for copying over views, and make sure app views will override gems
109
+ * Test: Test email send functionality
110
+ * Test: Add unit testing
113
111
 
114
112
  Copyright
115
113
  ========
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -5,7 +5,7 @@ module PiggybakHelper
5
5
  def cart_link
6
6
  cart = Piggybak::Cart.new(request.cookies["cart"])
7
7
  nitems = cart.items.inject(0) { |nitems, item| nitems + item[:quantity] }
8
- if nitems > 0
8
+ if nitems > 0 && !["piggybak/orders", "piggybak/cart"].include?(params[:controller])
9
9
  link_to "#{pluralize(nitems, 'item')}: #{number_to_currency(cart.total)}", piggybak.cart_url
10
10
  end
11
11
  end
@@ -1,5 +1,5 @@
1
1
  module Piggybak
2
- class PaymentCalculator::AuthorizeNet < PaymentCalculator
2
+ class PaymentCalculator::AuthorizeNet
3
3
  KEYS = ["login", "password"]
4
4
  KLASS = ::ActiveMerchant::Billing::AuthorizeNetGateway
5
5
 
@@ -1,5 +1,5 @@
1
1
  module Piggybak
2
- class PaymentCalculator::Fake < PaymentCalculator
2
+ class PaymentCalculator::Fake
3
3
  KEYS = []
4
4
  KLASS = ::Piggybak::PaymentCalculator::Fake
5
5
 
@@ -1,12 +1,5 @@
1
1
  module Piggybak
2
2
  class PaymentMethod < ActiveRecord::Base
3
-
4
- # klass_enum requires the ShippingCalculator subclasses to be loaded
5
- shipping_calcs_path = File.expand_path("../payment_calculator", __FILE__)
6
- Dir.glob(shipping_calcs_path + "**/*.rb").each do |subclass|
7
- ActiveSupport::Dependencies.require_or_load subclass
8
- end
9
-
10
3
  has_many :payment_method_values, :dependent => :destroy
11
4
  alias :metadata :payment_method_values
12
5
 
@@ -16,7 +9,7 @@ module Piggybak
16
9
  validates_presence_of :description
17
10
 
18
11
  def klass_enum
19
- Piggybak::PaymentCalculator.subclasses
12
+ Piggybak.config.payment_calculators
20
13
  end
21
14
 
22
15
  validates_each :payment_method_values do |record, attr, value|
@@ -24,7 +17,11 @@ module Piggybak
24
17
  payment_method = record.klass.constantize
25
18
  metadata_keys = value.collect { |v| v.key }.sort
26
19
  if payment_method::KEYS.sort != metadata_keys
27
- record.errors.add attr, "You must define key values for #{payment_method::KEYS.join(', ')} for this payment method."
20
+ if payment_method::KEYS.empty?
21
+ record.errors.add attr, "You don't need any metadata for this method."
22
+ else
23
+ record.errors.add attr, "You must define key values for #{payment_method::KEYS.join(', ')} for this payment method."
24
+ end
28
25
  end
29
26
  end
30
27
  end
@@ -1,5 +1,5 @@
1
1
  module Piggybak
2
- class ShippingCalculator::FlatRate < ShippingCalculator
2
+ class ShippingCalculator::FlatRate
3
3
  KEYS = ["rate"]
4
4
 
5
5
  def self.available?(*args)
@@ -1,5 +1,5 @@
1
1
  module Piggybak
2
- class ShippingCalculator::Free < ShippingCalculator
2
+ class ShippingCalculator::Free
3
3
  KEYS = []
4
4
 
5
5
  def self.available?(method, object)
@@ -1,5 +1,5 @@
1
1
  module Piggybak
2
- class ShippingCalculator::Range < ShippingCalculator
2
+ class ShippingCalculator::Range
3
3
  KEYS = ["cost", "upper", "lower"]
4
4
 
5
5
  def self.available?(method, object)
@@ -1,12 +1,5 @@
1
1
  module Piggybak
2
2
  class ShippingMethod < ActiveRecord::Base
3
-
4
- # klass_enum requires the ShippingCalculator subclasses to be loaded
5
- shipping_calcs_path = File.expand_path("../shipping_calculator", __FILE__)
6
- Dir.glob(shipping_calcs_path + "**/*.rb").each do |subclass|
7
- ActiveSupport::Dependencies.require_or_load subclass
8
- end
9
-
10
3
  has_many :shipping_method_values, :dependent => :destroy
11
4
  alias :metadata :shipping_method_values
12
5
 
@@ -20,13 +13,17 @@ module Piggybak
20
13
  calculator = record.klass.constantize
21
14
  metadata_keys = value.collect { |v| v.key }.sort
22
15
  if calculator::KEYS.sort != metadata_keys
23
- record.errors.add attr, "You must define key values for #{calculator::KEYS.join(', ')} for this shipping method."
16
+ if calculator::KEYS.empty?
17
+ record.errors.add attr, "You don't need any metadata for this method."
18
+ else
19
+ record.errors.add attr, "You must define key values for #{calculator::KEYS.join(', ')} for this shipping method."
20
+ end
24
21
  end
25
22
  end
26
23
  end
27
24
 
28
25
  def klass_enum
29
- Piggybak::ShippingCalculator.subclasses
26
+ Piggybak.config.shipping_calculators
30
27
  end
31
28
 
32
29
  def self.available_methods(cart)
@@ -1,5 +1,5 @@
1
1
  module Piggybak
2
- class TaxCalculator::Percent < TaxCalculator
2
+ class TaxCalculator::Percent
3
3
  KEYS = ["state_abbr", "rate"]
4
4
 
5
5
  def self.available?(method, object)
@@ -1,12 +1,5 @@
1
1
  module Piggybak
2
2
  class TaxMethod < ActiveRecord::Base
3
-
4
- # klass_enum requires the ShippingCalculator subclasses to be loaded
5
- shipping_calcs_path = File.expand_path("../tax_calculator", __FILE__)
6
- Dir.glob(shipping_calcs_path + "**/*.rb").each do |subclass|
7
- ActiveSupport::Dependencies.require_or_load subclass
8
- end
9
-
10
3
  has_many :tax_method_values, :dependent => :destroy
11
4
  alias :metadata :tax_method_values
12
5
 
@@ -20,13 +13,17 @@ module Piggybak
20
13
  calculator = record.klass.constantize
21
14
  metadata_keys = value.collect { |v| v.key }.sort
22
15
  if calculator::KEYS.sort != metadata_keys
23
- record.errors.add attr, "You must define key values for #{calculator::KEYS.join(', ')} for this tax method."
16
+ if calculator::KEYS.empty?
17
+ record.errors.add attr, "You don't need any metadata for this method."
18
+ else
19
+ record.errors.add attr, "You must define key values for #{calculator::KEYS.join(', ')} for this tax method."
20
+ end
24
21
  end
25
22
  end
26
23
  end
27
24
 
28
25
  def klass_enum
29
- Piggybak::TaxCalculator.subclasses
26
+ Piggybak.config.tax_calculators
30
27
  end
31
28
 
32
29
  def self.calculate_tax(object)
@@ -7,9 +7,13 @@
7
7
  <%= address.text_field :lastname %>
8
8
  </div>
9
9
  <div class="item">
10
- <%= address.label :address1 %>
10
+ <%= address.label :address1, "Address" %>
11
11
  <%= address.text_field :address1 %>
12
12
  </div>
13
+ <div class="item">
14
+ <%= address.label :address2, "Address cont." %>
15
+ <%= address.text_field :address2 %>
16
+ </div>
13
17
  <div class="item">
14
18
  <%= address.label :city %>
15
19
  <%= address.text_field :city %>
data/lib/piggybak.rb CHANGED
@@ -1,9 +1,23 @@
1
+ require 'piggybak/config'
1
2
  require 'acts_as_variant/base'
2
3
  require 'acts_as_orderer/base'
3
4
  require 'active_merchant'
4
5
  require 'currency'
5
6
 
6
7
  module Piggybak
8
+ def self.config(entity = nil, &block)
9
+ if entity
10
+ Piggybak::Config.model(entity, &block)
11
+ elsif block_given? && ENV['SKIP_RAILS_ADMIN_INITIALIZER'] != "true"
12
+ block.call(Piggybak::Config)
13
+ else
14
+ Piggybak::Config
15
+ end
16
+ end
17
+
18
+ def self.reset
19
+ Piggybak::Config.reset
20
+ end
7
21
 
8
22
  class Engine < Rails::Engine
9
23
  initializer "piggybak.add_helper" do |app|
@@ -0,0 +1,20 @@
1
+ module Piggybak
2
+ module Config
3
+ class << self
4
+ attr_accessor :payment_calculators
5
+ attr_accessor :shipping_calculators
6
+ attr_accessor :tax_calculators
7
+
8
+ def reset
9
+ @payment_calculators = ["::Piggybak::PaymentCalculator::Fake",
10
+ "::Piggybak::PaymentCalculator::AuthorizeNet"]
11
+ @shipping_calculators = ["::Piggybak::ShippingCalculator::FlatRate",
12
+ "::Piggybak::ShippingCalculator::Free",
13
+ "::Piggybak::ShippingCalculator::Range"]
14
+ @tax_calculators = ["::Piggybak::TaxCalculator::Percent"]
15
+ end
16
+ end
17
+
18
+ self.reset
19
+ end
20
+ end
data/piggybak.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "piggybak"
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Steph Skardal", "Brian Buchalter"]
12
- s.date = "2012-01-06"
12
+ s.date = "2012-01-07"
13
13
  s.description = "Mountable ecommerce"
14
14
  s.email = "steph@endpoint.com"
15
15
  s.extra_rdoc_files = [
@@ -34,21 +34,17 @@ Gem::Specification.new do |s|
34
34
  "app/models/piggybak/line_item.rb",
35
35
  "app/models/piggybak/order.rb",
36
36
  "app/models/piggybak/payment.rb",
37
- "app/models/piggybak/payment_calculator.rb",
38
37
  "app/models/piggybak/payment_calculator/authorize_net.rb",
39
38
  "app/models/piggybak/payment_calculator/fake.rb",
40
39
  "app/models/piggybak/payment_method.rb",
41
40
  "app/models/piggybak/payment_method_value.rb",
42
41
  "app/models/piggybak/shipment.rb",
43
- "app/models/piggybak/shipping_calculator.rb",
44
42
  "app/models/piggybak/shipping_calculator/flat_rate.rb",
45
43
  "app/models/piggybak/shipping_calculator/free.rb",
46
- "app/models/piggybak/shipping_calculator/pickup.rb",
47
44
  "app/models/piggybak/shipping_calculator/range.rb",
48
45
  "app/models/piggybak/shipping_method.rb",
49
46
  "app/models/piggybak/shipping_method_value.rb",
50
47
  "app/models/piggybak/state.rb",
51
- "app/models/piggybak/tax_calculator.rb",
52
48
  "app/models/piggybak/tax_calculator/percent.rb",
53
49
  "app/models/piggybak/tax_method.rb",
54
50
  "app/models/piggybak/tax_method_value.rb",
@@ -86,6 +82,7 @@ Gem::Specification.new do |s|
86
82
  "lib/acts_as_variant/base.rb",
87
83
  "lib/currency.rb",
88
84
  "lib/piggybak.rb",
85
+ "lib/piggybak/config.rb",
89
86
  "piggybak.gemspec"
90
87
  ]
91
88
  s.homepage = "http://github.com/stephskardal/piggybak"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: piggybak
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Steph Skardal
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2012-01-06 00:00:00 Z
14
+ date: 2012-01-07 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: countries
@@ -128,21 +128,17 @@ files:
128
128
  - app/models/piggybak/line_item.rb
129
129
  - app/models/piggybak/order.rb
130
130
  - app/models/piggybak/payment.rb
131
- - app/models/piggybak/payment_calculator.rb
132
131
  - app/models/piggybak/payment_calculator/authorize_net.rb
133
132
  - app/models/piggybak/payment_calculator/fake.rb
134
133
  - app/models/piggybak/payment_method.rb
135
134
  - app/models/piggybak/payment_method_value.rb
136
135
  - app/models/piggybak/shipment.rb
137
- - app/models/piggybak/shipping_calculator.rb
138
136
  - app/models/piggybak/shipping_calculator/flat_rate.rb
139
137
  - app/models/piggybak/shipping_calculator/free.rb
140
- - app/models/piggybak/shipping_calculator/pickup.rb
141
138
  - app/models/piggybak/shipping_calculator/range.rb
142
139
  - app/models/piggybak/shipping_method.rb
143
140
  - app/models/piggybak/shipping_method_value.rb
144
141
  - app/models/piggybak/state.rb
145
- - app/models/piggybak/tax_calculator.rb
146
142
  - app/models/piggybak/tax_calculator/percent.rb
147
143
  - app/models/piggybak/tax_method.rb
148
144
  - app/models/piggybak/tax_method_value.rb
@@ -180,6 +176,7 @@ files:
180
176
  - lib/acts_as_variant/base.rb
181
177
  - lib/currency.rb
182
178
  - lib/piggybak.rb
179
+ - lib/piggybak/config.rb
183
180
  - piggybak.gemspec
184
181
  homepage: http://github.com/stephskardal/piggybak
185
182
  licenses:
@@ -194,7 +191,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
194
191
  requirements:
195
192
  - - ">="
196
193
  - !ruby/object:Gem::Version
197
- hash: -4394646372034307498
194
+ hash: 2778086706911643141
198
195
  segments:
199
196
  - 0
200
197
  version: "0"
@@ -1,7 +0,0 @@
1
- module Piggybak
2
- class PaymentCalculator
3
- def self.authorize(*args)
4
- self::KLASS.authorize(*args)
5
- end
6
- end
7
- end
@@ -1,12 +0,0 @@
1
- module Piggybak
2
- class ShippingCalculator
3
- def self.available?(*args)
4
- false
5
- end
6
-
7
- def self.lookup(*args)
8
- { :available => false,
9
- :rate => 0.00 }
10
- end
11
- end
12
- end
@@ -1,23 +0,0 @@
1
- module Piggybak
2
- class ShippingCalculator::Pickup < ShippingCalculator
3
- KEYS = ["state_abbr", "rate"]
4
-
5
- def self.available?(method, object)
6
- abbr = method.metadata.detect { |t| t.key == "state_abbr" }.value
7
-
8
- if object.is_a?(Cart)
9
- state = State.find(object.extra_data["state_id"])
10
- return true if state && state.abbr == abbr
11
- else
12
- if object.billing_address && object.billing_address.state
13
- return object.billing_address.state.abbr == abbr
14
- end
15
- end
16
- return false
17
- end
18
-
19
- def self.rate(method, object)
20
- method.metadata.detect { |m| m.key == "rate" }.value.to_f.to_c
21
- end
22
- end
23
- end
@@ -1,7 +0,0 @@
1
- module Piggybak
2
- class TaxCalculator
3
- def self.available?(*args)
4
- false
5
- end
6
- end
7
- end