unidom-shopping 0.2 → 0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 744035cfa07343f8d3154893d0026231e1c84b0c
4
- data.tar.gz: 5893b8a7b0e3f4e2f85abfec9bccea61acc99b2e
3
+ metadata.gz: d2537888fd6be16096765b936f738a0b4aee4bcf
4
+ data.tar.gz: 632b5d0999f62d73133254212ecf823a5f949958
5
5
  SHA512:
6
- metadata.gz: 6e3dacabd5a464a9a7dd793da3f591d4d156ae2e9c79444579fda6086cc50d1fa3a35545d64bd1aaba27d0a982dc644bff4c32cbc0bc388f14cf5f6eaf7f90a3
7
- data.tar.gz: 21e17d7a67ebd0db431a34e614d14f76151c2545e582063b6fea4fe1f49e1fc1163b6f931886ca205ee18fe6a7dd404ca281bd15a1499b075c7345040e566c74
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
- Unidom::Shopping::ShoppingCart.valid_at.alive.first.items.valid.alive
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
  ```
@@ -10,4 +10,4 @@
10
10
  // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
- //= require_tree .
13
+ //= require_self
@@ -10,6 +10,5 @@
10
10
  * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
11
  * file per style scope.
12
12
  *
13
- *= require_tree .
14
13
  *= require_self
15
14
  */
@@ -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', as: :shopping_cart
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
- include Unidom::Common::Concerns::ModelExtension
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 "shopping/application", media: "all" %>
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>
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Shopping
3
- VERSION = '0.2'.freeze
3
+ VERSION = '0.3'.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: '0.2'
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-02-25 00:00:00.000000000 Z
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.2'
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.2'
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.5.1
73
+ rubygems_version: 2.6.4
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: Unidom Shopping Domain Model Engine 购物领域模型引擎