From 3f50a115dfd4a41400ac9cb540526445b19fa558 Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Fri, 2 Dec 2016 14:11:09 +0800 Subject: [PATCH] =?UTF-8?q?*=20[BREAKING]=20require=20=E2=80=9Cfog-core?= =?UTF-8?q?=E2=80=9D=20instead=20of=20=E2=80=9Cfog=E2=80=9D=20as=20runtime?= =?UTF-8?q?=20requirement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 18 ++++++----------- UPGRADING.md | 25 ++++++++++++++++++++++++ asset_sync.gemspec | 4 +++- lib/asset_sync.rb | 2 -- lib/asset_sync/config.rb | 18 +++++++++-------- lib/asset_sync/storage.rb | 4 +++- lib/asset_sync/version.rb | 2 +- spec/integration/aws_integration_spec.rb | 9 +++++---- spec/unit/storage_spec.rb | 2 +- 9 files changed, 54 insertions(+), 30 deletions(-) create mode 100644 UPGRADING.md diff --git a/README.md b/README.md index 2e7b0b96..e3f40e33 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/UPGRADING.md b/UPGRADING.md new file mode 100644 index 00000000..dda3b2cc --- /dev/null +++ b/UPGRADING.md @@ -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. + diff --git a/asset_sync.gemspec b/asset_sync.gemspec index dc9907e8..56e9580a 100644 --- a/asset_sync.gemspec +++ b/asset_sync.gemspec @@ -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') @@ -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" diff --git a/lib/asset_sync.rb b/lib/asset_sync.rb index f69439a8..3cf5e56e 100644 --- a/lib/asset_sync.rb +++ b/lib/asset_sync.rb @@ -1,5 +1,3 @@ -require 'fog' unless defined?(::Fog) -require 'erb' require "asset_sync/asset_sync" require 'asset_sync/config' require 'asset_sync/storage' diff --git a/lib/asset_sync/config.rb b/lib/asset_sync/config.rb index 7ae395c7..ad617753 100644 --- a/lib/asset_sync/config.rb +++ b/lib/asset_sync/config.rb @@ -1,4 +1,6 @@ require "active_model" +require "erb" +require "yaml" module AssetSync class Config @@ -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 @@ -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! @@ -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 diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index a4edcc16..3e3c712d 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -1,3 +1,5 @@ +require "fog/core" + module AssetSync class Storage REGEXP_FINGERPRINTED_FILES = /^(.*)\/([^-]+)-[^\.]+\.([^\.]+)$/ @@ -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)$/ diff --git a/lib/asset_sync/version.rb b/lib/asset_sync/version.rb index ff44e76c..b945fdd1 100644 --- a/lib/asset_sync/version.rb +++ b/lib/asset_sync/version.rb @@ -1,3 +1,3 @@ module AssetSync - VERSION = "1.3.0" + VERSION = "2.0.0.alpha.0" end diff --git a/spec/integration/aws_integration_spec.rb b/spec/integration/aws_integration_spec.rb index 5ccba42a..958d317f 100644 --- a/spec/integration/aws_integration_spec.rb +++ b/spec/integration/aws_integration_spec.rb @@ -1,4 +1,5 @@ require File.dirname(__FILE__) + '/../spec_helper' +require "fog/aws" def bucket(name) options = { @@ -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 } diff --git a/spec/unit/storage_spec.rb b/spec/unit/storage_spec.rb index 39d889e6..f1d7860b 100644 --- a/spec/unit/storage_spec.rb +++ b/spec/unit/storage_spec.rb @@ -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'