item_builder 0.1.13 → 0.1.14

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: f30c408c745d0be7fec186569f4015f4f758db7aef762a325fc001b23a930d47
4
- data.tar.gz: 5eea167ecc2c308e7f947fc48332cb64f51098b51b5da16bb8159dc3e1794e80
3
+ metadata.gz: 7f8232744164229bf81eaf5dc1069c9f56fd83d110c48d51088a2284e52dd2e5
4
+ data.tar.gz: fbbb12a28d964bc6badd2c5914ca8b0dab476576fb0d8009c4fff230d8ff8afe
5
5
  SHA512:
6
- metadata.gz: 237d19131993e4fec10b22704357c5d9204393021d509072db31b2e333e418acae87a9f2d2c4cb3876dd547eb34e6211204051492dfb65ae757b330bdcf7721f
7
- data.tar.gz: 6f9c343067f6a134dc20fba3e91ed5c5ab276364e121dc17e512455ffb460969e5578c84304140cbb352844898ac9f2dadddd9779171c1639a40ec647707430f
6
+ metadata.gz: f51bf30b10eb630cf99ec445ff4192ee150c32ac5b731a007103ab9329e47bd6fb4f49179b7762f302827bbe3a7ad9e72099465c3925984bf9278be58c316273
7
+ data.tar.gz: 3c2ecb37ead73a59dd4b9158fa66eadbdd196d77c58eee56b23b859cd57c02a76d3a9c251313dda44ceea88d1cd8f72d382d331e5767a08205c679b004e74f71
@@ -10,13 +10,58 @@ require 'item_models'
10
10
 
11
11
  module ItemBuilder
12
12
  class << self
13
+ attr_reader :listing_ids
14
+ attr_reader :listings
15
+ attr_reader :mode
16
+ attr_reader :wh_spaces
17
+ attr_reader :variants
18
+ attr_reader :variant_ids
13
19
  def build(listing_ids, mode)
20
+ @listing_ids = listing_ids
14
21
  @mode = mode
15
- VariantListing.where(id: listing_ids).map do |listing|
22
+ mode_check
23
+ end
24
+
25
+ def mode_check
26
+ if mode == :quantity
27
+ quantity_mode
28
+ else
29
+ default
30
+ end
31
+ end
32
+
33
+ def quantity_mode
34
+ listings.map do |listing|
35
+ modes[mode].new(
36
+ listing: listing,
37
+ wh_spaces: wh_spaces,
38
+ variants: variants
39
+ ).perform
40
+ end
41
+ end
42
+
43
+ def default
44
+ listings.map do |listing|
16
45
  modes[mode].new(listing: listing).perform
17
46
  end
18
47
  end
19
48
 
49
+ def wh_spaces
50
+ @wh_spaces ||= WarehouseSpace.where(item_variant_id: variant_ids)
51
+ end
52
+
53
+ def variants
54
+ @variants ||= Variant.where(id: variant_ids)
55
+ end
56
+
57
+ def variant_ids
58
+ @variant_ids ||= listings.map(&:variant_id).uniq
59
+ end
60
+
61
+ def listings
62
+ @listings ||= VariantListing.where(id: listing_ids)
63
+ end
64
+
20
65
  def modes
21
66
  {
22
67
  price: ItemBuilder::Modes::PriceService,
@@ -9,8 +9,12 @@ require 'item_builder/modes/update_service'
9
9
  module ItemBuilder
10
10
  module Modes
11
11
  attr_reader :listing
12
+ attr_reader :wh_spaces
13
+ attr_reader :variants
12
14
  def initialize(args)
13
15
  @listing = args.fetch(:listing)
16
+ @wh_spaces = args.fetch(:wh_spaces) || []
17
+ @variants = args.fetch(:variants) || []
14
18
  end
15
19
 
16
20
  def base
@@ -55,11 +55,11 @@ module ItemBuilder
55
55
  end
56
56
 
57
57
  def warehouse
58
- WarehouseSpace.find_by(item_variant_id: listing.variant_id)
58
+ wh_spaces.select {|ws| ws.item_variant_id == listing.variant_id }.first
59
59
  end
60
60
 
61
61
  def variant
62
- @variant ||= Variant.find(listing.variant_id)
62
+ variants.select {|v| v.id == listing.variant_id }.first
63
63
  end
64
64
  end
65
65
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ItemBuilder
4
- VERSION = '0.1.13'
4
+ VERSION = '0.1.14'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: item_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - okaaryanata
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-08 00:00:00.000000000 Z
11
+ date: 2021-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler