unidom-shopping 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -1
- data/app/assets/javascripts/unidom/shopping/application.js +1 -1
- data/app/assets/stylesheets/unidom/shopping/application.css +0 -1
- data/app/models/unidom/shopping/shopping_cart.rb +12 -2
- data/app/models/unidom/shopping/shopping_item.rb +2 -2
- data/app/views/layouts/unidom/shopping/application.html.erb +3 -2
- data/lib/unidom/shopping/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2537888fd6be16096765b936f738a0b4aee4bcf
|
4
|
+
data.tar.gz: 632b5d0999f62d73133254212ecf823a5f949958
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbc214ecba6299f0bf4ee33c3bdc48814a6f2d951518bbbc875c481e10f36889099e9f788d9878baadd2a45a547c81878f3b4fccb11942d37ea893c277deab6f
|
7
|
+
data.tar.gz: 26984b7c3e7db75423a6d0c090094ed34f93ac2468e4ebf1444eae2434648955964ac097eafdbbc4ab71c82bff7acf7d0edd1f7af3dc7d3dc38ef5575caa4310
|
data/README.md
CHANGED
@@ -6,6 +6,10 @@
|
|
6
6
|
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
7
|
Unidom (统一领域对象模型)是一系列的领域模型引擎。购物领域模型引擎包括购物车和购物项的模型。
|
8
8
|
|
9
|
+
## Recent Update
|
10
|
+
Check out the [Road Map](ROADMAP.md) to find out what's the next.
|
11
|
+
Check out the [Change Log](CHANGELOG.md) to find out what's new.
|
12
|
+
|
9
13
|
## Usage in Gemfile
|
10
14
|
```ruby
|
11
15
|
gem 'unidom-shopping'
|
@@ -15,8 +19,25 @@ gem 'unidom-shopping'
|
|
15
19
|
```shell
|
16
20
|
rake db:migrate
|
17
21
|
```
|
22
|
+
The migration versions start with 200205.
|
18
23
|
|
19
24
|
## Call the Model
|
20
25
|
```ruby
|
21
|
-
|
26
|
+
# Create Shopping Cart
|
27
|
+
lady = Party.create name: 'Ann'
|
28
|
+
shop = Shop.create name: 'WalMart'
|
29
|
+
shopping_cart = Unidom::Shopping::ShoppingCart.create shopper: lady, shop: shop, opened_at: Time.now
|
30
|
+
|
31
|
+
# Add Products into Shopping Cart
|
32
|
+
fish = Product.create name: 'Fish'
|
33
|
+
ball = Prdduct.create name: 'Ball'
|
34
|
+
shopping_cart.items.create shopper: lady, shopped: fish, unit_price: 39.96, quantity: 2, opened_at: Time.now
|
35
|
+
shopping_cart.items.create shopper: lady, shopped: ball, unit_price: 19.99, quantity: 1, opened_at: Time.now
|
36
|
+
# or
|
37
|
+
shopping_cart.add! fish, 39.96, 2, Time.now
|
38
|
+
shopping_cart.add! ball, 19.99
|
39
|
+
|
40
|
+
# Find the Shopping Cart
|
41
|
+
shopping_cart = Unidom::Shopping::ShoppingCart.shopped_by(lady).shop_is(shop).valid_at.alive.first
|
42
|
+
shopping_cart.items.valid_at.alive # fish & ball
|
22
43
|
```
|
@@ -4,14 +4,24 @@ class Unidom::Shopping::ShoppingCart < ActiveRecord::Base
|
|
4
4
|
|
5
5
|
self.table_name = 'unidom_shopping_carts'
|
6
6
|
|
7
|
+
include Unidom::Common::Concerns::ModelExtension
|
8
|
+
|
7
9
|
belongs_to :shopper, polymorphic: true
|
8
10
|
belongs_to :shop, polymorphic: true
|
9
11
|
|
10
|
-
has_many :items, class_name: 'Unidom::Shopping::ShoppingItem'
|
12
|
+
has_many :items, class_name: 'Unidom::Shopping::ShoppingItem'
|
11
13
|
|
12
14
|
scope :shopped_by, ->(shopper) { where shopper: shopper }
|
13
15
|
scope :shop_is, ->(shop) { where shop: shop }
|
14
16
|
|
15
|
-
|
17
|
+
def add!(shopped, unit_price, quantity = 1, opened_at = Time.now)
|
18
|
+
item = items.shopped_is(shopped).valid_at.alive.first
|
19
|
+
if item.present?
|
20
|
+
item.attributes = { shopper: shopper, unit_price: unit_price, quantity: quantity+item.quantity }
|
21
|
+
item.save!
|
22
|
+
else
|
23
|
+
items.create! shopped: shopped, shopper: shopper, unit_price: unit_price, quantity: quantity, opened_at: opened_at
|
24
|
+
end
|
25
|
+
end
|
16
26
|
|
17
27
|
end
|
@@ -4,6 +4,8 @@ class Unidom::Shopping::ShoppingItem < ActiveRecord::Base
|
|
4
4
|
|
5
5
|
self.table_name = 'unidom_shopping_items'
|
6
6
|
|
7
|
+
include Unidom::Common::Concerns::ModelExtension
|
8
|
+
|
7
9
|
validates :unit_price, presence: true, numericality: { greater_than: 0, less_than: 1000000000 }
|
8
10
|
validates :quantity, presence: true, numericality: { greater_than: 0, less_than: 1000000000 }
|
9
11
|
|
@@ -15,6 +17,4 @@ class Unidom::Shopping::ShoppingItem < ActiveRecord::Base
|
|
15
17
|
scope :shopped_by, ->(shopper) { where shopper: shopper }
|
16
18
|
scope :shopped_is, ->(shopped) { where shopped: shopped }
|
17
19
|
|
18
|
-
include Unidom::Common::Concerns::ModelExtension
|
19
|
-
|
20
20
|
end
|
@@ -2,13 +2,14 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<title>Shopping</title>
|
5
|
-
<%= stylesheet_link_tag
|
6
|
-
<%= javascript_include_tag "shopping/application" %>
|
5
|
+
<%= stylesheet_link_tag "shopping/application", media: "all" %>
|
7
6
|
<%= csrf_meta_tags %>
|
8
7
|
</head>
|
9
8
|
<body>
|
10
9
|
|
11
10
|
<%= yield %>
|
12
11
|
|
12
|
+
<%= javascript_include_tag 'shopping/application' %>
|
13
|
+
|
13
14
|
</body>
|
14
15
|
</html>
|
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: '0.
|
4
|
+
version: '0.3'
|
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-
|
11
|
+
date: 2016-07-21 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: '0.
|
19
|
+
version: '0.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: '0.
|
26
|
+
version: '0.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 (统一领域对象模型)是一系列的领域模型引擎。购物领域模型引擎包括购物车和购物项的模型。
|
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
72
|
rubyforge_project:
|
73
|
-
rubygems_version: 2.4
|
73
|
+
rubygems_version: 2.6.4
|
74
74
|
signing_key:
|
75
75
|
specification_version: 4
|
76
76
|
summary: Unidom Shopping Domain Model Engine 购物领域模型引擎
|