bootscale 0.6.1 → 0.7.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
  SHA1:
3
- metadata.gz: 5a2ae71d209d672c9fbccd5e29cebc9fe7dd0228
4
- data.tar.gz: ff3837943dd68e75681abc7e6fefb8ca73511d75
3
+ metadata.gz: 0e8a7115523ee4c47e8de297ce8f08cebcd8a3d3
4
+ data.tar.gz: c31eccaae013c2207c3c7cafb9c6eaff41032b1e
5
5
  SHA512:
6
- metadata.gz: 87097f048d7d2bf8edd276cff0ff6babb0c074ad811e32d675eb27d519d67a9de7b64690e5739dbc96f33857d59ca1e1551c4c0b0d7776011abc86489ab42ab6
7
- data.tar.gz: cf22a9b415c0d6276ab9cdea0f12678cd0e46cde7af46846c3a68f3af1afb5969db83b77c362a046a1aa290ef2be9ae71ef30a4148e1e9dd829f809e0df51de9
6
+ metadata.gz: 473b089c1bc30b5ec2fc839d723c37a8aa90d7eaab92942bcd97913b0ee4fbb77378066bc7f5c4091e82a2d1547b18d6df4a1b2ed06df90f1da87a6a39b9f8d1
7
+ data.tar.gz: c3987e12ccabd2614d320353679b3453f5e6b6f421fadb9034106b8e68ad08127e7e083ada5f7fa9220eb87ee0fc7c33cd1038e0d863641a7a00b9b997897c71
@@ -1,3 +1,4 @@
1
+ require 'logger'
1
2
  require_relative 'bootscale/version'
2
3
 
3
4
  module Bootscale
@@ -7,6 +8,7 @@ module Bootscale
7
8
 
8
9
  class << self
9
10
  attr_reader :cache, :cache_directory
11
+ attr_accessor :logger
10
12
 
11
13
  def cache_builder
12
14
  @cache_builder ||= CacheBuilder.new
@@ -18,10 +20,13 @@ module Bootscale
18
20
 
19
21
  def setup(options = {})
20
22
  @cache_directory = options[:cache_directory]
21
- @cache = Cache.new(cache_directory)
23
+ cache_implementation = options.fetch(:development_mode, false) ? DevelopmentCache : Cache
24
+ @cache = cache_implementation.new(cache_directory)
22
25
  require_relative 'bootscale/core_ext'
23
26
  end
24
27
  end
28
+
29
+ self.logger = Logger.new(STDERR)
25
30
  end
26
31
 
27
32
  require_relative 'bootscale/entry'
@@ -1,6 +1,23 @@
1
1
  module Bootscale
2
2
  module ActiveSupport
3
- class Cache < ::Bootscale::Cache
3
+ class << self
4
+ attr_reader :cache, :cache_directory
5
+
6
+ def cache_builder
7
+ @cache_builder ||= CacheBuilder.new
8
+ end
9
+
10
+ def setup(options = {})
11
+ @cache_directory = options.fetch(:cache_directory, Bootscale.cache_directory)
12
+ require 'active_support'
13
+ require 'active_support/dependencies'
14
+ cache_implementation = options.fetch(:development_mode, false) ? DevelopmentCache : Cache
15
+ @cache = cache_implementation.new(cache_directory)
16
+ require_relative 'active_support/core_ext'
17
+ end
18
+ end
19
+
20
+ module CacheConcern
4
21
  def load_path
5
22
  ::ActiveSupport::Dependencies.autoload_paths
6
23
  end
@@ -22,19 +39,12 @@ module Bootscale
22
39
  end
23
40
  end
24
41
 
25
- class << self
26
- attr_reader :cache, :cache_directory
27
-
28
- def cache_builder
29
- @cache_builder ||= CacheBuilder.new
30
- end
42
+ class Cache < ::Bootscale::Cache
43
+ include CacheConcern
44
+ end
31
45
 
32
- def setup(options = {})
33
- @cache_directory = options.fetch(:cache_directory, Bootscale.cache_directory)
34
- require 'active_support/dependencies'
35
- @cache = Cache.new(cache_directory)
36
- require_relative 'active_support/core_ext'
37
- end
46
+ class DevelopmentCache < ::Bootscale::DevelopmentCache
47
+ include CacheConcern
38
48
  end
39
49
  end
40
50
  end
@@ -30,8 +30,12 @@ module Bootscale
30
30
 
31
31
  attr_reader :storage
32
32
 
33
+ def regenerate(rescan = false)
34
+ @cache = save(Bootscale.cache_builder.generate(load_path, rescan))
35
+ end
36
+
33
37
  def fetch(load_path)
34
- load || save(Bootscale.cache_builder.generate(load_path))
38
+ load || regenerate
35
39
  end
36
40
 
37
41
  def load
@@ -45,4 +49,16 @@ module Bootscale
45
49
  cache
46
50
  end
47
51
  end
52
+
53
+ class DevelopmentCache < Cache
54
+ def [](path)
55
+ absolute_path = super
56
+ if absolute_path && !::File.exist?(absolute_path)
57
+ Bootscale.logger.info { "[Bootscale] #{absolute_path} is missing, regenerating cache" }
58
+ regenerate(true)
59
+ return super
60
+ end
61
+ absolute_path
62
+ end
63
+ end
48
64
  end
@@ -4,13 +4,21 @@ module Bootscale
4
4
  @entries = {}
5
5
  end
6
6
 
7
+ def clear!
8
+ @entries = {}
9
+ end
10
+
7
11
  # generate the requireables cache from all current load-path entries
8
12
  # each load-path is cached individually, so new ones can be added or removed
9
13
  # but added/removed files will not be discovered
10
- def generate(load_path)
14
+ def generate(load_path, rescan = false)
11
15
  requireables = load_path.reverse_each.flat_map do |path|
12
16
  path = path.to_s
13
- entries[path] ||= Entry.new(path).requireables
17
+ if rescan
18
+ entries[path] = Entry.new(path).requireables
19
+ else
20
+ entries[path] ||= Entry.new(path).requireables
21
+ end
14
22
  end
15
23
  Hash[requireables]
16
24
  end
@@ -0,0 +1,3 @@
1
+ require_relative 'dev_setup'
2
+ require_relative 'active_support'
3
+ Bootscale::ActiveSupport.setup(development_mode: true)
@@ -0,0 +1,2 @@
1
+ require 'bootscale'
2
+ Bootscale.setup(cache_directory: 'tmp/bootscale', development_mode: true)
@@ -1,3 +1,3 @@
1
1
  module Bootscale
2
- VERSION = '0.6.1'
2
+ VERSION = '0.7.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootscale
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-09 00:00:00.000000000 Z
11
+ date: 2016-12-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Inspired by Aaron Patterson's talk on the subject
14
14
  email:
@@ -25,6 +25,8 @@ files:
25
25
  - lib/bootscale/cache.rb
26
26
  - lib/bootscale/cache_builder.rb
27
27
  - lib/bootscale/core_ext.rb
28
+ - lib/bootscale/dev_rails.rb
29
+ - lib/bootscale/dev_setup.rb
28
30
  - lib/bootscale/entry.rb
29
31
  - lib/bootscale/file_storage.rb
30
32
  - lib/bootscale/rails.rb