bulk_loader 1.1.0 → 1.2.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: f333c3ac367e36f34c8612ab1d1860e827414d8bd388171bd18f05d23c61325d
4
- data.tar.gz: 201294000abe22d929ac1ae77c224635d582438442affffe493bc562dd5f06c8
3
+ metadata.gz: 3b828de71b675977a5e13ee65e0f46a7929717d712b54f38df4fd9f31442b8a8
4
+ data.tar.gz: d8dd3a45609fad64fc8a6f35f557b7660ca81c1e65b3bc889bfdad6ff06eea26
5
5
  SHA512:
6
- metadata.gz: afe87ce84b348f199062486aef49ee2f65601535245e4a3cf4a250ed3c6fd9e0281eb76a20e48a5f322bc9f4ab727c51842fa535bfd2ed9482dedbd173bbb1fd
7
- data.tar.gz: 0a377a26091d89683874c25d779641e3e876ce72a0ebd63aca3d968af577a3c1cb58bfb6af3d0adad02faae9ed7ba37b49c852d8a5c995aefac51c36b61afb20
6
+ metadata.gz: ed99f135707732b203fd5ab7517a808dbe5a54f46f5ad802099c77cf29337d38406715ef70d4c591d46f1c2ce1dfe3c2fec39c6e8f9249446be867494c368de1
7
+ data.tar.gz: 7e58ad0d7dea88ac8592a9a4261c67edf7efd55fcf5dfe0e35c2a9b8f6fe172abe963f46e7e61b8b00af2032e328da3d9bbe3ec626927d48fd9fa5eb2c0f46ce
@@ -0,0 +1,23 @@
1
+ name: Ruby
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ matrix:
11
+ ruby: ['2.6.x', '2.5.x', '2.4.x']
12
+
13
+ steps:
14
+ - uses: actions/checkout@v1
15
+ - name: Set up Ruby ${{ matrix.ruby }}
16
+ uses: actions/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby }}
19
+ - name: Build and test with Rake
20
+ run: |
21
+ gem install bundler
22
+ bundle install --jobs 4 --retry 3
23
+ bundle exec rake
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --format documentation
2
+ --warnings
2
3
  --color
data/.rubocop.yml CHANGED
@@ -11,10 +11,10 @@ AllCops:
11
11
  - 'example/**/*'
12
12
 
13
13
  Metrics/AbcSize:
14
- Max: 17
14
+ Max: 22
15
15
 
16
16
  Metrics/MethodLength:
17
- Max: 14
17
+ Max: 20
18
18
 
19
19
  Metrics/BlockLength:
20
20
  Exclude:
data/README.md CHANGED
@@ -80,7 +80,7 @@ class YourModel
80
80
  end
81
81
  ```
82
82
 
83
- #### export: false
83
+ #### export: false option ( default: true )
84
84
 
85
85
  :name method is just shorthand for bulk\_loader.public\_send(:name). So if you not want to create :name method, you can pass export: false to bulk\_loader definition.
86
86
 
@@ -100,6 +100,32 @@ then you can use this like followings.
100
100
  YourModel.new.bulk_loader.name
101
101
  ```
102
102
 
103
+ #### autoload: false option ( default: true )
104
+
105
+ If you set this option to false, +BulkLoader::UnloadAccessError+ occured when you does not call +YourModel.bulk\_loader.load explicitly on :name method.
106
+
107
+ ```ruby
108
+ class YourModel
109
+ include BulkLoader::DSL
110
+
111
+ bulk_loader :name, :mapped_key, default: nil, autoload: false do |mapped_keys|
112
+ # something with mapped_keys
113
+ end
114
+ end
115
+ ```
116
+
117
+ ```ruby
118
+ YourModel.new.name #=> raise error BulkLoader::UnloadAccessError
119
+ ```
120
+
121
+ You can pass this by calling load explicitly.
122
+
123
+ ```ruby
124
+ model = YourModel.new
125
+ YourModel.bulk_loader.load(:name, [model])
126
+ model.name #=> it does not raise BulkLoader::UnloadAccessError
127
+ ```
128
+
103
129
  ## Installation
104
130
 
105
131
  Add this line to your application's Gemfile:
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require 'rubocop/rake_task'
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new
5
7
 
6
- task :default => :spec
8
+ task :default => [:spec, :rubocop]
data/bulk_loader.gemspec CHANGED
@@ -20,10 +20,10 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.15"
24
- spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "bundler", ">= 1.15"
24
+ spec.add_development_dependency "rake", ">= 10.0"
25
25
  spec.add_development_dependency "rspec", "~> 3.0"
26
- spec.add_development_dependency "rubocop", "~> 0.49"
26
+ spec.add_development_dependency "rubocop", ">= 0.74"
27
27
  spec.add_development_dependency "guard", "~> 2.14"
28
28
  spec.add_development_dependency "guard-rspec", "~> 4.7.3"
29
29
  spec.add_development_dependency "guard-rubocop", "~> 1.3.0"
@@ -8,7 +8,11 @@ module BulkLoader
8
8
  end
9
9
 
10
10
  def lazy(name)
11
- @lazy_of[name] ||= BulkLoader::Lazy.new(@target)
11
+ @lazy_of[name] ||= BulkLoader::Lazy.new(@target, name: name)
12
+ end
13
+
14
+ def loaded?(name)
15
+ lazy(name).loaded?
12
16
  end
13
17
 
14
18
  def marshal_dump
@@ -35,7 +39,7 @@ module BulkLoader
35
39
  names = [name].freeze
36
40
  define_singleton_method(name) do
37
41
  attr = lazy(name)
38
- class_attribute.load(names, [self]) unless attr.loaded?
42
+ class_attribute.load(names, [self]) if !attr.loaded? && class_attribute.autoload?(name)
39
43
  attr.get
40
44
  end
41
45
  public_send(name)
@@ -6,12 +6,18 @@ module BulkLoader
6
6
  class ClassAttribute
7
7
  def initialize
8
8
  @loader_of = {}
9
+
10
+ @no_autoload_of = {}
9
11
  end
10
12
 
11
13
  def include?(name)
12
14
  @loader_of.include?(name)
13
15
  end
14
16
 
17
+ def autoload?(name)
18
+ !@no_autoload_of[name]
19
+ end
20
+
15
21
  def each(&block)
16
22
  @loader_of.each(&block)
17
23
  end
@@ -27,8 +33,9 @@ module BulkLoader
27
33
  end
28
34
  end
29
35
 
30
- def define_loader(name, loader)
36
+ def define_loader(name, loader, autoload: true)
31
37
  @loader_of[name] = loader
38
+ @no_autoload_of[name] = true unless autoload
32
39
  define_singleton_method(name) { loader }
33
40
  end
34
41
 
@@ -18,8 +18,11 @@ module BulkLoader
18
18
  name, mapping, options = *args
19
19
  options ||= {}
20
20
  does_export = options.delete(:export)
21
+ does_autoload = options.delete(:autoload)
22
+ does_autoload = true if does_autoload.nil?
21
23
 
22
- @bulk_loader.define_loader(name, BulkLoader::Loader.new(mapping, options, &block))
24
+ loader = BulkLoader::Loader.new(mapping, options, &block)
25
+ @bulk_loader.define_loader(name, loader, autoload: does_autoload)
23
26
 
24
27
  return if does_export == false
25
28
 
@@ -34,7 +37,7 @@ module BulkLoader
34
37
  end
35
38
 
36
39
  def bulk_loader
37
- return @bulk_loader if @bulk_loader
40
+ return @bulk_loader if defined?(@bulk_loader) && @bulk_loader
38
41
 
39
42
  @bulk_loader = BulkLoader::Attribute.new(self)
40
43
  end
@@ -1,18 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BulkLoader
4
+ class UnloadAccessError < StandardError; end
5
+
4
6
  # lazy class
5
7
  class Lazy
6
8
  attr_reader :target
7
9
 
8
- def initialize(target)
10
+ def initialize(target, name: nil)
9
11
  @loaded = false
10
12
  @value = nil
13
+ @name = name
11
14
  @target = target
12
15
  end
13
16
 
14
17
  def get
15
- raise 'data is not loaded!!' unless @loaded
18
+ raise UnloadAccessError, "#{@name} has not been loaded!!" unless @loaded
16
19
 
17
20
  @value
18
21
  end
@@ -39,7 +39,6 @@ module BulkLoader
39
39
 
40
40
  def get_mapping(lazy_objs)
41
41
  mapping_of = {}
42
- targets = lazy_objs.map(&:target)
43
42
  lazy_objs.each do |lazy_obj|
44
43
  target = lazy_obj.target
45
44
  mapped_target = @is_mapping_proc ? @mapping.call(target) : target.public_send(@mapping)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BulkLoader
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulk_loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keiji Yoshimi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-12 00:00:00.000000000 Z
11
+ date: 2019-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.15'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.15'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '0.49'
61
+ version: '0.74'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '0.49'
68
+ version: '0.74'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -115,6 +115,7 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".github/workflows/ruby.yml"
118
119
  - ".gitignore"
119
120
  - ".rspec"
120
121
  - ".rubocop.yml"