store_model 0.5.3 → 0.6.0

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: af63b9a0cfb1ce85d4d2d81418cf102a9c32470cedce2191fb86b07970e1e73a
4
- data.tar.gz: 9b109d3e56bbaad016f65b9c7db4ed3aa49091baae470546d94ebf1159bea081
3
+ metadata.gz: 3ce3d56b41eb6a6b5ecd2a0014bccb1ab7aa2beb62c6a19a93351634a43dfdad
4
+ data.tar.gz: bff2ff2d10c97e7ae2f0eecece11541d14d9170c9fa7a7ba6a27d8c503c8d6d2
5
5
  SHA512:
6
- metadata.gz: 485914961ef2a6c0d55705172d7f6251c1baf8802b5add498b4ce413f327926170748b008109fabae501b7c47a8293b131c79f95c90daa1ef39b59125ddbcd56
7
- data.tar.gz: 3e66a2591f425a77789bb3eb45922d9dc6c5e3c07e6902df71a38a091f808c5904052196b9f21dd421cb5646e6751d5fea910b57e232b014c78c111c542014cf
6
+ metadata.gz: f8ab3b06a4b1b3eca5869aa8fafd2132556d0ab096509ffee4f9538d65a6f98bc6f1c9cc7178f9c0bf034202f104931d62c1aea10688f9c3b0e9c59f86e6446d
7
+ data.tar.gz: 4daf5b0f2300ca79061cc8d420d2206848629ac34a03cd8381034efcc8c7d2f7d2b066fa938cbf343934862f09b284e88495772e7e8bf6e68c4b437c859b2c8b
data/lib/store_model.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "store_model/model"
4
4
  require "store_model/configuration"
5
+ require "store_model/railtie"
5
6
  require "active_model/validations/store_model_validator"
6
7
 
7
8
  module StoreModel # :nodoc:
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "store_model/ext/parent_assignment"
4
+
5
+ module StoreModel
6
+ # ActiveModel::Attributes patch with parent tracking support
7
+ module Attributes
8
+ include ParentAssignment
9
+
10
+ private
11
+
12
+ def attribute(*)
13
+ super.tap do |value|
14
+ assign_parent_to_store_model_relation(value)
15
+ end
16
+ end
17
+
18
+ def write_attribute(*)
19
+ super.tap do |value|
20
+ assign_parent_to_store_model_relation(value)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "store_model/ext/parent_assignment"
4
+
5
+ module StoreModel
6
+ # ActiveRecord::Base patch with parent tracking support
7
+ module Base
8
+ include ParentAssignment
9
+
10
+ def _read_attribute(*)
11
+ super.tap do |attribute|
12
+ assign_parent_to_store_model_relation(attribute)
13
+ end
14
+ end
15
+
16
+ def _write_attribute(*)
17
+ super.tap do |attribute|
18
+ assign_parent_to_store_model_relation(attribute)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StoreModel
4
+ # Helper methods for ActiveModel and ActiveRecord parent tracking support
5
+ module ParentAssignment
6
+ private
7
+
8
+ def assign_parent_to_store_model_relation(attribute)
9
+ assign_parent_to_singular_store_model(attribute)
10
+ return unless attribute.is_a?(Array)
11
+
12
+ attribute.each(&method(:assign_parent_to_singular_store_model))
13
+ end
14
+
15
+ def assign_parent_to_singular_store_model(item)
16
+ item.parent = self if item.is_a?(StoreModel::Model)
17
+ end
18
+ end
19
+ end
@@ -17,6 +17,8 @@ module StoreModel
17
17
  base.extend StoreModel::TypeBuilders
18
18
  end
19
19
 
20
+ attr_accessor :parent
21
+
20
22
  # Returns a hash representing the model. Some configuration can be
21
23
  # passed through +options+.
22
24
  #
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "store_model/ext/active_model/attributes"
4
+ require "store_model/ext/active_record/base"
5
+
6
+ module StoreModel # :nodoc:
7
+ class Railtie < Rails::Railtie # :nodoc:
8
+ config.to_prepare do |_app|
9
+ ActiveSupport.on_load(:active_record) do
10
+ ActiveModel::Attributes.prepend(Attributes)
11
+ prepend(Base)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StoreModel # :nodoc:
4
- VERSION = "0.5.3"
4
+ VERSION = "0.6.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: store_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - DmitryTsepelev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-05 00:00:00.000000000 Z
11
+ date: 2019-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -97,8 +97,12 @@ files:
97
97
  - lib/store_model/combine_errors_strategies/merge_error_strategy.rb
98
98
  - lib/store_model/configuration.rb
99
99
  - lib/store_model/enum.rb
100
+ - lib/store_model/ext/active_model/attributes.rb
101
+ - lib/store_model/ext/active_record/base.rb
102
+ - lib/store_model/ext/parent_assignment.rb
100
103
  - lib/store_model/model.rb
101
104
  - lib/store_model/nested_attributes.rb
105
+ - lib/store_model/railtie.rb
102
106
  - lib/store_model/type_builders.rb
103
107
  - lib/store_model/types.rb
104
108
  - lib/store_model/types/array_type.rb