comable-core 0.6.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 (81) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +97 -0
  4. data/app/assets/javascripts/comable/application.js +13 -0
  5. data/app/assets/stylesheets/comable/application.css +13 -0
  6. data/app/controllers/concerns/comable/permitted_attributes.rb +15 -0
  7. data/app/helpers/comable/application_helper.rb +84 -0
  8. data/app/helpers/comable/products_helper.rb +82 -0
  9. data/app/mailers/comable/order_mailer.rb +18 -0
  10. data/app/models/comable/ability.rb +18 -0
  11. data/app/models/comable/address.rb +39 -0
  12. data/app/models/comable/category.rb +72 -0
  13. data/app/models/comable/image.rb +15 -0
  14. data/app/models/comable/order.rb +121 -0
  15. data/app/models/comable/order/associations.rb +22 -0
  16. data/app/models/comable/order/callbacks.rb +43 -0
  17. data/app/models/comable/order/morrisable.rb +20 -0
  18. data/app/models/comable/order/scopes.rb +17 -0
  19. data/app/models/comable/order/validations.rb +39 -0
  20. data/app/models/comable/order_item.rb +98 -0
  21. data/app/models/comable/order_item/csvable.rb +32 -0
  22. data/app/models/comable/page.rb +30 -0
  23. data/app/models/comable/payment.rb +87 -0
  24. data/app/models/comable/payment_method.rb +27 -0
  25. data/app/models/comable/product.rb +55 -0
  26. data/app/models/comable/product/csvable.rb +20 -0
  27. data/app/models/comable/shipment.rb +85 -0
  28. data/app/models/comable/shipment_method.rb +9 -0
  29. data/app/models/comable/stock.rb +71 -0
  30. data/app/models/comable/stock/csvable.rb +26 -0
  31. data/app/models/comable/store.rb +30 -0
  32. data/app/models/comable/theme.rb +25 -0
  33. data/app/models/comable/tracker.rb +17 -0
  34. data/app/models/comable/user.rb +130 -0
  35. data/app/models/concerns/comable/cart_owner.rb +94 -0
  36. data/app/models/concerns/comable/checkout.rb +85 -0
  37. data/app/models/concerns/comable/importable.rb +67 -0
  38. data/app/models/concerns/comable/liquidable.rb +12 -0
  39. data/app/models/concerns/comable/product/search.rb +41 -0
  40. data/app/models/concerns/comable/ransackable.rb +38 -0
  41. data/app/models/concerns/comable/role_owner.rb +15 -0
  42. data/app/models/concerns/comable/sku_choice.rb +19 -0
  43. data/app/models/concerns/comable/sku_item.rb +17 -0
  44. data/app/uploaders/image_uploader.rb +7 -0
  45. data/app/views/comable/order_mailer/complete.text.erb +42 -0
  46. data/config/initializers/comma.rb +8 -0
  47. data/config/locales/en.yml +424 -0
  48. data/config/locales/ja.yml +425 -0
  49. data/db/migrate/20131214194807_create_comable_products.rb +15 -0
  50. data/db/migrate/20140120032559_create_comable_users.rb +46 -0
  51. data/db/migrate/20140502060116_create_comable_stocks.rb +14 -0
  52. data/db/migrate/20140723175431_create_comable_orders.rb +20 -0
  53. data/db/migrate/20140723175810_create_comable_order_items.rb +19 -0
  54. data/db/migrate/20140817194104_create_comable_payment_methods.rb +13 -0
  55. data/db/migrate/20140921191416_create_comable_shipment_methods.rb +11 -0
  56. data/db/migrate/20140926063541_create_comable_stores.rb +11 -0
  57. data/db/migrate/20141024025526_create_comable_addresses.rb +17 -0
  58. data/db/migrate/20150111031228_create_comable_categories.rb +10 -0
  59. data/db/migrate/20150111031229_create_comable_products_categories.rb +8 -0
  60. data/db/migrate/20150112173706_create_comable_images.rb +9 -0
  61. data/db/migrate/20150423095210_create_comable_shipments.rb +13 -0
  62. data/db/migrate/20150511171940_create_comable_payments.rb +12 -0
  63. data/db/migrate/20150513185230_create_comable_trackers.rb +12 -0
  64. data/db/migrate/20150519080729_create_comable_pages.rb +17 -0
  65. data/db/migrate/20150612143226_create_comable_themes.rb +15 -0
  66. data/db/migrate/20150612143445_add_theme_id_to_comable_stores.rb +7 -0
  67. data/db/seeds.rb +5 -0
  68. data/db/seeds/comable/users.rb +51 -0
  69. data/lib/comable/core.rb +48 -0
  70. data/lib/comable/core/configuration.rb +22 -0
  71. data/lib/comable/core/engine.rb +50 -0
  72. data/lib/comable/deprecator.rb +26 -0
  73. data/lib/comable/payment_provider.rb +14 -0
  74. data/lib/comable/payment_provider/base.rb +42 -0
  75. data/lib/comable/payment_provider/general.rb +15 -0
  76. data/lib/comable/state_machine_patch.rb +32 -0
  77. data/lib/comma_extractor_extentions.rb +31 -0
  78. data/lib/generators/comable/install/install_generator.rb +133 -0
  79. data/lib/generators/comable/install/templates/config/initializers/comable.rb +31 -0
  80. data/lib/tasks/comable_tasks.rake +4 -0
  81. metadata +346 -0
@@ -0,0 +1,14 @@
1
+ class CreateComableStocks < ActiveRecord::Migration
2
+ def change
3
+ create_table :comable_stocks do |t|
4
+ t.references :product, null: false
5
+ t.string :code, null: false
6
+ t.integer :quantity, null: false, default: 0
7
+ t.string :sku_h_choice_name
8
+ t.string :sku_v_choice_name
9
+ t.timestamps null: false
10
+ end
11
+
12
+ add_index :comable_stocks, :code, unique: true
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ class CreateComableOrders < ActiveRecord::Migration
2
+ def change
3
+ create_table :comable_orders do |t|
4
+ t.references :user
5
+ t.string :guest_token
6
+ t.string :code
7
+ t.string :email
8
+ t.integer :payment_fee, null: false, default: 0
9
+ t.integer :shipment_fee, null: false, default: 0
10
+ t.integer :total_price
11
+ t.references :bill_address
12
+ t.references :ship_address
13
+ t.string :state
14
+ t.datetime :completed_at
15
+ t.timestamps null: false
16
+ end
17
+
18
+ add_index :comable_orders, :code, unique: true
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ class CreateComableOrderItems < ActiveRecord::Migration
2
+ def change
3
+ create_table :comable_order_items do |t|
4
+ t.references :order, null: false
5
+ t.references :stock, null: false
6
+ t.string :name, null: false
7
+ t.string :code, null: false
8
+ t.integer :price, null: false
9
+ t.string :sku_h_item_name
10
+ t.string :sku_v_item_name
11
+ t.string :sku_h_choice_name
12
+ t.string :sku_v_choice_name
13
+ t.integer :quantity, default: 1, null: false
14
+ t.timestamps null: false
15
+ end
16
+
17
+ add_index :comable_order_items, [:order_id, :stock_id], unique: true
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ class CreateComablePaymentMethods < ActiveRecord::Migration
2
+ def change
3
+ create_table :comable_payment_methods do |t|
4
+ t.string :name, null: false
5
+ t.string :payment_provider_type, null: false
6
+ t.integer :payment_provider_kind, null: false
7
+ t.integer :fee, null: false
8
+ t.integer :enable_price_from
9
+ t.integer :enable_price_to
10
+ t.timestamps null: false
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ class CreateComableShipmentMethods < ActiveRecord::Migration
2
+ def change
3
+ create_table :comable_shipment_methods do |t|
4
+ t.boolean :activated_flag, null: false, default: true
5
+ t.string :name, null: false
6
+ t.integer :fee, null: false
7
+ t.string :traking_url
8
+ t.timestamps null: false
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class CreateComableStores < ActiveRecord::Migration
2
+ def change
3
+ create_table :comable_stores do |t|
4
+ t.string :name
5
+ t.string :meta_keywords
6
+ t.string :meta_description
7
+ t.string :email
8
+ t.timestamps null: false
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ class CreateComableAddresses < ActiveRecord::Migration
2
+ def change
3
+ create_table :comable_addresses do |t|
4
+ t.references :user
5
+ t.string :family_name, null: false
6
+ t.string :first_name, null: false
7
+ t.string :zip_code, null: false
8
+ t.references :state
9
+ t.string :state_name, null: false
10
+ t.string :city, null: false
11
+ t.string :detail
12
+ t.string :phone_number, null: false
13
+ t.datetime :last_used_at
14
+ t.timestamps null: false
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ class CreateComableCategories < ActiveRecord::Migration
2
+ def change
3
+ create_table :comable_categories do |t|
4
+ t.string :name, null: false
5
+ t.string :ancestry, index: true
6
+ t.integer :position
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ class CreateComableProductsCategories < ActiveRecord::Migration
2
+ def change
3
+ create_table :comable_products_categories do |t|
4
+ t.references :product, null: false, index: true
5
+ t.references :category, null: false, index: true
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ class CreateComableImages < ActiveRecord::Migration
2
+ def change
3
+ create_table :comable_images do |t|
4
+ t.references :product, null: false, index: true
5
+ t.string :file, null: false
6
+ t.timestamps null: false
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ class CreateComableShipments < ActiveRecord::Migration
2
+ def change
3
+ create_table :comable_shipments do |t|
4
+ t.references :order, null: false
5
+ t.references :shipment_method, null: false
6
+ t.integer :fee, null: false
7
+ t.string :state, null: false
8
+ t.string :tracking_number
9
+ t.datetime :completed_at
10
+ t.timestamps null: false
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ class CreateComablePayments < ActiveRecord::Migration
2
+ def change
3
+ create_table :comable_payments do |t|
4
+ t.references :order, null: false
5
+ t.references :payment_method, null: false
6
+ t.integer :fee, null: false
7
+ t.string :state, null: false
8
+ t.datetime :completed_at
9
+ t.timestamps null: false
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ class CreateComableTrackers < ActiveRecord::Migration
2
+ def change
3
+ create_table :comable_trackers do |t|
4
+ t.boolean :activated_flag, null: false, default: true
5
+ t.string :name, null: false
6
+ t.string :tracker_id
7
+ t.text :code, null: false
8
+ t.string :place, null: false
9
+ t.timestamps null: false
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ class CreateComablePages < ActiveRecord::Migration
2
+ def change
3
+ create_table :comable_pages do |t|
4
+ t.string :title, null: false
5
+ t.text :content, null: false
6
+ t.string :page_title
7
+ t.string :meta_description
8
+ t.string :meta_keywords
9
+ t.string :slug, null: false
10
+ t.datetime :published_at
11
+
12
+ t.timestamps null: false
13
+ end
14
+
15
+ add_index :comable_pages, :slug, unique: true
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ class CreateComableThemes < ActiveRecord::Migration
2
+ def change
3
+ create_table :comable_themes do |t|
4
+ t.string :name, null: false
5
+ t.string :version, null: false
6
+ t.string :display
7
+ t.string :description
8
+ t.string :homepage
9
+ t.string :author
10
+ t.timestamps null: false
11
+ end
12
+
13
+ add_index :comable_themes, [:name, :version], unique: true
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ class AddThemeIdToComableStores < ActiveRecord::Migration
2
+ def change
3
+ change_table :comable_stores do |t|
4
+ t.references :theme
5
+ end
6
+ end
7
+ end
data/db/seeds.rb ADDED
@@ -0,0 +1,5 @@
1
+ seeds_path = File.join(File.dirname(__FILE__), 'seeds')
2
+
3
+ Dir.glob(File.join(seeds_path, '**/*.rb')).sort.each do |fixture_file|
4
+ require fixture_file
5
+ end
@@ -0,0 +1,51 @@
1
+ require 'highline/import'
2
+
3
+ def default_email
4
+ 'comable@example.com'
5
+ end
6
+
7
+ def default_password
8
+ 'password'
9
+ end
10
+
11
+ def ask_admin_email
12
+ if ENV['ADMIN_EMAIL']
13
+ ENV['ADMIN_EMAIL']
14
+ else
15
+ ask("Email [#{default_email}]: ") do |q|
16
+ q.echo = true
17
+ q.whitespace = :strip
18
+ end
19
+ end.presence || default_email
20
+ end
21
+
22
+ def ask_admin_password
23
+ if ENV['ADMIN_PASSWORD']
24
+ ENV['ADMIN_PASSWORD']
25
+ else
26
+ ask("Password [#{default_password}]: ") do |q|
27
+ q.echo = false
28
+ q.whitespace = :strip
29
+ end
30
+ end.presence || default_password
31
+ end
32
+
33
+ def create_admin_user
34
+ email = ask_admin_email
35
+ password = ask_admin_password
36
+
37
+ if Comable::User.where(email: email).exists?
38
+ puts "WARNING: The email address has already existed: #{email}"
39
+ else
40
+ Comable::User.with_role(:admin).new do |obj|
41
+ obj.email = email
42
+ obj.password = password
43
+ end.save!
44
+ end
45
+ end
46
+
47
+ if Comable::User.with_role(:admin).exists?
48
+ puts 'Admin user has already been previously created.'
49
+ else
50
+ create_admin_user
51
+ end
@@ -0,0 +1,48 @@
1
+ require 'devise'
2
+ require 'enumerize'
3
+ require 'state_machine'
4
+ require 'ancestry'
5
+ require 'acts_as_list'
6
+ require 'carrierwave'
7
+ require 'cancancan'
8
+ require 'comma'
9
+ require 'axlsx_rails'
10
+ require 'roo'
11
+ require 'liquid'
12
+ require 'liquid-rails'
13
+ require 'friendly_id'
14
+
15
+ require 'comable/core/configuration'
16
+ require 'comable/core/engine'
17
+
18
+ require 'comable/payment_provider'
19
+ require 'comable/state_machine_patch'
20
+ require 'comable/deprecator'
21
+
22
+ require 'comma_extractor_extentions'
23
+
24
+ module Comable
25
+ class << self
26
+ def setup(&_)
27
+ yield Comable::Config
28
+ end
29
+
30
+ def translate(key, options = {})
31
+ I18n.translate("comable.#{key}", options)
32
+ end
33
+
34
+ alias_method :t, :translate
35
+
36
+ def app_name
37
+ 'Comable'
38
+ end
39
+
40
+ def homepage
41
+ 'https://github.com/appirits/comable#comable'
42
+ end
43
+
44
+ def license
45
+ 'https://github.com/appirits/comable/blob/master/MIT-LICENSE'
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,22 @@
1
+ module Comable
2
+ module Core
3
+ module Configuration
4
+ mattr_accessor :devise_strategies
5
+ @@devise_strategies = {
6
+ user: [:database_authenticatable, :registerable, :recoverable, :rememberable, :trackable]
7
+ }
8
+
9
+ mattr_accessor :products_per_page
10
+ @@products_per_page = 15
11
+
12
+ mattr_accessor :orders_per_page
13
+ @@orders_per_page = 5
14
+
15
+ mattr_accessor :export_xlsx_header_style
16
+ @@export_xlsx_header_style = { bg_color: '00000000', fg_color: 'ffffffff', alignment: { horizontal: :center }, bold: true }
17
+
18
+ mattr_accessor :export_xlsx_style
19
+ @@export_xlsx_style = nil
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,50 @@
1
+ module Comable
2
+ module Core
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace Comable
5
+
6
+ config.generators do |g|
7
+ g.test_framework :rspec, fixture: true
8
+ g.fixture_replacement :factory_girl, dir: 'spec/factories'
9
+ end
10
+
11
+ config.autoload_paths << "#{config.root}/app/models/concerns" if Rails::VERSION::MAJOR == 3
12
+
13
+ initializer 'comable.congiguration', before: :load_config_initializers do |app|
14
+ app.config.comable = Comable::Core::Configuration
15
+ Comable::Config = app.config.comable
16
+ end
17
+
18
+ # refs: https://github.com/plataformatec/devise/wiki/How-To:-Use-devise-inside-a-mountable-engine
19
+ initializer 'comable.devise.setup', before: :load_config_initializers do
20
+ Devise.setup do |config|
21
+ config.mailer_sender = 'comable@example.com'
22
+
23
+ require 'devise/orm/active_record'
24
+
25
+ config.case_insensitive_keys = [:email]
26
+ config.strip_whitespace_keys = [:email]
27
+ config.skip_session_storage = [:http_auth]
28
+ config.stretches = Rails.env.test? ? 1 : 10
29
+ config.reconfirmable = true
30
+ config.password_length = 8..128
31
+ config.reset_password_within = 6.hours
32
+ config.sign_out_via = :delete
33
+
34
+ # ==> Mountable engine configurations
35
+ config.router_name = :comable
36
+ config.parent_controller = 'Comable::ApplicationController'
37
+ end
38
+ end
39
+
40
+ initializer 'comable.devise.warden.manager' do
41
+ Warden::Manager.after_set_user except: :fetch do |record, warden, options|
42
+ if record.respond_to?(:after_set_user) && warden.authenticated?(options[:scope])
43
+ record.with_cookies(warden.cookies)
44
+ record.after_set_user
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,26 @@
1
+ if Rails::VERSION::MAJOR > 3
2
+ module Comable
3
+ class Deprecator < ActiveSupport::Deprecation
4
+ def initialize(deprecation_horizon = '0.4.0', gem_name = 'Comable')
5
+ super
6
+ end
7
+ end
8
+ end
9
+ else
10
+ # TODO: Deprecated itself!
11
+ module Comable
12
+ class Deprecator
13
+ include Singleton
14
+ end
15
+ end
16
+
17
+ class Module
18
+ def deprecate_with_deprecator(*method_names)
19
+ options = method_names.extract_options!
20
+ options.delete(:deprecator) if options.present?
21
+ deprecate_without_deprecator
22
+ end
23
+
24
+ alias_method_chain :deprecate, :deprecator
25
+ end
26
+ end