price_log 0.0.7 → 0.0.81
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/price_log/version.rb +1 -1
- data/lib/price_log.rb +14 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f679530724a85ac247b3b5d9d3b317a6cc3767dc
|
4
|
+
data.tar.gz: 69f0fa3e074ecad3eb4522923e2811b2b7d8cb70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63ae38a8ac82230483e4f425c2ba5b69e27de6085f9e499522ecd1c6e0fdb69d12ca4d6884240955ef895ce90035e178decef9a0fd8d6ab3facb53fa71192657
|
7
|
+
data.tar.gz: 255ecfa492e6f3eecd0fe7f6684884d0283a63a4635e42f33f4834f40fcf687358ec8647f3dcf7d09dbe7254d9ef9708739652307d4df4dfedf66650b74c6be7
|
data/lib/price_log/version.rb
CHANGED
data/lib/price_log.rb
CHANGED
@@ -17,6 +17,8 @@ module PriceLog
|
|
17
17
|
|
18
18
|
module ClassMethods
|
19
19
|
|
20
|
+
UNDEFINED_CURRENT_VALUE_FIELD_NAME = "UNDEFINED_CURRENT_VALUE_FIELD_NAME"
|
21
|
+
|
20
22
|
def has_price_log(name, options = {})
|
21
23
|
configuration = {
|
22
24
|
name: name,
|
@@ -26,17 +28,27 @@ module PriceLog
|
|
26
28
|
|
27
29
|
_field_name_ = configuration[:name]
|
28
30
|
_relation_name_ = "all_#{_field_name_}_price_logs".to_sym
|
29
|
-
|
30
|
-
|
31
31
|
has_many _relation_name_, -> (object){ where("priceable_field_name = ?", _field_name_.to_sym)}, {as: :priceable, dependent: :destroy, class_name: "PriceLogEntry", validate:false}
|
32
32
|
|
33
|
+
_current_value_field_name_ = options[:current_value_field_name] || UNDEFINED_CURRENT_VALUE_FIELD_NAME
|
34
|
+
|
33
35
|
class_eval %{
|
34
36
|
def #{_field_name_}(date=nil)
|
37
|
+
#{ (_current_value_field_name_ == UNDEFINED_CURRENT_VALUE_FIELD_NAME) ? "return self.#{_current_value_field_name_} if self.respond_to?('#{_current_value_field_name_}') && date.nil? " : '' }
|
38
|
+
pl = self.#{_field_name_}_log(date)
|
39
|
+
pl.price unless pl.nil?
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def #{_field_name_}_log(date=nil)
|
35
44
|
self.#{_relation_name_}.for_date(self.class.name, self.id, '#{_field_name_}', date).first
|
36
45
|
end
|
37
46
|
|
38
47
|
def #{_field_name_}=(amount)
|
39
48
|
ple = PriceLogEntry.new(priceable: self, price: amount, start_date: DateTime.now, priceable_field_name: '#{_field_name_}')
|
49
|
+
|
50
|
+
#{ (_current_value_field_name_ == UNDEFINED_CURRENT_VALUE_FIELD_NAME) ? "self.#{_current_value_field_name_} = amount if self.respond_to?('#{_current_value_field_name_}')" : ''}
|
51
|
+
|
40
52
|
self.#{_relation_name_} << ple
|
41
53
|
end
|
42
54
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: price_log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.81
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrzej Liśkiewicz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|