impromptu 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 1.4.0
data/impromptu.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{impromptu}
8
- s.version = "1.3.0"
8
+ s.version = "1.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Will Cannings"]
@@ -1,9 +1,9 @@
1
1
  module Impromptu
2
2
  class File
3
- attr_reader :path, :folder, :resources, :related_resources, :related_files, :modified_time
3
+ attr_reader :path, :folder, :resources, :related_resources, :related_files, :modified_time, :preload
4
4
  RELOADABLE_EXTENSIONS = %w{rb}
5
5
 
6
- def initialize(path, folder, provides=[])
6
+ def initialize(path, folder, preload=false, provides=[])
7
7
  @path = path
8
8
  @folder = folder
9
9
  @resources = OrderedSet.new
@@ -12,6 +12,7 @@ module Impromptu
12
12
  @frozen = false
13
13
  @modified_time = nil
14
14
  @dirty = true
15
+ @preload = preload
15
16
  @provides = [provides].compact.flatten
16
17
  end
17
18
 
@@ -27,6 +28,17 @@ module Impromptu
27
28
  @path.hash
28
29
  end
29
30
 
31
+ # Indicate whether this file needs to be preloaded
32
+ def preload=(preload)
33
+ @preload = preload
34
+ end
35
+
36
+ # True if this file needs to be preloaded before other files
37
+ # are automatically loaded on demand
38
+ def preload?
39
+ @preload
40
+ end
41
+
30
42
  # Traverse the file/resource graph to determine which total
31
43
  # set of files and resources are related to this file. For
32
44
  # instance, if a resource provided by this file is also
@@ -181,6 +193,7 @@ module Impromptu
181
193
  @provides.each do |resource_name|
182
194
  resource = Impromptu.root_resource.get_or_create_child(combine_symbol_with_namespace(resource_name))
183
195
  resource.add_file(self)
196
+ resource.preload = preload?
184
197
  @resources << resource
185
198
  end
186
199
  end
@@ -129,7 +129,8 @@ module Impromptu
129
129
  # * provides (required): an array of symbols, or a symbol
130
130
  # indicating the name of the resource(s) provided by the file
131
131
  def file(name, options={})
132
- file = Impromptu::File.new(@folder.join(*name).realpath, self, options[:provides])
132
+ file_preload = options[:preload] || preload?
133
+ file = Impromptu::File.new(@folder.join(*name).realpath, self, file_preload, options[:provides])
133
134
  @files.push(file).add_resource_definition
134
135
  end
135
136
 
@@ -158,7 +159,7 @@ module Impromptu
158
159
  # find all source files and add unseen files to the files list
159
160
  @folder.find do |path|
160
161
  next unless source_file?(path)
161
- file = Impromptu::File.new(path.realpath, self)
162
+ file = Impromptu::File.new(path.realpath, self, preload?)
162
163
  new_file_set << file
163
164
  unless @files.include?(file)
164
165
  changes = true
@@ -178,16 +179,6 @@ module Impromptu
178
179
  file.refreeze
179
180
  end
180
181
  end
181
-
182
- # ensure all resources defined by this folder
183
- # are marked to be preloaded if required
184
- if preload?
185
- @files.each do |file|
186
- file.resources.each do |resource|
187
- resource.preload = true
188
- end
189
- end
190
- end
191
182
  end
192
183
 
193
184
 
@@ -33,12 +33,13 @@ module Impromptu
33
33
  @name.hash
34
34
  end
35
35
 
36
- # Define this resource as preloaded
36
+ # Indicate whether this resource needs to be preloaded
37
37
  def preload=(preload)
38
38
  @preload = preload
39
39
  end
40
40
 
41
- # True if this resource is defined as preloaded
41
+ # True if this resource needs to be preloaded before other files
42
+ # are automatically loaded on demand
42
43
  def preload?
43
44
  @preload
44
45
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 3
7
+ - 4
8
8
  - 0
9
- version: 1.3.0
9
+ version: 1.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Will Cannings