unidom-price 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: dbc16602b186855ce7f5d79d96da01ea8ab1b86f3fcec038b8b484cee90fa59d
4
- data.tar.gz: 5aa681db92e9cd954fa830b6595cc48a472b70e0a46e2b7ef7b28b36c0b45fd6
3
+ metadata.gz: 0eceb203e83e315331b5a2dbf77638805322c64aa743505f753dfc6fb276c637
4
+ data.tar.gz: fe3e9e23fe9bc7d0bce917cefd64e18795e1f178563e32d0447747d86545580b
5
5
  SHA512:
6
- metadata.gz: 9f1e0c311793e174b8a70706e8982bcd3e45e5bd697d4ca8b1e520a8ff76ce0e2deb7a4e5aca7b25d9c4c664a0a9cd4de46d4c0646c569da62f1bca6fc3b5eb0
7
- data.tar.gz: af56a0d0c1d1b30bea50f87447fa155ce9fd83a08c7f27a9c1bcb4b3448c45ee115cacd31921985e9a5672d4a09fdc9c8131d6d870524a1095f7c2a89962ba4a
6
+ metadata.gz: 6907d5214cb8233c422a896c1b9835c12eb6e03768de40bb34c7f04210b05fc10cffff4b484b12cbe83438cdac23cdb6ee7818ad96bf7f592d099bf5aecdc3f1
7
+ data.tar.gz: c86b2fe7ba4c9b8da9f47606872b909a6c020dcb4747a87b95ac886d9b3ca279cbb9764cd9f2981cb9be02e7813201a0dc7a254a04318fb980003086719d3697
@@ -1,6 +1,12 @@
1
1
  ##
2
2
  # Application controller 是模块内所有控制器的基类。
3
3
 
4
- class Unidom::Price::ApplicationController < ActionController::Base
5
- protect_from_forgery with: :exception
4
+ module Unidom
5
+ module Price
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::Price::ApplicationHelper
1
+ module Unidom
2
+ module Price
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::Price::ApplicationJob < ActiveJob::Base
4
+ module Unidom
5
+ module Price
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::Price::ApplicationMailer < ActionMailer::Base
5
- default from: 'from@example.com'
6
- layout 'mailer'
4
+ module Unidom
5
+ module Price
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::Price::ApplicationRecord < ActiveRecord::Base
5
- self.abstract_class = true
4
+ module Unidom
5
+ module Price
6
+
7
+ class ApplicationRecord < ActiveRecord::Base
8
+ self.abstract_class = true
9
+ end
10
+
11
+ end
6
12
  end
@@ -1,38 +1,46 @@
1
1
  ##
2
2
  # As Priced 是被定价物品的领域逻辑关注点。
3
3
 
4
- module Unidom::Price::Concerns::AsPriced
4
+ module Unidom
5
+ module Price
6
+ module Concerns
5
7
 
6
- extend ActiveSupport::Concern
7
- include Unidom::Common::Concerns::ArgumentValidation
8
+ module AsPriced
8
9
 
9
- included do |includer|
10
+ extend ActiveSupport::Concern
11
+ include Unidom::Common::Concerns::ArgumentValidation
10
12
 
11
- has_many :prices, class_name: 'Unidom::Price::Price', as: :priced
13
+ included do |includer|
12
14
 
13
- def is_priced!(amount, by: nil, at: Time.now)
15
+ has_many :prices, class_name: 'Unidom::Price::Price', as: :priced
14
16
 
15
- assert_present! :amount, amount
16
- assert_present! :by, by
17
- assert_present! :at, at
17
+ def is_priced!(amount, by: nil, at: Time.now)
18
18
 
19
- pricing = prices.valid_at(now: at).alive.first
20
- pricing.soft_destroy if pricing.present?
21
- prices.create! pricer: by, amount: amount, opened_at: at
19
+ assert_present! :amount, amount
20
+ assert_present! :by, by
21
+ assert_present! :at, at
22
22
 
23
- end
23
+ pricing = prices.valid_at(now: at).alive.first
24
+ pricing.soft_destroy if pricing.present?
25
+ prices.create! pricer: by, amount: amount, opened_at: at
24
26
 
25
- def is_priced?(at: Time.now)
27
+ end
26
28
 
27
- assert_present! :at, at
29
+ def is_priced?(at: Time.now)
28
30
 
29
- prices.valid_at(now: at).alive.exists?
31
+ assert_present! :at, at
30
32
 
31
- end
33
+ prices.valid_at(now: at).alive.exists?
32
34
 
33
- end
35
+ end
34
36
 
35
- module ClassMethods
36
- end
37
+ end
37
38
 
39
+ module ClassMethods
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+ end
38
46
  end
@@ -1,38 +1,46 @@
1
1
  ##
2
2
  # As Pricer 是定价者的领域逻辑关注点。
3
3
 
4
- module Unidom::Price::Concerns::AsPricer
4
+ module Unidom
5
+ module Price
6
+ module Concerns
5
7
 
6
- extend ActiveSupport::Concern
8
+ module AsPricer
7
9
 
8
- included do |includer|
10
+ extend ActiveSupport::Concern
9
11
 
10
- has_many :pricings, class_name: 'Unidom::Price::Price', as: :pricer
12
+ included do |includer|
11
13
 
12
- def price!(it, amount, at: Time.now)
14
+ has_many :pricings, class_name: 'Unidom::Price::Price', as: :pricer
13
15
 
14
- assert_present! :it, it
15
- assert_present! :amount, amount
16
- assert_present! :at, at
16
+ def price!(it, amount, at: Time.now)
17
17
 
18
- pricing = pricings.priced_is(it).valid_at(now: at).alive.first
19
- pricing.soft_destroy if pricing.present?
20
- pricings.create! priced: it, amount: amount, opened_at: at
18
+ assert_present! :it, it
19
+ assert_present! :amount, amount
20
+ assert_present! :at, at
21
21
 
22
- end
22
+ pricing = pricings.priced_is(it).valid_at(now: at).alive.first
23
+ pricing.soft_destroy if pricing.present?
24
+ pricings.create! priced: it, amount: amount, opened_at: at
23
25
 
24
- def price?(it, at: Time.now)
26
+ end
25
27
 
26
- assert_present! :it, it
27
- assert_present! :at, at
28
+ def price?(it, at: Time.now)
28
29
 
29
- pricings.priced_is(it).valid_at(now: at).alive.exists?
30
+ assert_present! :it, it
31
+ assert_present! :at, at
30
32
 
31
- end
33
+ pricings.priced_is(it).valid_at(now: at).alive.exists?
32
34
 
33
- end
35
+ end
34
36
 
35
- module ClassMethods
36
- end
37
+ end
37
38
 
39
+ module ClassMethods
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+ end
38
46
  end
@@ -2,55 +2,61 @@
2
2
  # pricing: 基价(Base)、折扣成分、额外收费成分、厂商建议价。
3
3
  # charging: 一次性收费、重复性收费、使用率收费。
4
4
 
5
- class Unidom::Price::Price < Unidom::Price::ApplicationRecord
6
-
7
- self.table_name = 'unidom_prices'
8
-
9
- include Unidom::Common::Concerns::ModelExtension
10
- include ProgneTapera::EnumCode
11
-
12
- validates :amount, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1_000_000_000 }
13
-
14
- belongs_to :priced, polymorphic: true
15
- belongs_to :pricer, polymorphic: true
16
-
17
- scope :priced_by, ->(pricer) { where pricer: pricer }
18
- scope :priced_is, ->(priced) { where priced: priced }
19
-
20
- code :calculation, Unidom::Price::Calculation
21
- code :charging, Unidom::Price::Charging
22
- code :pricing, Unidom::Price::Pricing
23
-
24
- ##
25
- # 将物品 priced 定价为 amount , 定价者是 pricer。
26
- def self.price!(priced, amount: 0, pricer: nil, calculation_code: 'AMNT', pricing_code: 'BASE', charging_code: 'ONCE', opened_at: Time.now)
5
+ module Unidom
6
+ module Price
7
+
8
+ class Price < ApplicationRecord
9
+
10
+ self.table_name = 'unidom_prices'
11
+
12
+ include Unidom::Common::Concerns::ModelExtension
13
+ include ProgneTapera::EnumCode
14
+
15
+ validates :amount, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1_000_000_000 }
16
+
17
+ belongs_to :priced, polymorphic: true
18
+ belongs_to :pricer, polymorphic: true
19
+
20
+ scope :priced_by, ->(pricer) { where pricer: pricer }
21
+ scope :priced_is, ->(priced) { where priced: priced }
22
+
23
+ code :calculation, Unidom::Price::Calculation
24
+ code :charging, Unidom::Price::Charging
25
+ code :pricing, Unidom::Price::Pricing
26
+
27
+ ##
28
+ # 将物品 priced 定价为 amount , 定价者是 pricer。
29
+ def self.price!(priced, amount: 0, pricer: nil, calculation_code: 'AMNT', pricing_code: 'BASE', charging_code: 'ONCE', opened_at: Time.now)
30
+
31
+ assert_present! :priced, priced
32
+ assert_present! :amount, amount
33
+ assert_present! :calculation_code, calculation_code
34
+ assert_present! :pricing_code, pricing_code
35
+ assert_present! :charging_code, charging_code
36
+ assert_present! :opened_at, opened_at
37
+
38
+ price = priced_is(priced).calculation_coded_as(calculation_code).pricing_coded_as(pricing_code).charging_coded_as(charging_code).valid_at.alive.first
39
+ if price.present?
40
+ price.amount = amount
41
+ if pricer.present?
42
+ price.pricer = pricer
43
+ else
44
+ price.pricer_id = Unidom::Common::NULL_UUID
45
+ price.pricer_type = ''
46
+ end
47
+ else
48
+ attributes = { priced: priced, amount: amount, calculation_code: calculation_code, pricing_code: pricing_code, charging_code: charging_code, opened_at: opened_at }
49
+ if pricer.present?
50
+ attributes[:pricer] = pricer
51
+ else
52
+ attributes[:pricer_id] = Unidom::Common::NULL_UUID
53
+ attributes[:pricer_type] = ''
54
+ end
55
+ create! attributes
56
+ end
57
+ end
27
58
 
28
- assert_present! :priced, priced
29
- assert_present! :amount, amount
30
- assert_present! :calculation_code, calculation_code
31
- assert_present! :pricing_code, pricing_code
32
- assert_present! :charging_code, charging_code
33
- assert_present! :opened_at, opened_at
59
+ end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Price::Price'
34
60
 
35
- price = priced_is(priced).calculation_coded_as(calculation_code).pricing_coded_as(pricing_code).charging_coded_as(charging_code).valid_at.alive.first
36
- if price.present?
37
- price.amount = amount
38
- if pricer.present?
39
- price.pricer = pricer
40
- else
41
- price.pricer_id = Unidom::Common::NULL_UUID
42
- price.pricer_type = ''
43
- end
44
- else
45
- attributes = { priced: priced, amount: amount, calculation_code: calculation_code, pricing_code: pricing_code, charging_code: charging_code, opened_at: opened_at }
46
- if pricer.present?
47
- attributes[:pricer] = pricer
48
- else
49
- attributes[:pricer_id] = Unidom::Common::NULL_UUID
50
- attributes[:pricer_type] = ''
51
- end
52
- create! attributes
53
- end
54
61
  end
55
-
56
- end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Price::Price'
62
+ end
@@ -1,7 +1,13 @@
1
- class Unidom::Price::Calculation < ActiveRecord::Type::Value
1
+ module Unidom
2
+ module Price
2
3
 
3
- include ProgneTapera::EnumConfig
4
+ class Calculation < ActiveRecord::Type::Value
4
5
 
5
- enum :unidom_calculation
6
+ include ProgneTapera::EnumConfig
6
7
 
8
+ enum :unidom_calculation
9
+
10
+ end
11
+
12
+ end
7
13
  end
@@ -1,7 +1,13 @@
1
- class Unidom::Price::Charging < ActiveRecord::Type::Value
1
+ module Unidom
2
+ module Price
2
3
 
3
- include ProgneTapera::EnumConfig
4
+ class Charging < ActiveRecord::Type::Value
4
5
 
5
- enum :unidom_charging
6
+ include ProgneTapera::EnumConfig
6
7
 
8
+ enum :unidom_charging
9
+
10
+ end
11
+
12
+ end
7
13
  end
@@ -1,7 +1,13 @@
1
- class Unidom::Price::Pricing < ActiveRecord::Type::Value
1
+ module Unidom
2
+ module Price
2
3
 
3
- include ProgneTapera::EnumConfig
4
+ class Pricing < ActiveRecord::Type::Value
4
5
 
5
- enum :unidom_pricing
6
+ include ProgneTapera::EnumConfig
6
7
 
8
+ enum :unidom_pricing
9
+
10
+ end
11
+
12
+ end
7
13
  end
@@ -2,7 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Unidom Price</title>
5
- <%= stylesheet_link_tag 'unidom/price/application', media: "all" %>
5
+ <%= stylesheet_link_tag 'unidom/price/application', media: 'all' %>
6
6
  <%= csrf_meta_tags %>
7
7
  </head>
8
8
  <body>
@@ -1,4 +1,4 @@
1
- class CreateUnidomPrices < ActiveRecord::Migration
1
+ class CreateUnidomPrices < ActiveRecord::Migration[6.0]
2
2
 
3
3
  def change
4
4
 
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Price
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-price
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-15 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/price/types_rspec.rb
69
69
  - lib/unidom/price/validators_rspec.rb
70
70
  - lib/unidom/price/version.rb
71
- homepage: https://github.com/topbitdu/unidom-price
71
+ homepage: https://gitee.com/Unidom/unidom-price
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 Price Domain Model Engine 价格领域模型引擎
94
94
  test_files: []