Skip to content

Instantly share code, notes, and snippets.

@psy-q
Created January 2, 2012 14:27
Show Gist options
  • Select an option

  • Save psy-q/1550877 to your computer and use it in GitHub Desktop.

Select an option

Save psy-q/1550877 to your computer and use it in GitHub Desktop.
class ShippingCalculators::ShippingCalculator < ActiveRecord::Base
set_table_name 'shipping_calculators'
serialize :configuration, OpenStruct
belongs_to :tax_class
def initialize
@cost = BigDecimal.new("0")
@taxes = BigDecimal.new("0")
@gross_cost = BigDecimal.new("0")
@package_count = 0
end
# Define this method on the child classes
def calculate_for
end
def cost
return @cost
end
def taxes
return @taxes
end
def package_count
return @package_count
end
end
class ShippingCalculators::WeightBased < ShippingCalculators::ShippingCalculator
def calculate_for(document)
# foo, bar, stuff goes here
end
end
class CreateShippingCalculators < ActiveRecord::Migration
def change
create_table :shipping_calculators do |t|
t.string :name
t.text :configuration
t.string :type
t.integer :tax_class_id
end
end
end
mysql> desc shipping_calculators;
+---------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | YES | | NULL | |
| configuration | text | YES | | NULL | |
| type | varchar(255) | YES | | NULL | |
| tax_class_id | int(11) | YES | | NULL | |
+---------------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment