unidom-shopping 2.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19549b0781e7a5a0740dacc5edaaf663856b27ab1e9fa75945af8cd885254a34
4
- data.tar.gz: 5bb273a96325c1d43f22cea07b07f69fab9a788cbfbb16e22833962a791f4f78
3
+ metadata.gz: edaaa6056e98d80899e568f4e560c3ddb5b523ee9199485a9ae8a6205aad0cab
4
+ data.tar.gz: 55661d4d5ffb161836913e4ca20e32a109194f951262231c8b815d137f7a4f3b
5
5
  SHA512:
6
- metadata.gz: d0d760891d68cb4fb09c15f6807a566d393362e0ea8ecbd7fecd648f57dc6c4b0be8df067b9cbd70e68ca5b3aeb86b768f29fe9c994af22040b3528b56c0389b
7
- data.tar.gz: b3e238a6198eb80537d64156a06a21502e99ad535245c917f11f9cc48f0307b5fbdb10c02409d5ab291c309d510c9c981a4e28fc92c18df264b627694235a91f
6
+ metadata.gz: 1450d0f6f35b1ddee35d628dfe87e41bf93f42e6e7602f8f065543f398f1b2d80d8086e2eb5e224b49ed9e7ec17cc6680d70d91ba718439cf188a97efdfe1108
7
+ data.tar.gz: 919daf5e47c28c18f599dc7f20e173aef698f9771c6c87786b06573ada9e1889fd2f892b9597780dbda9f7593b647669db5443912b2ec741d88f86994343ad09
@@ -1,6 +1,12 @@
1
1
  ##
2
2
  # Application controller 是模块内所有控制器的基类。
3
3
 
4
- class Unidom::Shopping::ApplicationController < ActionController::Base
5
- protect_from_forgery with: :exception
4
+ module Unidom
5
+ module Shopping
6
+
7
+ class ApplicationController < ActionController::Base
8
+ protect_from_forgery with: :exception
9
+ end
10
+
11
+ end
6
12
  end
@@ -1,2 +1,8 @@
1
- module Unidom::Shopping::ApplicationHelper
1
+ module Unidom
2
+ module Shopping
3
+
4
+ module ApplicationHelper
5
+ end
6
+
7
+ end
2
8
  end
@@ -1,5 +1,11 @@
1
1
  ##
2
2
  # Application job 是模块内所有异步任务的基类。
3
3
 
4
- class Unidom::Shopping::ApplicationJob < ActiveJob::Base
4
+ module Unidom
5
+ module Shopping
6
+
7
+ class ApplicationJob < ActiveJob::Base
8
+ end
9
+
10
+ end
5
11
  end
@@ -1,7 +1,13 @@
1
1
  ##
2
2
  # Application mailer 是模块内所有电子邮件发送类的基类。
3
3
 
4
- class Unidom::Shopping::ApplicationMailer < ActionMailer::Base
5
- default from: 'from@example.com'
6
- layout 'mailer'
4
+ module Unidom
5
+ module Shopping
6
+
7
+ class ApplicationMailer < ActionMailer::Base
8
+ default from: 'from@example.com'
9
+ layout 'mailer'
10
+ end
11
+
12
+ end
7
13
  end
@@ -1,6 +1,12 @@
1
1
  ##
2
2
  # Application record 是模块内所有模型的抽象基类。
3
3
 
4
- class Unidom::Shopping::ApplicationRecord < ActiveRecord::Base
5
- self.abstract_class = true
4
+ module Unidom
5
+ module Shopping
6
+
7
+ class ApplicationRecord < ActiveRecord::Base
8
+ self.abstract_class = true
9
+ end
10
+
11
+ end
6
12
  end
@@ -1,33 +1,41 @@
1
1
  ##
2
2
  # As Cart Shopper 是购物车所有者的领域逻辑关注点。
3
3
 
4
- module Unidom::Shopping::Concerns::AsCartShopper
4
+ module Unidom
5
+ module Shopping
6
+ module Concerns
5
7
 
6
- extend ActiveSupport::Concern
7
- include Unidom::Common::Concerns::ArgumentValidation
8
+ module AsCartShopper
8
9
 
9
- included do |includer|
10
+ extend ActiveSupport::Concern
11
+ include Unidom::Common::Concerns::ArgumentValidation
10
12
 
11
- has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shopper
13
+ included do |includer|
12
14
 
13
- ##
14
- # 以购物者的身份,从指定的商店 from 获取购物车。时间为 at ,缺省为当前时间。如:
15
- # current_person.get_cart! from: shop
16
- def get_cart!(from: nil, at: Time.now)
15
+ has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shopper
17
16
 
18
- assert_present! :from, from
17
+ ##
18
+ # 以购物者的身份,从指定的商店 from 获取购物车。时间为 at ,缺省为当前时间。如:
19
+ # current_person.get_cart! from: shop
20
+ def get_cart!(from: nil, at: Time.now)
19
21
 
20
- shopping_carts.shop_is(from).valid_at(now: at).alive.first_or_create! opened_at: at
22
+ assert_present! :from, from
21
23
 
22
- end
24
+ shopping_carts.shop_is(from).valid_at(now: at).alive.first_or_create! opened_at: at
23
25
 
24
- def get_cart?(from: nil, at: Time.now)
25
- shopping_carts.shop_is(from).valid_at(now: at).alive.exists?
26
- end
26
+ end
27
27
 
28
- end
28
+ def get_cart?(from: nil, at: Time.now)
29
+ shopping_carts.shop_is(from).valid_at(now: at).alive.exists?
30
+ end
29
31
 
30
- module ClassMethods
31
- end
32
+ end
32
33
 
34
+ module ClassMethods
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
33
41
  end
@@ -1,40 +1,48 @@
1
1
  ##
2
2
  # As Item Shopper 是购物项所有者的领域逻辑关注点。
3
3
 
4
- module Unidom::Shopping::Concerns::AsItemShopper
4
+ module Unidom
5
+ module Shopping
6
+ module Concerns
5
7
 
6
- extend ActiveSupport::Concern
7
- include Unidom::Common::Concerns::ArgumentValidation
8
+ module AsItemShopper
8
9
 
9
- included do |includer|
10
+ extend ActiveSupport::Concern
11
+ include Unidom::Common::Concerns::ArgumentValidation
10
12
 
11
- has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopper
13
+ included do |includer|
12
14
 
13
- ##
14
- # 以购物者的身份,将商品 it ,放入购物车 into 。购物时间是 at ,缺省为当前时间。单价是 unit_price ,缺省为 0 。数量是 quantity ,缺省为 1 。如:
15
- # current_person.add! coca_cola, into: shopping_cart, unit_price: 3.50, quantity: 3
16
- def add!(it, into: nil, at: Time.now, unit_price: 0, quantity: 1)
15
+ has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopper
17
16
 
18
- assert_present! :it, it
17
+ ##
18
+ # 以购物者的身份,将商品 it ,放入购物车 into 。购物时间是 at ,缺省为当前时间。单价是 unit_price ,缺省为 0 。数量是 quantity ,缺省为 1 。如:
19
+ # current_person.add! coca_cola, into: shopping_cart, unit_price: 3.50, quantity: 3
20
+ def add!(it, into: nil, at: Time.now, unit_price: 0, quantity: 1)
19
21
 
20
- query = shopping_items.shopping_cart_is(into).shopped_is(it).valid_at(now: at).alive
21
- item = query.first
22
- if item.present?
23
- item.unit_price = unit_price
24
- item.increment! :quantity, quantity
25
- else
26
- item = shopping_items.create! shopping_cart: into, shopped: it, unit_price: unit_price, quantity: quantity, opened_at: at
27
- end
28
- item
29
- end
22
+ assert_present! :it, it
30
23
 
31
- def add?(it, into: nil, at: Time.now)
32
- shopping_items.shopping_cart_is(into).shopped_is(it).valid_at(now: at).alive.exists?
33
- end
24
+ query = shopping_items.shopping_cart_is(into).shopped_is(it).valid_at(now: at).alive
25
+ item = query.first
26
+ if item.present?
27
+ item.unit_price = unit_price
28
+ item.increment! :quantity, quantity
29
+ else
30
+ item = shopping_items.create! shopping_cart: into, shopped: it, unit_price: unit_price, quantity: quantity, opened_at: at
31
+ end
32
+ item
33
+ end
34
34
 
35
- end
35
+ def add?(it, into: nil, at: Time.now)
36
+ shopping_items.shopping_cart_is(into).shopped_is(it).valid_at(now: at).alive.exists?
37
+ end
36
38
 
37
- module ClassMethods
38
- end
39
+ end
39
40
 
41
+ module ClassMethods
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
40
48
  end
@@ -1,24 +1,32 @@
1
1
  ##
2
2
  # As Shop 是购物场所的领域逻辑关注点。
3
3
 
4
- module Unidom::Shopping::Concerns::AsShop
4
+ module Unidom
5
+ module Shopping
6
+ module Concerns
5
7
 
6
- extend ActiveSupport::Concern
8
+ module AsShop
7
9
 
8
- included do |includer|
10
+ extend ActiveSupport::Concern
9
11
 
10
- has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shop
12
+ included do |includer|
11
13
 
12
- ##
13
- # 从当前商店中,获取购物车。购物者为 by 。获取时间为 at ,缺省为当前时间。如:
14
- # shop.get_cart! by: current_person
15
- def get_cart!(by: nil, at: Time.now)
16
- shopping_carts.shopped_by(by).valid_at(now: at).alive.first_or_create! opened_at: at
17
- end
14
+ has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shop
18
15
 
19
- end
16
+ ##
17
+ # 从当前商店中,获取购物车。购物者为 by 。获取时间为 at ,缺省为当前时间。如:
18
+ # shop.get_cart! by: current_person
19
+ def get_cart!(by: nil, at: Time.now)
20
+ shopping_carts.shopped_by(by).valid_at(now: at).alive.first_or_create! opened_at: at
21
+ end
20
22
 
21
- module ClassMethods
22
- end
23
+ end
24
+
25
+ module ClassMethods
26
+ end
23
27
 
28
+ end
29
+
30
+ end
31
+ end
24
32
  end
@@ -1,40 +1,48 @@
1
1
  ##
2
2
  # As Shopped 是被购买的商品的领域逻辑关注点。
3
3
 
4
- module Unidom::Shopping::Concerns::AsShopped
5
-
6
- extend ActiveSupport::Concern
7
-
8
- included do |includer|
9
-
10
- has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopped
11
-
12
- ##
13
- # 将当前商品放入购物车 into ,购物者是 by 。购物时间是 at ,缺省为当前时间。单价是 unit_price ,缺省为 0 。数量是 quantity ,缺省为 1 。如:
14
- # coca_cola.is_added! into: shopping_cart, by: current_person, unit_price: 3.50, quantity: 2
15
- def is_added!(into: nil, by: nil, at: Time.now, unit_price: 0, quantity: 1)
16
- query = shopping_items.shopping_cart_is(into).valid_at(now: at).alive
17
- item = query.first
18
- if item.present?
19
- item.unit_price = unit_price
20
- item.shopper = by
21
- item.increment! :quantity, quantity
22
- else
23
- item = shopping_items.create! shopping_cart: into, shopper: by, unit_price: unit_price, quantity: quantity, opened_at: at
4
+ module Unidom
5
+ module Shopping
6
+ module Concerns
7
+
8
+ module AsShopped
9
+
10
+ extend ActiveSupport::Concern
11
+
12
+ included do |includer|
13
+
14
+ has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopped
15
+
16
+ ##
17
+ # 将当前商品放入购物车 into ,购物者是 by 。购物时间是 at ,缺省为当前时间。单价是 unit_price ,缺省为 0 。数量是 quantity ,缺省为 1 。如:
18
+ # coca_cola.is_added! into: shopping_cart, by: current_person, unit_price: 3.50, quantity: 2
19
+ def is_added!(into: nil, by: nil, at: Time.now, unit_price: 0, quantity: 1)
20
+ query = shopping_items.shopping_cart_is(into).valid_at(now: at).alive
21
+ item = query.first
22
+ if item.present?
23
+ item.unit_price = unit_price
24
+ item.shopper = by
25
+ item.increment! :quantity, quantity
26
+ else
27
+ item = shopping_items.create! shopping_cart: into, shopper: by, unit_price: unit_price, quantity: quantity, opened_at: at
28
+ end
29
+ item
30
+ end
31
+
32
+ def is_added?(into: nil, by: nil, at: Time.now)
33
+ query = shopping_items.shopping_cart_is(into)
34
+ query = query.shopped_by(by) if by.present?
35
+ query = query.valid_at(now: at).alive
36
+ query.exists?
37
+ end
38
+
39
+ end
40
+
41
+ module ClassMethods
42
+ end
43
+
24
44
  end
25
- item
26
- end
27
45
 
28
- def is_added?(into: nil, by: nil, at: Time.now)
29
- query = shopping_items.shopping_cart_is(into)
30
- query = query.shopped_by(by) if by.present?
31
- query = query.valid_at(now: at).alive
32
- query.exists?
33
46
  end
34
-
35
47
  end
36
-
37
- module ClassMethods
38
- end
39
-
40
48
  end
@@ -1,34 +1,40 @@
1
1
  ##
2
2
  # Shopping Cart 是购物车。
3
3
 
4
- class Unidom::Shopping::ShoppingCart < Unidom::Shopping::ApplicationRecord
4
+ module Unidom
5
+ module Shopping
5
6
 
6
- self.table_name = 'unidom_shopping_carts'
7
+ class ShoppingCart < ApplicationRecord
7
8
 
8
- include Unidom::Common::Concerns::ModelExtension
9
+ self.table_name = 'unidom_shopping_carts'
9
10
 
10
- belongs_to :shopper, polymorphic: true
11
- belongs_to :shop, polymorphic: true
11
+ include Unidom::Common::Concerns::ModelExtension
12
12
 
13
- has_many :items, class_name: 'Unidom::Shopping::ShoppingItem'
13
+ belongs_to :shopper, polymorphic: true
14
+ belongs_to :shop, polymorphic: true
14
15
 
15
- scope :shopped_by, ->(shopper) { where shopper: shopper }
16
- scope :shop_is, ->(shop) { where shop: shop }
16
+ has_many :items, class_name: 'Unidom::Shopping::ShoppingItem'
17
17
 
18
- ##
19
- # 将商品 shopped 放入购物车。购物者为 by 。单价为 unit_price ,缺省值为 0 。数量为 quantity ,缺省值是 1 。时间为 at ,缺省为当前时间。如:
20
- # shopping_cart.add! coca_cola, by: current_person, unit_price: 3.50, quantity: 2
21
- def add!(shopped, by: nil, unit_price: 0, quantity: 1, at: Time.now)
18
+ scope :shopped_by, ->(shopper) { where shopper: shopper }
19
+ scope :shop_is, ->(shop) { where shop: shop }
22
20
 
23
- assert_present! :shopped, shopped
21
+ ##
22
+ # 将商品 shopped 放入购物车。购物者为 by 。单价为 unit_price ,缺省值为 0 。数量为 quantity ,缺省值是 1 。时间为 at ,缺省为当前时间。如:
23
+ # shopping_cart.add! coca_cola, by: current_person, unit_price: 3.50, quantity: 2
24
+ def add!(shopped, by: nil, unit_price: 0, quantity: 1, at: Time.now)
24
25
 
25
- item = items.shopped_is(shopped).valid_at.alive.first
26
- if item.present?
27
- item.attributes = { shopper: by||shopper, unit_price: unit_price, quantity: quantity+item.quantity }
28
- item.save!
29
- else
30
- items.create! shopped: shopped, shopper: by||shopper, unit_price: unit_price, quantity: quantity, opened_at: at
31
- end
32
- end
26
+ assert_present! :shopped, shopped
27
+
28
+ item = items.shopped_is(shopped).valid_at.alive.first
29
+ if item.present?
30
+ item.attributes = { shopper: by||shopper, unit_price: unit_price, quantity: quantity+item.quantity }
31
+ item.save!
32
+ else
33
+ items.create! shopped: shopped, shopper: by||shopper, unit_price: unit_price, quantity: quantity, opened_at: at
34
+ end
35
+ end
33
36
 
34
- end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Shopping::ShoppingCart'
37
+ end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Shopping::ShoppingCart'
38
+
39
+ end
40
+ end
@@ -1,21 +1,27 @@
1
1
  ##
2
2
  # Shopping Item 是购物项。
3
3
 
4
- class Unidom::Shopping::ShoppingItem < Unidom::Shopping::ApplicationRecord
4
+ module Unidom
5
+ module Shopping
5
6
 
6
- self.table_name = 'unidom_shopping_items'
7
+ class ShoppingItem < ApplicationRecord
7
8
 
8
- include Unidom::Common::Concerns::ModelExtension
9
+ self.table_name = 'unidom_shopping_items'
9
10
 
10
- validates :unit_price, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: Unidom::Common::MAXIMUM_AMOUNT }
11
- validates :quantity, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: Unidom::Common::MAXIMUM_AMOUNT }
11
+ include Unidom::Common::Concerns::ModelExtension
12
12
 
13
- belongs_to :shopping_cart, class_name: 'Unidom::Shopping::ShoppingCart'
14
- belongs_to :shopper, polymorphic: true
15
- belongs_to :shopped, polymorphic: true
13
+ validates :unit_price, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: Unidom::Common::MAXIMUM_AMOUNT }
14
+ validates :quantity, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: Unidom::Common::MAXIMUM_AMOUNT }
16
15
 
17
- scope :shopping_cart_is, ->(shopping_cart) { where shopping_cart: shopping_cart }
18
- scope :shopped_by, ->(shopper) { where shopper: shopper }
19
- scope :shopped_is, ->(shopped) { where shopped: shopped }
16
+ belongs_to :shopping_cart, class_name: 'Unidom::Shopping::ShoppingCart'
17
+ belongs_to :shopper, polymorphic: true
18
+ belongs_to :shopped, polymorphic: true
20
19
 
21
- end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Shopping::ShoppingItem'
20
+ scope :shopping_cart_is, ->(shopping_cart) { where shopping_cart: shopping_cart }
21
+ scope :shopped_by, ->(shopper) { where shopper: shopper }
22
+ scope :shopped_is, ->(shopped) { where shopped: shopped }
23
+
24
+ end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Shopping::ShoppingItem'
25
+
26
+ end
27
+ end
@@ -2,7 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Unidom Shopping</title>
5
- <%= stylesheet_link_tag "unidom/shopping/application", media: "all" %>
5
+ <%= stylesheet_link_tag 'unidom/shopping/application', media: 'all' %>
6
6
  <%= csrf_meta_tags %>
7
7
  </head>
8
8
  <body>
@@ -1,4 +1,4 @@
1
- class CreateUnidomShoppingCarts < ActiveRecord::Migration
1
+ class CreateUnidomShoppingCarts < ActiveRecord::Migration[6.0]
2
2
 
3
3
  def change
4
4
 
@@ -9,7 +9,7 @@ class CreateUnidomShoppingCarts < ActiveRecord::Migration
9
9
  t.references :shop, type: :uuid, null: false,
10
10
  polymorphic: { null: false, default: '', limit: 200 }
11
11
 
12
- t.column :state, 'char(1)', null: false, default: 'C'
12
+ t.column :state, 'char(1)', null: false, default: Unidom::Common::STATE
13
13
  t.datetime :opened_at, null: false, default: Unidom::Common::OPENED_AT
14
14
  t.datetime :closed_at, null: false, default: Unidom::Common::CLOSED_AT
15
15
  t.boolean :defunct, null: false, default: false
@@ -1,4 +1,4 @@
1
- class CreateUnidomShoppingItems < ActiveRecord::Migration
1
+ class CreateUnidomShoppingItems < ActiveRecord::Migration[6.0]
2
2
 
3
3
  def change
4
4
 
@@ -13,7 +13,7 @@ class CreateUnidomShoppingItems < ActiveRecord::Migration
13
13
  t.decimal :unit_price, null: false, default: 0.0, precision: 12, scale: 2
14
14
  t.decimal :quantity, null: false, default: 0.0, precision: 12, scale: 2
15
15
 
16
- t.column :state, 'char(1)', null: false, default: 'C'
16
+ t.column :state, 'char(1)', null: false, default: Unidom::Common::STATE
17
17
  t.datetime :opened_at, null: false, default: Unidom::Common::OPENED_AT
18
18
  t.datetime :closed_at, null: false, default: Unidom::Common::CLOSED_AT
19
19
  t.boolean :defunct, null: false, default: false
@@ -23,7 +23,7 @@ class CreateUnidomShoppingItems < ActiveRecord::Migration
23
23
 
24
24
  end
25
25
 
26
- add_index :unidom_shopping_items, :shopping_cart_id
26
+ #add_index :unidom_shopping_items, :shopping_cart_id
27
27
  add_index :unidom_shopping_items, :shopper_id
28
28
  add_index :unidom_shopping_items, :shopped_id
29
29
 
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Shopping
3
- VERSION = '2.0'.freeze
3
+ VERSION = '2.0.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-shopping
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.0'
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-20 00:00:00.000000000 Z
11
+ date: 2021-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common
@@ -68,11 +68,11 @@ files:
68
68
  - lib/unidom/shopping/types_rspec.rb
69
69
  - lib/unidom/shopping/validators_rspec.rb
70
70
  - lib/unidom/shopping/version.rb
71
- homepage: https://github.com/topbitdu/unidom-shopping
71
+ homepage: https://gitee.com/Unidom/unidom-shopping
72
72
  licenses:
73
73
  - MIT
74
74
  metadata: {}
75
- post_install_message:
75
+ post_install_message:
76
76
  rdoc_options: []
77
77
  require_paths:
78
78
  - lib
@@ -87,8 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  requirements: []
90
- rubygems_version: 3.1.2
91
- signing_key:
90
+ rubygems_version: 3.2.3
91
+ signing_key:
92
92
  specification_version: 4
93
93
  summary: Unidom Shopping Domain Model Engine 购物领域模型引擎
94
94
  test_files: []