unidom-shopping 1.6.4 → 1.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -11
- data/app/controllers/unidom/shopping/application_controller.rb +3 -0
- data/app/jobs/unidom/shopping/application_job.rb +3 -0
- data/app/mailers/unidom/shopping/application_mailer.rb +3 -0
- data/app/models/unidom/shopping/application_record.rb +3 -0
- data/app/models/unidom/shopping/concerns/as_cart_shopper.rb +6 -0
- data/app/models/unidom/shopping/concerns/as_item_shopper.rb +6 -0
- data/app/models/unidom/shopping/concerns/as_shop.rb +6 -0
- data/app/models/unidom/shopping/concerns/as_shopped.rb +6 -0
- data/app/models/unidom/shopping/shopping_cart.rb +4 -1
- data/app/models/unidom/shopping/shopping_item.rb +1 -1
- data/lib/unidom/shopping/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d26d94a4ba3b2e459005323e41f55b23420f6128
|
4
|
+
data.tar.gz: aa5c50a608e51ae24131cd87f639e65b7e0f055a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bc634a438ebea10ac6d15c1cbe42d34434b4621aefd1d3475b73e950160df0669d0bccc7f8ad8857dd8fe5bf0af9045edee57ed35ed13f314dc6295e971d2b8
|
7
|
+
data.tar.gz: 372c43e865991c41938bcf919a7109a8188ec111be0ad21a80ab839fba5de5d6f8442d3391947a4e216791d7fc107de26f5ef4f1953816252d668e1c91558668
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Unidom Shopping 购物领域模型引擎
|
2
2
|
|
3
|
+
[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/unidom-shopping/frames)
|
3
4
|
[![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
|
5
|
+
|
4
6
|
[![Gem Version](https://badge.fury.io/rb/unidom-shopping.svg)](https://badge.fury.io/rb/unidom-shopping)
|
5
7
|
[![Dependency Status](https://gemnasium.com/badges/github.com/topbitdu/unidom-shopping.svg)](https://gemnasium.com/github.com/topbitdu/unidom-shopping)
|
6
8
|
|
@@ -68,27 +70,43 @@ include Unidom::Shopping::Concerns::AsShopped
|
|
68
70
|
|
69
71
|
### As Cart Shopper
|
70
72
|
|
71
|
-
The As Cart Shopper concern do the following tasks for the includer automatically:
|
72
|
-
1. Define the has_many :shopping_carts macro as: ``has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shopper``
|
73
|
-
2. Define the #get_cart! method as: ``get_cart!(from: nil, at: Time.now)``
|
73
|
+
The As Cart Shopper concern do the following tasks for the includer automatically:
|
74
|
+
1. Define the has_many :shopping_carts macro as: ``has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shopper``
|
75
|
+
2. Define the #get_cart! method as: ``get_cart!(from: nil, at: Time.now)``
|
74
76
|
3. Define the #get_cart? method as: ``get_cart?(from: nil, at: Time.now)``
|
75
77
|
|
76
78
|
### As Item Shopper
|
77
79
|
|
78
|
-
The As Item Shopper concern do the following tasks for the includer automatically:
|
79
|
-
1. Define the has_many :shopping_items macro as: ``has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopper``
|
80
|
-
2. Define the #add! method as: ``add!(it, into: nil, at: Time.now, unit_price: 0, quantity: 1)``
|
80
|
+
The As Item Shopper concern do the following tasks for the includer automatically:
|
81
|
+
1. Define the has_many :shopping_items macro as: ``has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopper``
|
82
|
+
2. Define the #add! method as: ``add!(it, into: nil, at: Time.now, unit_price: 0, quantity: 1)``
|
81
83
|
3. Define the #add? method as: ``add?(it, into: nil, at: Time.now)``
|
82
84
|
|
83
85
|
### As Shop
|
84
86
|
|
85
|
-
The As Shop concern do the following tasks for the includer automatically:
|
86
|
-
1. Define the has_many :shopping_carts macro as: ``has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shop``
|
87
|
+
The As Shop concern do the following tasks for the includer automatically:
|
88
|
+
1. Define the has_many :shopping_carts macro as: ``has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shop``
|
87
89
|
2. Define the #get_cart! method as: ``get_cart!(by: nil, at: Time.now)``
|
88
90
|
|
89
91
|
### As Shopped
|
90
92
|
|
91
|
-
The As Shopped concern do the following tasks for the includer automatically:
|
92
|
-
1. Define the has_many :shopping_items macro as: ``has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopped``
|
93
|
-
2. Define the #is_added! method as: ``is_added!(into: nil, by: nil, at: Time.now, unit_price: 0, quantity: 1)``
|
93
|
+
The As Shopped concern do the following tasks for the includer automatically:
|
94
|
+
1. Define the has_many :shopping_items macro as: ``has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopped``
|
95
|
+
2. Define the #is_added! method as: ``is_added!(into: nil, by: nil, at: Time.now, unit_price: 0, quantity: 1)``
|
94
96
|
3. Define the #is_added? method as: ``is_added?(into: nil, by: nil, at: Time.now)``
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
## Disable the Model & Migration
|
101
|
+
|
102
|
+
If you only need the app components other than models, the migrations should be neglected, and the models should not be loaded.
|
103
|
+
```ruby
|
104
|
+
# config/initializers/unidom.rb
|
105
|
+
Unidom::Common.configure do |options|
|
106
|
+
|
107
|
+
options[:neglected_namespaces] = %w{
|
108
|
+
Unidom::Shopping
|
109
|
+
}
|
110
|
+
|
111
|
+
end
|
112
|
+
```
|
@@ -1,3 +1,6 @@
|
|
1
|
+
##
|
2
|
+
# As Cart Shopper 是购物车所有者的领域逻辑关注点。
|
3
|
+
|
1
4
|
module Unidom::Shopping::Concerns::AsCartShopper
|
2
5
|
|
3
6
|
extend ActiveSupport::Concern
|
@@ -6,6 +9,9 @@ module Unidom::Shopping::Concerns::AsCartShopper
|
|
6
9
|
|
7
10
|
has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shopper
|
8
11
|
|
12
|
+
##
|
13
|
+
# 以购物者的身份,从指定的商店 from 获取购物车。时间为 at ,缺省为当前时间。如:
|
14
|
+
# current_person.get_cart! from: shop
|
9
15
|
def get_cart!(from: nil, at: Time.now)
|
10
16
|
shopping_carts.shop_is(from).valid_at(now: at).alive.first_or_create! opened_at: at
|
11
17
|
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
##
|
2
|
+
# As Item Shopper 是购物项所有者的领域逻辑关注点。
|
3
|
+
|
1
4
|
module Unidom::Shopping::Concerns::AsItemShopper
|
2
5
|
|
3
6
|
extend ActiveSupport::Concern
|
@@ -6,6 +9,9 @@ module Unidom::Shopping::Concerns::AsItemShopper
|
|
6
9
|
|
7
10
|
has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopper
|
8
11
|
|
12
|
+
##
|
13
|
+
# 以购物者的身份,将商品 it ,放入购物车 into 。购物时间是 at ,缺省为当前时间。单价是 unit_price ,缺省为 0 。数量是 quantity ,缺省为 1 。如:
|
14
|
+
# current_person.add! coca_cola, into: shopping_cart, unit_price: 3.50, quantity: 3
|
9
15
|
def add!(it, into: nil, at: Time.now, unit_price: 0, quantity: 1)
|
10
16
|
query = shopping_items.shopping_cart_is(into).shopped_is(it).valid_at(now: at).alive
|
11
17
|
item = query.first
|
@@ -1,3 +1,6 @@
|
|
1
|
+
##
|
2
|
+
# As Shop 是购物场所的领域逻辑关注点。
|
3
|
+
|
1
4
|
module Unidom::Shopping::Concerns::AsShop
|
2
5
|
|
3
6
|
extend ActiveSupport::Concern
|
@@ -6,6 +9,9 @@ module Unidom::Shopping::Concerns::AsShop
|
|
6
9
|
|
7
10
|
has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shop
|
8
11
|
|
12
|
+
##
|
13
|
+
# 从当前商店中,获取购物车。购物者为 by 。获取时间为 at ,缺省为当前时间。如:
|
14
|
+
# shop.get_cart! by: current_person
|
9
15
|
def get_cart!(by: nil, at: Time.now)
|
10
16
|
shopping_carts.shopped_by(by).valid_at(now: at).alive.first_or_create! opened_at: at
|
11
17
|
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
##
|
2
|
+
# As Shopped 是被购买的商品的领域逻辑关注点。
|
3
|
+
|
1
4
|
module Unidom::Shopping::Concerns::AsShopped
|
2
5
|
|
3
6
|
extend ActiveSupport::Concern
|
@@ -6,6 +9,9 @@ module Unidom::Shopping::Concerns::AsShopped
|
|
6
9
|
|
7
10
|
has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopped
|
8
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
|
9
15
|
def is_added!(into: nil, by: nil, at: Time.now, unit_price: 0, quantity: 1)
|
10
16
|
query = shopping_items.shopping_cart_is(into).valid_at(now: at).alive
|
11
17
|
item = query.first
|
@@ -15,6 +15,9 @@ class Unidom::Shopping::ShoppingCart < Unidom::Shopping::ApplicationRecord
|
|
15
15
|
scope :shopped_by, ->(shopper) { where shopper: shopper }
|
16
16
|
scope :shop_is, ->(shop) { where shop: shop }
|
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
|
18
21
|
def add!(shopped, by: nil, unit_price: 0, quantity: 1, at: Time.now)
|
19
22
|
item = items.shopped_is(shopped).valid_at.alive.first
|
20
23
|
if item.present?
|
@@ -25,4 +28,4 @@ class Unidom::Shopping::ShoppingCart < Unidom::Shopping::ApplicationRecord
|
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
28
|
-
end
|
31
|
+
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Shopping::ShoppingCart'
|
@@ -18,4 +18,4 @@ class Unidom::Shopping::ShoppingItem < Unidom::Shopping::ApplicationRecord
|
|
18
18
|
scope :shopped_by, ->(shopper) { where shopper: shopper }
|
19
19
|
scope :shopped_is, ->(shopped) { where shopped: shopped }
|
20
20
|
|
21
|
-
end
|
21
|
+
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Shopping::ShoppingItem'
|
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: 1.6.
|
4
|
+
version: 1.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-common
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.9'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.9'
|
27
27
|
description: Unidom (UNIfied Domain Object Model) is a series of domain model engines.
|
28
28
|
The Shopping domain model engine includes Shopping Cart and Shopping Item models.
|
29
29
|
Unidom (统一领域对象模型)是一系列的领域模型引擎。购物领域模型引擎包括购物车和购物项的模型。
|