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 +4 -4
- data/lib/store_model.rb +1 -0
- data/lib/store_model/ext/active_model/attributes.rb +24 -0
- data/lib/store_model/ext/active_record/base.rb +22 -0
- data/lib/store_model/ext/parent_assignment.rb +19 -0
- data/lib/store_model/model.rb +2 -0
- data/lib/store_model/railtie.rb +15 -0
- data/lib/store_model/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ce3d56b41eb6a6b5ecd2a0014bccb1ab7aa2beb62c6a19a93351634a43dfdad
|
4
|
+
data.tar.gz: bff2ff2d10c97e7ae2f0eecece11541d14d9170c9fa7a7ba6a27d8c503c8d6d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8ab3b06a4b1b3eca5869aa8fafd2132556d0ab096509ffee4f9538d65a6f98bc6f1c9cc7178f9c0bf034202f104931d62c1aea10688f9c3b0e9c59f86e6446d
|
7
|
+
data.tar.gz: 4daf5b0f2300ca79061cc8d420d2206848629ac34a03cd8381034efcc8c7d2f7d2b066fa938cbf343934862f09b284e88495772e7e8bf6e68c4b437c859b2c8b
|
data/lib/store_model.rb
CHANGED
@@ -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
|
data/lib/store_model/model.rb
CHANGED
@@ -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
|
data/lib/store_model/version.rb
CHANGED
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.
|
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-
|
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
|