bsm-models 0.10.1 → 0.11.0

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
2
  SHA256:
3
- metadata.gz: fa6e7aaa2e0defdb2d52f9eb853df13bf006b87c44aea8d4478018e5d237ec7f
4
- data.tar.gz: 102767fc8eea2bbfde29f15fa33a332ad1e2a2a2ab65e7c9d401711cfc1670ae
3
+ metadata.gz: 07a5dbf9862a89755b6ea1d829651466227f856d27e203f5dd53a4466b576d27
4
+ data.tar.gz: 710753e8b26f19e564ceb8b16224419f3c2cfd4bd1247226f197d9c3a2ebf05b
5
5
  SHA512:
6
- metadata.gz: e13bde6a1f7611d67550a8fca9f25900d0a87a07676e17ba4037a608ce458b29c2f5492e28008410bb81a4fadf4c8fd62847c813c3ebc072e2ec94de81f2b61a
7
- data.tar.gz: 778270722323bf197641bce226ca4271e5584dd5616d54cba674147fd29ba4d4e961d0cae1b83ceb88daf4a9fff0e0b9c083488f50d298fb558f21977fb64a8f
6
+ metadata.gz: 196f8bf345b53f7c61c191ffbae886cd2c8bf8aac1996e2e3631e8ff114645e4325144ecf9184609133d9886d27911db2858a572163feaa87c67fd7774a5c75c
7
+ data.tar.gz: f4154249b9f00553d7b034fe2f24f48b26a98ad9f2c10881a2b98b7170384177b10621a6360f96598084cd02259c357da519da24a74d223768ddc05705aeb66d
@@ -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, 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.10.1
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-31 00:00:00.000000000 Z
11
+ date: 2019-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.1'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec
28
+ name: railties
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec-its
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: sqlite3
56
+ name: rspec-its
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: shoulda-matchers
70
+ name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: railties
84
+ name: shoulda-matchers
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.3.6
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.3.6
97
111
  description: ''
98
112
  email: dimitrij@blacksquaremedia.com
99
113
  executables: []
@@ -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.0.0
142
+ version: 2.3.0
129
143
  required_rubygems_version: !ruby/object:Gem::Requirement
130
144
  requirements:
131
145
  - - ">="
132
146
  - !ruby/object:Gem::Version
133
147
  version: 1.8.0
134
148
  requirements: []
135
- rubyforge_project:
136
- rubygems_version: 2.7.6
149
+ rubygems_version: 3.0.2
137
150
  signing_key:
138
151
  specification_version: 4
139
152
  summary: BSM's very custom model extensions