unidom-price 1.1 → 1.2

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: ad1b3bfa256196866e0c121411789815360c50d5
4
- data.tar.gz: 1a614f382c7c1a40d44afdf341b08ce26ea92313
3
+ metadata.gz: c75e12e56ca3e86473e2a7aa901bbb6d572d4375
4
+ data.tar.gz: a9bda6ba710a320dd033ba4ec599aa5fe59721ad
5
5
  SHA512:
6
- metadata.gz: b46a6f6baa45b54de4ce80af9035cd85b16ab5f689c388bf6bf658c84021d92c693c4bb8832578ce9c6d4726b4a81ba906c9ce02c045f7ead620925a13cbb6f5
7
- data.tar.gz: e252e804530a7b49ce1a1c5c6d0fd8176388134aacc40883bb4dc0703a56a3c23fcfdcd3abdca08cbeac11b8acaacc4e07e8a3d7c75092e7a9b7d999cb640512
6
+ metadata.gz: 2fb5a5a334c087cef62849ccd0d385d37386a6566634ed21ca40666d78b3c9cbfe0de5b6630cc29c1a3767b03104c45e2a8b417ee26ff0bf15d140d249709604
7
+ data.tar.gz: 1aab7bdb3ed4f1ae3e861c2a15bf2389f5c8161d656028bfc3d2b181b3add87bc40c4fb46f25cdeecd8135702bb7e62abdd557f5911974fb147007073df01705
data/README.md CHANGED
@@ -65,7 +65,9 @@ include Unidom::Price::Concerns::AsPricer
65
65
  ### As Priced
66
66
  The As Priced concern do the following tasks for the includer automatically:
67
67
  1. Define the has_many :prices macro as: ``has_many :prices, class_name: 'Unidom::Price::Price', as: :priced``
68
+ 2. Define the #is_priced! method as: ``is_priced!(amount, by: nil, at: Time.now)``
68
69
 
69
70
  ### As Pricer
70
71
  The As Priced concern do the following tasks for the includer automatically:
71
72
  1. Define the has_many :pricings macro as: ``has_many :pricings, class_name: 'Unidom::Price::Price', as: :pricer``
73
+ 2. Define the #price! method as: ``price!(it, amount, at: Time.now)``
@@ -6,6 +6,16 @@ module Unidom::Price::Concerns::AsPriced
6
6
 
7
7
  has_many :prices, class_name: 'Unidom::Price::Price', as: :priced
8
8
 
9
+ def is_priced!(amount, by: nil, at: Time.now)
10
+ pricing = prices.valid_at(now: at).alive.first
11
+ pricing.soft_destroy if pricing.present?
12
+ prices.create! pricer: by, amount: amount, opened_at: at
13
+ end
14
+
15
+ #def is_priced?(at: Time.now)
16
+ # prices.valid_at(now: at).alive.exists?
17
+ #end
18
+
9
19
  end
10
20
 
11
21
  module ClassMethods
@@ -6,6 +6,16 @@ module Unidom::Price::Concerns::AsPricer
6
6
 
7
7
  has_many :pricings, class_name: 'Unidom::Price::Price', as: :pricer
8
8
 
9
+ def price!(it, amount, at: Time.now)
10
+ pricing = pricings.priced_is(it).valid_at(now: at).alive.first
11
+ pricing.soft_destroy if pricing.present?
12
+ pricings.create! priced: it, amount: amount, opened_at: at
13
+ end
14
+
15
+ #def price?(it, at: Time.now)
16
+ # pricings.priced_is(it).valid_at(now: at).alive.exists?
17
+ #end
18
+
9
19
  end
10
20
 
11
21
  module ClassMethods
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Price
3
- VERSION = '1.1'.freeze
3
+ VERSION = '1.2'.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: '1.1'
4
+ version: '1.2'
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-08-30 00:00:00.000000000 Z
11
+ date: 2016-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common