bsm-models 0.10.0 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/bsm/model.rb +3 -2
- data/lib/bsm/model/abstract.rb +6 -7
- data/lib/bsm/model/coders/abstract_column.rb +7 -8
- data/lib/bsm/model/coders/json_column.rb +4 -6
- data/lib/bsm/model/coders/marshal_column.rb +4 -6
- data/lib/bsm/model/deletable.rb +0 -1
- data/lib/bsm/model/eager_descendants.rb +11 -13
- data/lib/bsm/model/editable.rb +4 -5
- data/lib/bsm/model/has_many_serialized.rb +2 -6
- data/lib/bsm/model/sti_convertable.rb +7 -9
- metadata +25 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 37b0f8692505a8c0eb8e1410f1421139f9247a5302ef839e092a38e1aef44a51
|
4
|
+
data.tar.gz: 4acbd231917862f721aa9e94cf2bed96ac87c0ab31a1a51cf6e2bbe8b42ef173
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d82f0494a4a1157b203d35a5dd7e5db0bc0987d813ead7c28eb7f399ef1c4a9f44cbf4909db7f8c2e647cb3352e231a8c309f80a8dec8434780f0c6c5af1081
|
7
|
+
data.tar.gz: efb282c26b87a863cc09021f266924a0a2ac7544f39af116d4b1a75cd3f4667d6f17916b0c89e7c1bd26cdd22bb1d1bbbdb49bae01c3640bbb2f12e1bc68d1b3
|
data/lib/bsm/model.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
begin
|
2
2
|
require 'rails'
|
3
3
|
rescue LoadError
|
4
|
+
nil
|
4
5
|
end
|
5
6
|
|
6
7
|
module Bsm
|
@@ -11,11 +12,11 @@ module Bsm
|
|
11
12
|
autoload :EagerDescendants, 'bsm/model/eager_descendants'
|
12
13
|
autoload :StiConvertable, 'bsm/model/sti_convertable'
|
13
14
|
autoload :HasManySerialized, 'bsm/model/has_many_serialized'
|
14
|
-
autoload :Coders,
|
15
|
+
autoload :Coders, 'bsm/model/coders'
|
15
16
|
end
|
16
17
|
|
17
18
|
class Railtie < ::Rails::Railtie
|
18
19
|
require 'active_support/i18n'
|
19
|
-
I18n.load_path << File.expand_path('
|
20
|
+
I18n.load_path << File.expand_path('model/locale/en.yml', __dir__)
|
20
21
|
end if defined?(::Rails::Railtie)
|
21
22
|
end
|
data/lib/bsm/model/abstract.rb
CHANGED
@@ -8,13 +8,12 @@ module Bsm::Model::Abstract
|
|
8
8
|
errors.add :base, :abstract if abstract_model_instance?
|
9
9
|
end
|
10
10
|
|
11
|
-
class_eval <<-
|
12
|
-
def abstract_model_instance?
|
13
|
-
self.class >= ::#{self.
|
14
|
-
end
|
15
|
-
|
11
|
+
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
12
|
+
def abstract_model_instance? # def abstract_model_instance?
|
13
|
+
self.class >= ::#{name} # self.class >= ::ThisModel
|
14
|
+
end # end
|
15
|
+
METHOD
|
16
16
|
|
17
17
|
protected :must_not_be_abstract, :abstract_model_instance?
|
18
18
|
end
|
19
|
-
|
20
|
-
end
|
19
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
class Bsm::Model::Coders::AbstractColumn
|
2
|
-
|
3
2
|
def self.rescue_errors
|
4
3
|
[]
|
5
4
|
end
|
@@ -12,18 +11,19 @@ class Bsm::Model::Coders::AbstractColumn
|
|
12
11
|
@object_class = object_class
|
13
12
|
end
|
14
13
|
|
15
|
-
def dump(
|
14
|
+
def dump(_obj)
|
16
15
|
not_implemented
|
17
16
|
end
|
18
17
|
|
19
18
|
def load(string)
|
20
19
|
return object_class.new if object_class != Object && string.nil?
|
20
|
+
|
21
21
|
begin
|
22
|
-
obj = object_class
|
22
|
+
obj = string.is_a?(object_class) ? string : _load(string)
|
23
23
|
|
24
24
|
unless obj.is_a?(object_class) || obj.nil?
|
25
25
|
raise ActiveRecord::SerializationTypeMismatch,
|
26
|
-
|
26
|
+
"Attribute was supposed to be a #{object_class}, but was a #{obj.class}"
|
27
27
|
end
|
28
28
|
obj ||= object_class.new if object_class != Object
|
29
29
|
|
@@ -35,8 +35,7 @@ class Bsm::Model::Coders::AbstractColumn
|
|
35
35
|
|
36
36
|
protected
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
def _load(_string)
|
39
|
+
raise NotImplementedError
|
40
|
+
end
|
42
41
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
class Bsm::Model::Coders::JsonColumn < Bsm::Model::Coders::AbstractColumn
|
2
|
-
|
3
2
|
def self.rescue_errors
|
4
|
-
[
|
3
|
+
[::JSON::ParserError]
|
5
4
|
end
|
6
5
|
|
7
6
|
def dump(obj)
|
@@ -10,8 +9,7 @@ class Bsm::Model::Coders::JsonColumn < Bsm::Model::Coders::AbstractColumn
|
|
10
9
|
|
11
10
|
protected
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
def _load(string)
|
13
|
+
ActiveSupport::JSON.decode(string)
|
14
|
+
end
|
17
15
|
end
|
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'base64'
|
2
2
|
|
3
3
|
class Bsm::Model::Coders::MarshalColumn < Bsm::Model::Coders::AbstractColumn
|
4
|
-
|
5
4
|
def self.rescue_errors
|
6
|
-
[
|
5
|
+
[ArgumentError, TypeError]
|
7
6
|
end
|
8
7
|
|
9
8
|
def dump(obj)
|
@@ -12,8 +11,7 @@ class Bsm::Model::Coders::MarshalColumn < Bsm::Model::Coders::AbstractColumn
|
|
12
11
|
|
13
12
|
protected
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
def _load(string)
|
15
|
+
Marshal.load(Base64.decode64(string))
|
16
|
+
end
|
19
17
|
end
|
data/lib/bsm/model/deletable.rb
CHANGED
@@ -2,25 +2,23 @@ module Bsm::Model::EagerDescendants
|
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
module ClassMethods
|
5
|
-
|
6
5
|
def descendants
|
7
|
-
eager_constantize!
|
6
|
+
eager_constantize!
|
8
7
|
super
|
9
8
|
end
|
10
9
|
|
11
10
|
private
|
12
11
|
|
13
|
-
|
14
|
-
|
12
|
+
def eager_constantize!
|
13
|
+
return if @__eagerly_constantized__
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
Dir[File.join(load_path, parent_name.underscore, "**", "*.rb")].each do |file|
|
20
|
-
ActiveSupport::Dependencies.depend_on file
|
21
|
-
end
|
22
|
-
@__eagerly_constantized__ = true
|
15
|
+
load_path = $LOAD_PATH.find do |path|
|
16
|
+
File.exist? File.join(path, "#{name.underscore}.rb")
|
23
17
|
end
|
24
|
-
|
18
|
+
Dir[File.join(load_path, module_parent_name.underscore, '**', '*.rb')].each do |file|
|
19
|
+
ActiveSupport::Dependencies.depend_on file
|
20
|
+
end
|
21
|
+
@__eagerly_constantized__ = true
|
22
|
+
end
|
25
23
|
end unless Rails.application.config.respond_to?(:eager_load) && Rails.application.config.eager_load
|
26
|
-
end
|
24
|
+
end
|
data/lib/bsm/model/editable.rb
CHANGED
@@ -2,7 +2,7 @@ module Bsm::Model::Editable
|
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
included do
|
5
|
-
validate :must_be_editable, :
|
5
|
+
validate :must_be_editable, on: :update
|
6
6
|
attr_accessor :force_editable
|
7
7
|
end
|
8
8
|
|
@@ -16,8 +16,7 @@ module Bsm::Model::Editable
|
|
16
16
|
|
17
17
|
protected
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
def must_be_editable
|
20
|
+
errors.add :base, :immutable if immutable?
|
21
|
+
end
|
23
22
|
end
|
@@ -4,19 +4,15 @@ module Bsm::Model::HasManySerialized
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
module ClassMethods
|
7
|
-
|
8
7
|
def has_many_serialized(name, scope = nil, options = {})
|
9
8
|
Builder.build(self, name, scope, options)
|
10
9
|
end
|
11
|
-
|
12
10
|
end
|
13
11
|
|
14
12
|
class Builder < ActiveRecord::Associations::Builder::CollectionAssociation
|
15
|
-
|
16
13
|
def self.build(model, name, *)
|
17
14
|
model.serialize "#{name.to_s.singularize}_ids", ::Bsm::Model::Coders::JsonColumn.new(Array)
|
18
|
-
super
|
19
|
-
end
|
15
|
+
super
|
20
16
|
end
|
21
17
|
|
22
18
|
def self.define_accessors(model, reflection)
|
@@ -33,6 +29,7 @@ module Bsm::Model::HasManySerialized
|
|
33
29
|
records = Array.wrap(records)
|
34
30
|
records.each do |record|
|
35
31
|
next if record.is_a?(klass)
|
32
|
+
|
36
33
|
raise ActiveRecord::AssociationTypeMismatch, "#{klass.name} expected, got #{record.class}"
|
37
34
|
end
|
38
35
|
write_attribute attribute_name, records.map(&:id).sort
|
@@ -50,6 +47,5 @@ module Bsm::Model::HasManySerialized
|
|
50
47
|
def valid_dependent_options
|
51
48
|
[]
|
52
49
|
end
|
53
|
-
|
54
50
|
end
|
55
51
|
end
|
@@ -3,10 +3,11 @@ module Bsm::Model::StiConvertable
|
|
3
3
|
|
4
4
|
included do
|
5
5
|
include Bsm::Model::EagerDescendants
|
6
|
+
|
6
7
|
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
7
|
-
def self.real_type?
|
8
|
-
self < ::#{name}
|
9
|
-
end
|
8
|
+
def self.real_type? # def real_type?
|
9
|
+
self < ::#{name} # self.class < ::ThisModel
|
10
|
+
end # end
|
10
11
|
METHOD
|
11
12
|
end
|
12
13
|
|
@@ -15,10 +16,9 @@ module Bsm::Model::StiConvertable
|
|
15
16
|
end
|
16
17
|
|
17
18
|
module ClassMethods
|
18
|
-
|
19
19
|
# @Override: Allow to specify a kind
|
20
20
|
def new(attributes = nil, *args, &block)
|
21
|
-
kind = attributes.delete(:kind) { attributes.delete('kind') }
|
21
|
+
kind = attributes.delete(:kind) { attributes.delete('kind') } if attributes.respond_to?(:delete)
|
22
22
|
return super if real_type?
|
23
23
|
|
24
24
|
klass = real_descendants.find {|k| k.kind == kind } || fallback_descendant
|
@@ -38,11 +38,9 @@ module Bsm::Model::StiConvertable
|
|
38
38
|
def kind
|
39
39
|
name.demodulize.underscore
|
40
40
|
end
|
41
|
-
|
42
41
|
end
|
43
42
|
|
44
|
-
delegate :kind, :
|
43
|
+
delegate :kind, to: 'self.class'
|
45
44
|
|
46
|
-
def kind=(
|
47
|
-
end
|
45
|
+
def kind=(_val); end
|
48
46
|
end
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bsm-models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitrij Denissenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '6.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: railties
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,7 +67,7 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rubocop-bsm
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ">="
|
@@ -81,7 +95,7 @@ dependencies:
|
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: sqlite3
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - ">="
|
@@ -125,15 +139,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
139
|
requirements:
|
126
140
|
- - ">="
|
127
141
|
- !ruby/object:Gem::Version
|
128
|
-
version: 2.
|
142
|
+
version: '2.6'
|
129
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
144
|
requirements:
|
131
145
|
- - ">="
|
132
146
|
- !ruby/object:Gem::Version
|
133
|
-
version:
|
147
|
+
version: '0'
|
134
148
|
requirements: []
|
135
|
-
|
136
|
-
rubygems_version: 2.6.11
|
149
|
+
rubygems_version: 3.1.4
|
137
150
|
signing_key:
|
138
151
|
specification_version: 4
|
139
152
|
summary: BSM's very custom model extensions
|