unidom-product 0.3 → 0.4

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
  SHA1:
3
- metadata.gz: 388edde88bb09434d63ff9a0bd6e1473ade4f16c
4
- data.tar.gz: 3b2eb0a046a4b04de46cb28e108e63e225dc9a78
3
+ metadata.gz: e624865efbaf6ba17d3f4e149bfc4c0e7782d61f
4
+ data.tar.gz: 41ca96e289af3cc75d74cbd62b8897fa3b49f200
5
5
  SHA512:
6
- metadata.gz: 9f2bc5b3bad27833224eef03a1542a2001a3363ad4b8647855b0148137b330ec8bda5087d64d3992bba0ae66ad7761aaa4992728a4b7eb7d4deb8d49006c013b
7
- data.tar.gz: 69b7c736b9ab7d7a6deb36eaa6eba1fd47db6d6490005f3acdb147eacd0e16bf46d36170b29a10279743925c094adf12f0ceacab8cdbc26977b77d58424d03b7
6
+ metadata.gz: f490de65ab811c55c5381274ddecb82ac1626aace2b618c96c6e18ccf9950c351f4d1d8dba93d25ed6def6515396baa16b848ea7da5a9b1c3ce64e80cced514b
7
+ data.tar.gz: e3be10c8e5db2b8029e1df961b6cd7dd3ff92bf8c547dec33061b5fa9aec1fbc432081a8289ac3ef84c0586d0cf763d635f0d928378dfadc6dc600bc89d4d6ee
@@ -19,4 +19,23 @@ class Unidom::Product::ProductAssociating < ActiveRecord::Base
19
19
  belongs_to :source, class_name: 'Unidom::Product::Product'
20
20
  belongs_to :target, class_name: 'Unidom::Product::Product'
21
21
 
22
+ scope :source_is, ->(product) { where source_id: to_id(product) }
23
+ scope :target_is, ->(product) { where target_id: to_id(product) }
24
+
25
+ def self.associate!(source, target, product_association_code, ordinal = 1, quantity = 1, opened_at = Time.now)
26
+
27
+ associating = source_is(source).target_is(target).product_association_coded_as(product_association_code).valid_at.alive.first
28
+ associating.soft_destroy if associating.present?
29
+
30
+ #if associating.present?
31
+ # associating.attributes = { ordinal: ordinal, quantity: quantity, opened_at: opened_at }
32
+ # associating.save!
33
+ #else
34
+ # associating = create! source_id: to_id(source), target_id: to_id(target), product_association_code: product_association_code, ordinal: ordinal, quantity: quantity, opened_at: opened_at
35
+ #end
36
+ #associating
37
+ create! source_id: to_id(source), target_id: to_id(target), product_association_code: product_association_code, ordinal: ordinal, quantity: quantity, opened_at: opened_at
38
+
39
+ end
40
+
22
41
  end
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Product
3
- VERSION = '0.3'.freeze
3
+ VERSION = '0.4'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-product
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.4'
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-10 00:00:00.000000000 Z
11
+ date: 2016-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common