comable-core 0.7.0 → 0.7.1

This diff has not been reviewed by any users.
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: 7b21105a8f6d073d7b66ee2dba182428b5008d78
4
- data.tar.gz: c3c2f4c865dab49b010d16b658f14d1c0b5605b2
3
+ metadata.gz: 0ef459f5170d6bf67d798f586b4fb15799935358
4
+ data.tar.gz: 2b509ef0d762a5369d1210ab3c29a904fe33f5c2
5
5
  SHA512:
6
- metadata.gz: da54c6caa5b324b720030516906dbd355f3375bbc54a385f21c3e8fe9ee157e43c2455043132ba71d1a048a48e0f3ad5bbf326c1962193d2550123a3ae152039
7
- data.tar.gz: d2a46b412f7182914adf3abca17fcb2b1626f0cca649e255387c342660f5c7a62d548ed4902fb2e8d75bc874f135ad99a8198f28a359eb99e9270f8fcfc25c3e
6
+ metadata.gz: ba17a422dda10ebe99a4c5088349dc68de06f427b950b18e0660c95765789a8f59b6ae5afdd702e263168b4e5bf142e7ef654124b80beb380cf9a879bb97cf11
7
+ data.tar.gz: 26a44a40cafe32242b38497061234e8118db9980e75124f9e1bcdc42e685edb03e42ecf0607bea9ead7a63c418283d44515b1309f9b458e3a5ccedf974205da3
@@ -6,6 +6,8 @@ module Comable
6
6
 
7
7
  default_scope -> { order('position ASC') }
8
8
 
9
+ after_save :touch_all_products
10
+
9
11
  DEFAULT_PATH_NAME_DELIMITER = ' > '
10
12
 
11
13
  class << self
@@ -68,5 +70,9 @@ module Comable
68
70
  restore_from_jstree!(node['children'], category)
69
71
  end
70
72
  end
73
+
74
+ def touch_all_products
75
+ products.update_all(updated_at: Time.now)
76
+ end
71
77
  end
72
78
  end
@@ -4,7 +4,7 @@ module Comable
4
4
 
5
5
  mount_uploader :file, Comable::ImageUploader
6
6
 
7
- belongs_to :product, class_name: Comable::Product.name
7
+ belongs_to :product, class_name: Comable::Product.name, touch: true
8
8
 
9
9
  liquid_methods :url
10
10
 
@@ -8,7 +8,7 @@ module Comable
8
8
 
9
9
  has_many :variants, class_name: Comable::Variant.name, inverse_of: :product, dependent: :destroy
10
10
  has_many :images, -> { order(:id) }, class_name: Comable::Image.name, dependent: :destroy
11
- has_and_belongs_to_many :categories, class_name: Comable::Category.name, join_table: :comable_products_categories
11
+ has_and_belongs_to_many :categories, class_name: Comable::Category.name, join_table: :comable_products_categories, after_add: :touch_updated_at, after_remove: :touch_updated_at
12
12
 
13
13
  accepts_nested_attributes_for :variants, allow_destroy: true
14
14
  accepts_nested_attributes_for :images, allow_destroy: true
@@ -24,6 +24,15 @@ module Comable
24
24
 
25
25
  PREVIEW_SESSION_KEY = :preview_product
26
26
 
27
+ class << self
28
+ def cache_key
29
+ page = all.current_page if all.respond_to? :current_page
30
+ maximum_updated_at = maximum(:updated_at)
31
+ timestamp = maximum_updated_at.utc.to_s(cache_timestamp_format) if maximum_updated_at
32
+ "#{model_name.cache_key}/all-#{[page, timestamp, count].compact.join('-')}"
33
+ end
34
+ end
35
+
27
36
  def image_url
28
37
  image = images.first
29
38
  return image.url if image
@@ -109,5 +118,11 @@ module Comable
109
118
  deprecate :code, deprecator: Comable::Deprecator.instance
110
119
  deprecate :code=, deprecator: Comable::Deprecator.instance
111
120
  deprecate :option_types_attributes=, deprecator: Comable::Deprecator.instance
121
+
122
+ private
123
+
124
+ def touch_updated_at(_category)
125
+ touch if persisted?
126
+ end
112
127
  end
113
128
  end
@@ -10,7 +10,7 @@ module Comable
10
10
  include Comable::Liquidable
11
11
  include Comable::Stock::Csvable
12
12
 
13
- belongs_to :variant, class_name: Comable::Variant.name, inverse_of: :stocks
13
+ belongs_to :variant, class_name: Comable::Variant.name, inverse_of: :stocks, touch: true
14
14
  belongs_to :stock_location, class_name: Comable::StockLocation.name
15
15
 
16
16
  #
@@ -3,7 +3,7 @@ module Comable
3
3
  include Comable::Ransackable
4
4
  include Comable::Variant::Quantifier
5
5
 
6
- belongs_to :product, class_name: Comable::Product.name, inverse_of: :variants
6
+ belongs_to :product, class_name: Comable::Product.name, inverse_of: :variants, touch: true
7
7
  has_many :stocks, class_name: Comable::Stock.name, inverse_of: :variant, dependent: :destroy
8
8
 
9
9
  has_and_belongs_to_many :option_values, -> { order(:option_type_id, :created_at, :id) }, class_name: Comable::OptionValue.name, join_table: :comable_variants_option_values
@@ -0,0 +1,5 @@
1
+ class AddProductIdIndexToComableVariants < ActiveRecord::Migration
2
+ def change
3
+ add_index :comable_variants, :product_id
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddVariantIdIndexToComableStocks < ActiveRecord::Migration
2
+ def change
3
+ add_index :comable_stocks, :variant_id
4
+ end
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comable-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - YOSHIDA Hiroki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-20 00:00:00.000000000 Z
11
+ date: 2015-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -375,6 +375,8 @@ files:
375
375
  - db/migrate/20151013082845_remove_null_option_of_shipment_method_id_on_comable_shipments.rb
376
376
  - db/migrate/20151013194926_add_guest_token_index_to_comable_orders.rb
377
377
  - db/migrate/20151112102452_add_draft_to_comable_orders.rb
378
+ - db/migrate/20151129213103_add_product_id_index_to_comable_variants.rb
379
+ - db/migrate/20151129213205_add_variant_id_index_to_comable_stocks.rb
378
380
  - db/seeds.rb
379
381
  - db/seeds/comable/users.rb
380
382
  - lib/comable/core.rb