unidom-shopping 1.4 → 1.5
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42d829fc77ba0db5c34938988b0efd7aee86484c
|
4
|
+
data.tar.gz: 81fb85b40868d5affa293da912bf803728790d26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fa9fb539419f36cff69d2e7760321dbbae92aead279e6fc2dd45731e4c0739153bffcbaa64e55dfb2a3b2278d029168464d0f6364c0140b649493d2bd29142f
|
7
|
+
data.tar.gz: 58f37b443f11ebc1ad4d482c620b7ed771170081c1a96ff1709d8612d66b7ca479ea185afe26f898c8f9aecb242e9970af985a1b076f7bb11db4749d8f7780c6
|
data/README.md
CHANGED
@@ -2,26 +2,39 @@
|
|
2
2
|
|
3
3
|
[![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/unidom-shopping.svg)](https://badge.fury.io/rb/unidom-shopping)
|
5
|
+
[![Dependency Status](https://gemnasium.com/badges/github.com/topbitdu/unidom-shopping.svg)](https://gemnasium.com/github.com/topbitdu/unidom-shopping)
|
5
6
|
|
6
7
|
Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Shopping domain model engine includes Shopping Cart and Shopping Item models.
|
7
8
|
Unidom (统一领域对象模型)是一系列的领域模型引擎。购物领域模型引擎包括购物车和购物项的模型。
|
8
9
|
|
10
|
+
|
11
|
+
|
9
12
|
## Recent Update
|
13
|
+
|
10
14
|
Check out the [Road Map](ROADMAP.md) to find out what's the next.
|
11
15
|
Check out the [Change Log](CHANGELOG.md) to find out what's new.
|
12
16
|
|
17
|
+
|
18
|
+
|
13
19
|
## Usage in Gemfile
|
20
|
+
|
14
21
|
```ruby
|
15
22
|
gem 'unidom-shopping'
|
16
23
|
```
|
17
24
|
|
25
|
+
|
26
|
+
|
18
27
|
## Run the Database Migration
|
28
|
+
|
19
29
|
```shell
|
20
30
|
rake db:migrate
|
21
31
|
```
|
22
32
|
The migration versions start with 200205.
|
23
33
|
|
34
|
+
|
35
|
+
|
24
36
|
## Call the Model
|
37
|
+
|
25
38
|
```ruby
|
26
39
|
# Create Shopping Cart
|
27
40
|
lady = Party.create name: 'Ann'
|
@@ -45,6 +58,7 @@ shopping_cart.items.valid_at.alive # fish & ball
|
|
45
58
|
|
46
59
|
|
47
60
|
## Include the Concerns
|
61
|
+
|
48
62
|
```ruby
|
49
63
|
include Unidom::Shopping::Concerns::AsCartShopper
|
50
64
|
include Unidom::Shopping::Concerns::AsItemShopper
|
@@ -53,21 +67,27 @@ include Unidom::Shopping::Concerns::AsShopped
|
|
53
67
|
```
|
54
68
|
|
55
69
|
### As Cart Shopper
|
70
|
+
|
56
71
|
The As Cart Shopper concern do the following tasks for the includer automatically:
|
57
|
-
1. Define the has_many :shopping_carts macro as: ``has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shopper``
|
58
|
-
2. Define the #get_cart! method as: ``get_cart!(from: nil, at: Time.now)``
|
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)``
|
59
74
|
3. Define the #get_cart? method as: ``get_cart?(from: nil, at: Time.now)``
|
60
75
|
|
61
76
|
### As Item Shopper
|
77
|
+
|
62
78
|
The As Item Shopper concern do the following tasks for the includer automatically:
|
63
|
-
1. Define the has_many :shopping_items macro as: ``has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopper``
|
64
|
-
2. Define the #add! method as: ``add!(it, into: nil, at: Time.now, unit_price: 0, quantity: 1)``
|
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)``
|
65
81
|
3. Define the #add? method as: ``add?(it, into: nil, at: Time.now)``
|
66
82
|
|
67
83
|
### As Shop
|
84
|
+
|
68
85
|
The As Shop concern do the following tasks for the includer automatically:
|
69
|
-
1. Define the has_many :shopping_carts macro as: ``has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shop``
|
86
|
+
1. Define the has_many :shopping_carts macro as: ``has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shop``
|
87
|
+
2. Define the #get_cart! method as: ``get_cart!(by: nil, at: Time.now)``
|
70
88
|
|
71
89
|
### As Shopped
|
90
|
+
|
72
91
|
The As Shopped concern do the following tasks for the includer automatically:
|
73
|
-
1. Define the has_many :shopping_items macro as: ``has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopped``
|
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)``
|
@@ -11,7 +11,7 @@ module Unidom::Shopping::Concerns::AsItemShopper
|
|
11
11
|
item = query.first
|
12
12
|
if item.present?
|
13
13
|
item.unit_price = unit_price
|
14
|
-
item.increment! quantity
|
14
|
+
item.increment! :quantity, quantity
|
15
15
|
else
|
16
16
|
item = shopping_items.create! shopping_cart: into, shopped: it, unit_price: unit_price, quantity: quantity, opened_at: at
|
17
17
|
end
|
@@ -6,6 +6,10 @@ module Unidom::Shopping::Concerns::AsShop
|
|
6
6
|
|
7
7
|
has_many :shopping_carts, class_name: 'Unidom::Shopping::ShoppingCart', as: :shop
|
8
8
|
|
9
|
+
def get_cart!(by: nil, at: Time.now)
|
10
|
+
shopping_carts.shopped_by(by).valid_at(now: at).alive.first_or_create! opened_at: at
|
11
|
+
end
|
12
|
+
|
9
13
|
end
|
10
14
|
|
11
15
|
module ClassMethods
|
@@ -6,6 +6,26 @@ module Unidom::Shopping::Concerns::AsShopped
|
|
6
6
|
|
7
7
|
has_many :shopping_items, class_name: 'Unidom::Shopping::ShoppingItem', as: :shopped
|
8
8
|
|
9
|
+
def is_added!(into: nil, by: nil, at: Time.now, unit_price: 0, quantity: 1)
|
10
|
+
query = shopping_items.shopping_cart_is(into).valid_at(now: at).alive
|
11
|
+
item = query.first
|
12
|
+
if item.present?
|
13
|
+
item.unit_price = unit_price
|
14
|
+
item.shopper = by
|
15
|
+
item.increment! :quantity, quantity
|
16
|
+
else
|
17
|
+
item = shopping_items.create! shopping_cart: into, shopper: by, unit_price: unit_price, quantity: quantity, opened_at: at
|
18
|
+
end
|
19
|
+
item
|
20
|
+
end
|
21
|
+
|
22
|
+
#def is_added?(into: nil, by: nil, at: Time.now)
|
23
|
+
# query = shopping_items.shopping_cart_is(into)
|
24
|
+
# query = query.shopped_by(by) if by.present?
|
25
|
+
# query = query.valid_at(now: at).alive
|
26
|
+
# query.exists?
|
27
|
+
#end
|
28
|
+
|
9
29
|
end
|
10
30
|
|
11
31
|
module ClassMethods
|
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.
|
4
|
+
version: '1.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: 2016-10-
|
11
|
+
date: 2016-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-common
|