comable 0.0.3 → 0.1.0

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -0
  3. data/Rakefile +60 -4
  4. data/lib/comable/version.rb +14 -1
  5. data/lib/comable.rb +4 -8
  6. metadata +18 -244
  7. data/app/assets/javascripts/comable/application.js +0 -13
  8. data/app/assets/stylesheets/comable/application.css +0 -13
  9. data/app/controllers/comable/application_controller.rb +0 -5
  10. data/app/controllers/comable/carts_controller.rb +0 -40
  11. data/app/controllers/comable/orders_controller.rb +0 -115
  12. data/app/controllers/comable/products_controller.rb +0 -11
  13. data/app/helpers/comable/application_helper.rb +0 -18
  14. data/app/helpers/comable/products_helper.rb +0 -55
  15. data/app/models/comable/customer.rb +0 -97
  16. data/app/models/comable/order.rb +0 -93
  17. data/app/models/comable/order_delivery.rb +0 -16
  18. data/app/models/comable/order_detail.rb +0 -42
  19. data/app/models/comable/payment.rb +0 -26
  20. data/app/models/comable/product.rb +0 -32
  21. data/app/models/comable/stock.rb +0 -82
  22. data/app/views/comable/carts/show.slim +0 -22
  23. data/app/views/comable/orders/confirm.slim +0 -25
  24. data/app/views/comable/orders/create.slim +0 -5
  25. data/app/views/comable/orders/delivery.slim +0 -8
  26. data/app/views/comable/orders/new.slim +0 -4
  27. data/app/views/comable/orders/orderer.slim +0 -7
  28. data/app/views/comable/orders/payment.slim +0 -12
  29. data/app/views/comable/products/index.slim +0 -11
  30. data/app/views/comable/products/show.slim +0 -21
  31. data/app/views/layouts/comable/application.slim +0 -11
  32. data/config/locales/ja.yml +0 -11
  33. data/config/routes.rb +0 -23
  34. data/db/migrate/20131214194807_create_comable_products.rb +0 -14
  35. data/db/migrate/20140120032559_create_comable_customers.rb +0 -8
  36. data/db/migrate/20140502060116_create_comable_stocks.rb +0 -14
  37. data/db/migrate/20140723175431_create_comable_orders.rb +0 -15
  38. data/db/migrate/20140723175624_create_comable_order_deliveries.rb +0 -9
  39. data/db/migrate/20140723175810_create_comable_order_details.rb +0 -12
  40. data/db/migrate/20140817194104_create_comable_payments.rb +0 -11
  41. data/lib/comable/cart_owner.rb +0 -79
  42. data/lib/comable/decoratable.rb +0 -10
  43. data/lib/comable/engine.rb +0 -7
  44. data/lib/comable/errors.rb +0 -4
  45. data/lib/comable/migration.rb +0 -16
  46. data/lib/comable/payment_method/base.rb +0 -26
  47. data/lib/comable/payment_method/general.rb +0 -15
  48. data/lib/comable/payment_method.rb +0 -14
  49. data/lib/tasks/comable_tasks.rake +0 -4
  50. data/lib/tasks/comable_yardoc.task +0 -14
@@ -1,9 +0,0 @@
1
- class CreateComableOrderDeliveries < Comable::Migration
2
- def change
3
- create_table :comable_order_deliveries do |t|
4
- t.integer :comable_order_id, null: false
5
- t.string :family_name
6
- t.string :first_name
7
- end
8
- end
9
- end
@@ -1,12 +0,0 @@
1
- class CreateComableOrderDetails < Comable::Migration
2
- def change
3
- create_table :comable_order_details do |t|
4
- t.integer :comable_order_delivery_id, null: false
5
- t.integer :comable_stock_id, null: false
6
- t.integer :price
7
- t.integer :quantity, default: 1, null: false
8
- end
9
-
10
- add_index :comable_order_details, [:comable_order_delivery_id, :comable_stock_id], unique: true, name: :comable_order_details_idx_01
11
- end
12
- end
@@ -1,11 +0,0 @@
1
- class CreateComablePayments < ActiveRecord::Migration
2
- def change
3
- create_table :comable_payments do |t|
4
- t.string :name, null: false
5
- t.string :payment_method_type, null: false
6
- t.integer :payment_method_kind, null: false
7
- t.integer :enable_price_from
8
- t.integer :enable_price_to
9
- end
10
- end
11
- end
@@ -1,79 +0,0 @@
1
- module Comable
2
- module CartOwner
3
- def add_cart_item(obj, quantity: 1)
4
- process_cart_item(obj) do |stock|
5
- add_stock_to_cart(stock, quantity)
6
- end
7
- end
8
-
9
- def remove_cart_item(obj, quantity: -1)
10
- add_cart_item(obj, quantity: quantity)
11
- end
12
-
13
- def reset_cart_item(obj, quantity: 0)
14
- process_cart_item(obj) do |stock|
15
- reset_stock_from_cart(stock, quantity)
16
- end
17
- end
18
-
19
- def cart_items
20
- fail 'You should implement cart_items method.'
21
- end
22
-
23
- def cart
24
- Cart.new(cart_items)
25
- end
26
-
27
- class Cart < Array
28
- def price
29
- sum(&:current_subtotal_price)
30
- end
31
- end
32
-
33
- private
34
-
35
- def process_cart_item(obj)
36
- case obj
37
- when Comable::Product
38
- yield obj.stocks.first
39
- when Comable::Stock
40
- yield obj
41
- when Array
42
- obj.map { |item| yield item }
43
- else
44
- fail
45
- end
46
- end
47
-
48
- def add_stock_to_cart(stock, quantity)
49
- fail I18n.t('comable.carts.product_not_stocked') if stock.soldout?
50
-
51
- cart_items = find_cart_items_by(stock)
52
- if cart_items.any?
53
- cart_item = cart_items.first
54
- cart_item.quantity += quantity
55
- (cart_item.quantity > 0) ? cart_item.save : cart_item.destroy
56
- else
57
- cart_items.create(quantity: quantity)
58
- end
59
- end
60
-
61
- def reset_stock_from_cart(stock, quantity)
62
- cart_items = find_cart_items_by(stock)
63
- if quantity > 0
64
- return add_stock_to_cart(stock, quantity) if cart_items.empty?
65
- cart_item = cart_items.first
66
- cart_item.quantity = quantity
67
- cart_item.save
68
- else
69
- return false if cart_items.empty?
70
- cart_item.destroy
71
- end
72
- end
73
-
74
- def find_cart_items_by(stock)
75
- fail I18n.t('comable.carts.product_not_found') unless stock.is_a?(Comable::Stock)
76
- cart_items.where(Comable::Stock.table_name.singularize.foreign_key => stock.id)
77
- end
78
- end
79
- end
@@ -1,10 +0,0 @@
1
- module Comable
2
- module Decoratable
3
- def self.included(base)
4
- # refs: http://edgeguides.rubyonrails.org/engines.html#overriding-models-and-controllers
5
- Dir.glob(Rails.root + "app/decorators/comable/#{base.name.demodulize.underscore}_decorator*.rb").each do |c|
6
- require_dependency(c)
7
- end
8
- end
9
- end
10
- end
@@ -1,7 +0,0 @@
1
- require 'slim'
2
-
3
- module Comable
4
- class Engine < ::Rails::Engine
5
- isolate_namespace Comable
6
- end
7
- end
@@ -1,4 +0,0 @@
1
- module Comable
2
- class InvalidOrder < StandardError
3
- end
4
- end
@@ -1,16 +0,0 @@
1
- module Comable
2
- class Migration < ActiveRecord::Migration
3
- def self.define_add_column_safety_method_for(type)
4
- define_method "add_column_safety_to_#{type.to_s.pluralize}" do |column_name, type_name, options = {}|
5
- column_name_sym = column_name.to_sym
6
- return if Utusemi.config.map(type).attributes[column_name_sym]
7
- add_column Comable.const_get(type.to_s.classify).table_name, column_name_sym, type_name, options
8
- end
9
- end
10
-
11
- COMABLE_TYPES = %w( product stock customer order order_delivery order_detail )
12
- COMABLE_TYPES.each do |type|
13
- define_add_column_safety_method_for(type)
14
- end
15
- end
16
- end
@@ -1,26 +0,0 @@
1
- module Comable
2
- module PaymentMethod
3
- class Base
4
- class << self
5
- def name_symbol
6
- name.demodulize.underscore.to_sym
7
- end
8
-
9
- def display_name
10
- please_implement_method
11
- end
12
-
13
- def kind
14
- please_implement_method
15
- end
16
-
17
- private
18
-
19
- def please_implement_method
20
- calling_method_name = caller_locations(1, 1).first.label
21
- fail "You should implement '#{calling_method_name}' method in #{name}."
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,15 +0,0 @@
1
- module Comable
2
- module PaymentMethod
3
- class General < Base
4
- class << self
5
- def display_name
6
- '汎用決済モジュール'
7
- end
8
-
9
- def kind
10
- { none: 'なし' }
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,14 +0,0 @@
1
- require 'comable/payment_method/base'
2
- require 'comable/payment_method/general'
3
-
4
- module Comable
5
- module PaymentMethod
6
- class << self
7
- def all
8
- (constants - [:Base]).map do |constant_name|
9
- const_get(constant_name)
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :comable do
3
- # # Task goes here
4
- # end
@@ -1,14 +0,0 @@
1
- require 'yard'
2
- require 'yard/rake/yardoc_task'
3
-
4
- YARD::Rake::YardocTask.new do |t|
5
- t.files = %w(
6
- app/models/**/*.rb
7
- app/controllers/**/*.rb
8
- app/helpers/**/*.rb
9
- app/mailers/**/*.rb
10
- lib/**/*.rb
11
- )
12
- t.options = []
13
- t.options = %w(--debug --verbose) if $trace
14
- end