bsm-models 0.9.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 68a107120c0c5f44c411f7447348323a7c0ca6ee
4
- data.tar.gz: ae4e2a600e05ce1eb233affd003e21ebcea2ceca
2
+ SHA256:
3
+ metadata.gz: 4f4aa0f0eb8e4f1d0177ff328886762f34f2ca6b7be2f29be6e6d81b7082f932
4
+ data.tar.gz: 4ba6ae82c5276b0a594203faeb37d3bc66db87815b8c79ec042fae424f9ac3aa
5
5
  SHA512:
6
- metadata.gz: d82015d125b38b3185e0ac731884b1082b8d1780210c30f2eef49a621f694c8f0cad045e858225c6f74f2d80a582c35875b9cd568d0a58aabdb2ac19bf848980
7
- data.tar.gz: 33e2006f7fe15c1eed43d92fd4897ed571b542ada330461c4390f3676769f42f94900ad3edc80293175857f9b288fc6a98efa7b1dfb357dd9748d337a3026fd3
6
+ metadata.gz: 248ff7b584f16b6c29e8238dcd32fe610317ecd3f58d5ad659ff7753f8d6bc7cd1caeb67c94385c5270592f73f36de32da82d5399b7f6690c215390455944537
7
+ data.tar.gz: b20a1ba4f587ad84b407c447ba3cd978910b068141fa4337e0e81919b76780b73a79e7bdb290cc83d80a66b2183c3a58325da8758703c7e34d18d8819f3cb58c
@@ -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, 'bsm/model/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('../model/locale/en.yml', __FILE__)
20
+ I18n.load_path << File.expand_path('model/locale/en.yml', __dir__)
20
21
  end if defined?(::Rails::Railtie)
21
22
  end
@@ -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 <<-END_EVAL
11
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
12
12
  def abstract_model_instance?
13
- self.class >= ::#{self.name}
13
+ self.class >= ::#{name}
14
14
  end
15
- END_EVAL
15
+ METHOD
16
16
 
17
17
  protected :must_not_be_abstract, :abstract_model_instance?
18
18
  end
19
-
20
- end
19
+ end
@@ -8,18 +8,19 @@ class Bsm::Model::Coders::AbstractColumn
8
8
  attr_reader :object_class
9
9
 
10
10
  # @param [Class] obejct_class
11
- def initialize(object_class = Object)
11
+ def initialize(object_class=Object)
12
12
  @object_class = object_class
13
13
  end
14
14
 
15
- def dump(obj)
15
+ def dump(_obj)
16
16
  not_implemented
17
17
  end
18
18
 
19
19
  def load(string)
20
20
  return object_class.new if object_class != Object && string.nil?
21
+
21
22
  begin
22
- obj = object_class === string ? string : _load(string)
23
+ obj = string.is_a?(object_class) ? string : _load(string)
23
24
 
24
25
  unless obj.is_a?(object_class) || obj.nil?
25
26
  raise ActiveRecord::SerializationTypeMismatch,
@@ -35,8 +36,8 @@ class Bsm::Model::Coders::AbstractColumn
35
36
 
36
37
  protected
37
38
 
38
- def _load(string)
39
- raise NotImplementedError
40
- end
39
+ def _load(_string)
40
+ raise NotImplementedError
41
+ end
41
42
 
42
43
  end
@@ -1,7 +1,7 @@
1
1
  class Bsm::Model::Coders::JsonColumn < Bsm::Model::Coders::AbstractColumn
2
2
 
3
3
  def self.rescue_errors
4
- [ ::JSON::ParserError ]
4
+ [::JSON::ParserError]
5
5
  end
6
6
 
7
7
  def dump(obj)
@@ -10,8 +10,8 @@ class Bsm::Model::Coders::JsonColumn < Bsm::Model::Coders::AbstractColumn
10
10
 
11
11
  protected
12
12
 
13
- def _load(string)
14
- ActiveSupport::JSON.decode(string)
15
- end
13
+ def _load(string)
14
+ ActiveSupport::JSON.decode(string)
15
+ end
16
16
 
17
17
  end
@@ -3,7 +3,7 @@ require 'base64'
3
3
  class Bsm::Model::Coders::MarshalColumn < Bsm::Model::Coders::AbstractColumn
4
4
 
5
5
  def self.rescue_errors
6
- [ ArgumentError, TypeError ]
6
+ [ArgumentError, TypeError]
7
7
  end
8
8
 
9
9
  def dump(obj)
@@ -12,8 +12,8 @@ class Bsm::Model::Coders::MarshalColumn < Bsm::Model::Coders::AbstractColumn
12
12
 
13
13
  protected
14
14
 
15
- def _load(string)
16
- Marshal.load(Base64.decode64(string))
17
- end
15
+ def _load(string)
16
+ Marshal.load(Base64.decode64(string))
17
+ end
18
18
 
19
19
  end
@@ -14,5 +14,4 @@ module Bsm::Model::Deletable
14
14
  def check_deletable?
15
15
  throw :abort unless deletable?
16
16
  end
17
-
18
17
  end
@@ -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
- def eager_constantize!
14
- return if @__eagerly_constantized__
12
+ def eager_constantize!
13
+ return if @__eagerly_constantized__
15
14
 
16
- load_path = $LOAD_PATH.find do |path|
17
- File.exist? File.join(path, "#{name.underscore}.rb")
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
@@ -2,7 +2,7 @@ module Bsm::Model::Editable
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  included do
5
- validate :must_be_editable, :on => :update
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
- def must_be_editable
20
- errors.add :base, :immutable if immutable?
21
- end
22
-
19
+ def must_be_editable
20
+ errors.add :base, :immutable if immutable?
21
+ end
23
22
  end
@@ -4,11 +4,9 @@ module Bsm::Model::HasManySerialized
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  module ClassMethods
7
-
8
- def has_many_serialized(name, scope = nil, options = {})
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
@@ -33,6 +31,7 @@ module Bsm::Model::HasManySerialized
33
31
  records = Array.wrap(records)
34
32
  records.each do |record|
35
33
  next if record.is_a?(klass)
34
+
36
35
  raise ActiveRecord::AssociationTypeMismatch, "#{klass.name} expected, got #{record.class}"
37
36
  end
38
37
  write_attribute attribute_name, records.map(&:id).sort
@@ -15,10 +15,9 @@ module Bsm::Model::StiConvertable
15
15
  end
16
16
 
17
17
  module ClassMethods
18
-
19
18
  # @Override: Allow to specify a kind
20
- def new(attributes = nil, *args, &block)
21
- kind = attributes.delete(:kind) { attributes.delete('kind') } if attributes.respond_to?(:delete)
19
+ def new(attributes=nil, *args, &block)
20
+ kind = attributes.delete(:kind) { attributes.delete('kind') } if attributes.respond_to?(:delete)
22
21
  return super if real_type?
23
22
 
24
23
  klass = real_descendants.find {|k| k.kind == kind } || fallback_descendant
@@ -38,11 +37,9 @@ module Bsm::Model::StiConvertable
38
37
  def kind
39
38
  name.demodulize.underscore
40
39
  end
41
-
42
40
  end
43
41
 
44
- delegate :kind, :to => 'self.class'
42
+ delegate :kind, to: 'self.class'
45
43
 
46
- def kind=(_)
47
- end
44
+ def kind=(_val); end
48
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bsm-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-16 00:00:00.000000000 Z
11
+ date: 2019-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,20 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '5.1'
19
+ version: '6.0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: '5.0'
30
- - - "<"
26
+ version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
31
32
  - !ruby/object:Gem::Version
32
- version: '5.1'
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'
33
41
  - !ruby/object:Gem::Dependency
34
42
  name: rspec
35
43
  requirement: !ruby/object:Gem::Requirement
@@ -59,7 +67,7 @@ dependencies:
59
67
  - !ruby/object:Gem::Version
60
68
  version: '0'
61
69
  - !ruby/object:Gem::Dependency
62
- name: sqlite3
70
+ name: rubocop
63
71
  requirement: !ruby/object:Gem::Requirement
64
72
  requirements:
65
73
  - - ">="
@@ -87,7 +95,7 @@ dependencies:
87
95
  - !ruby/object:Gem::Version
88
96
  version: '0'
89
97
  - !ruby/object:Gem::Dependency
90
- name: railties
98
+ name: sqlite3
91
99
  requirement: !ruby/object:Gem::Requirement
92
100
  requirements:
93
101
  - - ">="
@@ -131,15 +139,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
139
  requirements:
132
140
  - - ">="
133
141
  - !ruby/object:Gem::Version
134
- version: 2.0.0
142
+ version: '2.5'
135
143
  required_rubygems_version: !ruby/object:Gem::Requirement
136
144
  requirements:
137
145
  - - ">="
138
146
  - !ruby/object:Gem::Version
139
- version: 1.8.0
147
+ version: '0'
140
148
  requirements: []
141
- rubyforge_project:
142
- rubygems_version: 2.5.2
149
+ rubygems_version: 3.0.3
143
150
  signing_key:
144
151
  specification_version: 4
145
152
  summary: BSM's very custom model extensions