Skip to content

Commit

Permalink
* [BREAKING] require “fog-core” instead of “fog” as runtime requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
PikachuEXE committed Dec 21, 2016
1 parent 7dd619c commit 3f50a11
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 30 deletions.
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,20 @@ This was initially built and is intended to work on [Heroku](http://heroku.com)

## Upgrading?

If you are upgrading from a version of asset_sync **< 0.2.0** (i.e. 0.1.x). All of the references to config variables have changed to reference those used in **Fog**. Ensure to backup your `asset_sync.rb` or `asset_sync.yml` files and re-run the generator. You may also then need to update your ENV configuration variables (or you can change the ones that are referenced).
Upgraded from 1.x? Read `UPGRADING.md`

## Installation

Add the gem to your Gemfile
Since 2.x, Asset Sync depends on gem `fog-core` instead of `fog`.
This is due to `fog` is including many unused storage provider gems as its dependencies.

``` ruby
gem 'asset_sync'
```

### Optimized Fog loading

Since AssetSync doesn't know which parts of Fog you intend to use, it will just load the entire library.
If you prefer to load fewer classes into your application, which will reduce load time and memory use,
you need to load those parts of Fog yourself *before* loading AssetSync:
Asset Sync has no idea about what provider will be used,
so you are responsible for bundling the right gem for the provider to be used.

In your Gemfile:
```ruby
gem "fog", "~>1.20", require: "fog/aws/storage"
gem "asset_sync"
gem "fog-aws"
```

### Extended Installation (Faster sync with turbosprockets)
Expand Down
25 changes: 25 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Guide to upgrading from AssetSync 1.x to 2.x

Make sure that you're running the latest AssetSync 1.x release.

This upgrading guide touches on:
- Changed dependencies


## Changed dependencies
Asset Sync now depends on gem `fog-core` instead of `fog`.
This is due to `fog` is including many unused storage provider gems as its dependencies.

Asset Sync has no idea about what provider will be used,
so you are responsible for bundling the right gem for the provider to be used.

For example, when using AWS as fog provider:
```ruby
# Gemfile
gem "asset_sync"
gem "fog-aws"
```

If you don't install the required gem,
Fog will complain (by exception) about it when provider is set by Asset Sync.

4 changes: 3 additions & 1 deletion asset_sync.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |s|

s.rubyforge_project = "asset_sync"

s.add_dependency('fog', ">= 1.8.0")
s.add_dependency("fog-core")
s.add_dependency('unf')
s.add_dependency('activemodel')
s.add_dependency('mime-types')
Expand All @@ -27,6 +27,8 @@ Gem::Specification.new do |s|
s.add_development_dependency "bundler"
s.add_development_dependency "jeweler"

s.add_development_dependency "fog-aws"

s.add_development_dependency "uglifier"
s.add_development_dependency "appraisal"

Expand Down
2 changes: 0 additions & 2 deletions lib/asset_sync.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'fog' unless defined?(::Fog)
require 'erb'
require "asset_sync/asset_sync"
require 'asset_sync/config'
require 'asset_sync/storage'
Expand Down
18 changes: 10 additions & 8 deletions lib/asset_sync/config.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require "active_model"
require "erb"
require "yaml"

module AssetSync
class Config
Expand Down Expand Up @@ -63,12 +65,12 @@ def initialize
self.run_on_precompile = true
self.cdn_distribution_id = nil
self.invalidate = []
load_yml! if defined?(Rails) && yml_exists?
load_yml! if defined?(::Rails) && yml_exists?
end

def manifest_path
directory =
Rails.application.config.assets.manifest || default_manifest_directory
::Rails.application.config.assets.manifest || default_manifest_directory
File.join(directory, "manifest.yml")
end

Expand Down Expand Up @@ -113,24 +115,24 @@ def google?
end

def yml_exists?
defined?(Rails.root) ? File.exist?(self.yml_path) : false
defined?(::Rails.root) ? File.exist?(self.yml_path) : false
end

def yml
@yml ||= YAML.load(ERB.new(IO.read(yml_path)).result)[Rails.env] || {}
@yml ||= ::YAML.load(::ERB.new(IO.read(yml_path)).result)[::Rails.env] || {}
end

def yml_path
Rails.root.join("config", "asset_sync.yml").to_s
::Rails.root.join("config", "asset_sync.yml").to_s
end

def assets_prefix
# Fix for Issue #38 when Rails.config.assets.prefix starts with a slash
self.prefix || Rails.application.config.assets.prefix.sub(/^\//, '')
self.prefix || ::Rails.application.config.assets.prefix.sub(/^\//, '')
end

def public_path
@public_path || Rails.public_path
@public_path || ::Rails.public_path
end

def load_yml!
Expand Down Expand Up @@ -214,7 +216,7 @@ def fog_options
private

def default_manifest_directory
File.join(Rails.public_path, assets_prefix)
File.join(::Rails.public_path, assets_prefix)
end
end
end
4 changes: 3 additions & 1 deletion lib/asset_sync/storage.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "fog/core"

module AssetSync
class Storage
REGEXP_FINGERPRINTED_FILES = /^(.*)\/([^-]+)-[^\.]+\.([^\.]+)$/
Expand Down Expand Up @@ -61,7 +63,7 @@ def get_local_files
elsif File.exist?(self.config.manifest_path)
log "Using: Manifest #{self.config.manifest_path}"
yml = YAML.load(IO.read(self.config.manifest_path))

return yml.map do |original, compiled|
# Upload font originals and compiled
if original =~ /^.+(eot|svg|ttf|woff)$/
Expand Down
2 changes: 1 addition & 1 deletion lib/asset_sync/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module AssetSync
VERSION = "1.3.0"
VERSION = "2.0.0.alpha.0"
end
9 changes: 5 additions & 4 deletions spec/integration/aws_integration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require File.dirname(__FILE__) + '/../spec_helper'
require "fog/aws"

def bucket(name)
options = {
Expand All @@ -23,12 +24,12 @@ def execute(command)
@prefix = SecureRandom.hex(6)
end

let(:app_js_regex){
/#{@prefix}\/application-[a-zA-Z0-9]*.js$/
let(:app_js_regex){
/#{@prefix}\/application-[a-zA-Z0-9]*.js$/
}

let(:app_js_gz_regex){
/#{@prefix}\/application-[a-zA-Z0-9]*.js.gz$/
let(:app_js_gz_regex){
/#{@prefix}\/application-[a-zA-Z0-9]*.js.gz$/
}

let(:files){ bucket(@prefix).files }
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def check_file(file)
storage.upload_files
end

it "shoud invalidate files" do
it "should invalidate files" do
@config.cdn_distribution_id = "1234"
@config.invalidate = ['local_image1.jpg']
@config.fog_provider = 'AWS'
Expand Down

0 comments on commit 3f50a11

Please sign in to comment.