pinion 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,9 +3,13 @@ require "time"
3
3
 
4
4
  module Pinion
5
5
  class DirectoryWatcher
6
- def initialize(root = ".")
6
+ # Assume a static filesystem if options[:static] = true. Used in production mode.
7
+ def initialize(root = ".", options = {})
7
8
  @root = root
8
9
  @watch_directories = Set.new
10
+ if @static = options[:static]
11
+ @find_cache = {}
12
+ end
9
13
  end
10
14
 
11
15
  def <<(directory) @watch_directories << File.join(@root, directory) end
@@ -20,11 +24,17 @@ module Pinion
20
24
  end
21
25
 
22
26
  def find(path)
27
+ return @find_cache[path] if (@static && @find_cache.include?(path))
28
+ result = nil
23
29
  @watch_directories.each do |directory|
24
- result = File.join(directory, path)
25
- return result if File.file? result
30
+ filename = File.join(directory, path)
31
+ if File.file? filename
32
+ result = filename
33
+ break
34
+ end
26
35
  end
27
- nil
36
+ @find_cache[path] = result if @static
37
+ result
28
38
  end
29
39
 
30
40
  def latest_mtime_with_suffix(suffix)
@@ -10,10 +10,10 @@ module Pinion
10
10
  # because we need that information before requests are handled due to #asset_url
11
11
  def initialize(mount_point)
12
12
  @mount_point = mount_point
13
- @watcher = DirectoryWatcher.new
13
+ @environment = (defined?(RACK_ENV) && RACK_ENV) || ENV["RACK_ENV"] || "development"
14
+ @watcher = DirectoryWatcher.new ".", :static => (@environment == "production")
14
15
  @cached_assets = {}
15
16
  @file_server = Rack::File.new(Dir.pwd)
16
- @environment = (defined?(RACK_ENV) && RACK_ENV) || ENV["RACK_ENV"] || "development"
17
17
  end
18
18
 
19
19
  def convert(from_and_to, &block)
@@ -123,6 +123,7 @@ module Pinion
123
123
  def find_asset(to_path)
124
124
  asset = @cached_assets[to_path]
125
125
  if asset
126
+ return asset if @environment == "production"
126
127
  mtime = asset.mtime
127
128
  latest = @watcher.latest_mtime_with_suffix(asset.from_type.to_s)
128
129
  if latest > mtime
@@ -1,3 +1,3 @@
1
1
  module Pinion
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pinion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &23433260 !ruby/object:Gem::Requirement
16
+ requirement: &25868840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *23433260
24
+ version_requirements: *25868840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &23432840 !ruby/object:Gem::Requirement
27
+ requirement: &25868420 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *23432840
35
+ version_requirements: *25868420
36
36
  description: ! 'Pinion is a Rack application that you can use to compile and serve
37
37
  assets (such as Javascript and CSS).
38
38