Skip to content

Commit

Permalink
allow setting individual values in rails config, resolves #111
Browse files Browse the repository at this point in the history
  • Loading branch information
toy committed Nov 21, 2015
1 parent 8d534db commit 4daabc3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Don't use `-strip` option for optipng when the bin version is less than 0.7 [#106](https://github.com/toy/image_optim/issues/106) [@toy](https://github.com/toy)
* Use quality `0..100` by default in lossy mode of pngquant worker [#77](https://github.com/toy/image_optim/issues/77) [@toy](https://github.com/toy)
* Add `:disable_plugins` and `:enable_plugins` options to `svgo` worker [#110](https://github.com/toy/image_optim/pull/110) [@tomhughes](https://github.com/tomhughes)
* Allow setting config in rails like `config.assets.image_optim.name = value` [#111](https://github.com/toy/image_optim/pull/111) [@toy](https://github.com/toy)

## v0.21.0 (2015-05-30)

Expand Down
2 changes: 2 additions & 0 deletions lib/image_optim/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
class ImageOptim
# Adds image_optim as preprocessor for gif, jpeg, png and svg images
class Railtie < Rails::Railtie
config.assets.image_optim = ActiveSupport::OrderedOptions.new

initializer 'image_optim.initializer' do |app|
register_preprocessor(app) if register_preprocessor?(app)
end
Expand Down
18 changes: 17 additions & 1 deletion spec/image_optim/railtie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@ def self.name
assets.paths = %w[spec/images]

assets.delete(:compress)
assets.delete(:image_optim)
end

yield config if block_given?
end.initialize!
end

around do |example|
options = Marshal.dump(ImageOptim::Railtie.config.assets.image_optim)
begin
example.run
ensure
ImageOptim::Railtie.config.assets.image_optim = Marshal.load(options)
end
end

after do
Rails.application = nil
end
Expand Down Expand Up @@ -88,6 +96,14 @@ def self.name
config.assets.image_optim = hash
end
end

it 'is possible to assign individual values' do
hash = {:config_paths => 'config/image_optim.yml'}
expect(ImageOptim).to receive(:new).with(hash).and_call_original
init_rails_app do |config|
config.assets.image_optim.config_paths = 'config/image_optim.yml'
end
end
end
end

Expand Down

0 comments on commit 4daabc3

Please sign in to comment.