diff --git a/lib/guard/dsl.rb b/lib/guard/dsl.rb index 6494bb190..c1ad6429c 100644 --- a/lib/guard/dsl.rb +++ b/lib/guard/dsl.rb @@ -331,7 +331,7 @@ def logger(options) end end - ::Guard::UI.options = ::Guard::UI.options.merge options + ::Guard::UI.options = ::Guard::UI.options.marshal_dump.merge options end # Sets the default scope on startup diff --git a/lib/guard/options.rb b/lib/guard/options.rb index 3f73a3bb1..15859421e 100644 --- a/lib/guard/options.rb +++ b/lib/guard/options.rb @@ -6,8 +6,6 @@ module Guard # class Options < OpenStruct - attr_accessor :options - # Initializes an Guard::Options object. `default_opts` is merged into # `opts`. # @@ -15,9 +13,7 @@ class Options < OpenStruct # @param [Hash] default_opts the default options # def initialize(opts = {}, default_opts = {}) - opts = default_opts.dup.merge(opts.dup) - - super(opts) + super(default_opts.dup.merge(opts.dup)) end end diff --git a/lib/guard/ui.rb b/lib/guard/ui.rb index ffe98c700..b50e1479c 100644 --- a/lib/guard/ui.rb +++ b/lib/guard/ui.rb @@ -20,8 +20,8 @@ class << self # def logger @logger ||= begin - options = self.options.dup - Lumberjack::Logger.new(options.delete(:device) || $stderr, options) + opts = options.marshal_dump + Lumberjack::Logger.new(opts.delete(:device) { $stderr }, opts) end end @@ -30,7 +30,7 @@ def logger # @return [Hash] the logger options # def options - @options ||= { :level => :info, :template => ':time - :severity - :message', :time_format => '%H:%M:%S' } + @options ||= ::Guard::Options.new(level: :info, template: ':time - :severity - :message', time_format: '%H:%M:%S') end # Set the logger options @@ -41,7 +41,7 @@ def options # @option options [String] time_format the time format # def options=(options) - @options = options + @options = ::Guard::Options.new(options) end # Show an info message. @@ -53,7 +53,7 @@ def options=(options) def info(message, options = {}) filter(options[:plugin]) do |plugin| reset_line if options[:reset] - self.logger.info(message, plugin) + logger.info(message, plugin) end end @@ -66,7 +66,7 @@ def info(message, options = {}) def warning(message, options = {}) filter(options[:plugin]) do |plugin| reset_line if options[:reset] - self.logger.warn(color(message, :yellow), plugin) + logger.warn(color(message, :yellow), plugin) end end @@ -79,7 +79,7 @@ def warning(message, options = {}) def error(message, options = {}) filter(options[:plugin]) do |plugin| reset_line if options[:reset] - self.logger.error(color(message, :red), plugin) + logger.error(color(message, :red), plugin) end end @@ -95,7 +95,7 @@ def deprecation(message, options = {}) filter(options[:plugin]) do |plugin| reset_line if options[:reset] - self.logger.warn(color(message, :yellow), plugin) + logger.warn(color(message, :yellow), plugin) end end @@ -108,7 +108,7 @@ def deprecation(message, options = {}) def debug(message, options = {}) filter(options[:plugin]) do |plugin| reset_line if options[:reset] - self.logger.debug(color(message, :yellow), plugin) + logger.debug(color(message, :yellow), plugin) end end @@ -164,8 +164,8 @@ def action_with_scopes(action, scopes) # @yieldparam [String] param the calling plugin name # def filter(plugin) - only = self.options[:only] - except = self.options[:except] + only = options.only + except = options.except plugin = plugin || calling_plugin_name if (!only && !except) || (only && only.match(plugin)) || (except && !except.match(plugin)) diff --git a/spec/guard/dsl_spec.rb b/spec/guard/dsl_spec.rb index af7746a8e..585159c49 100644 --- a/spec/guard/dsl_spec.rb +++ b/spec/guard/dsl_spec.rb @@ -232,57 +232,57 @@ def self.call(plugin, event, args) end describe '#logger' do - after { Guard::UI.options = { :level => :info, :template => ':time - :severity - :message', :time_format => '%H:%M:%S' } } + after { Guard::UI.options = { level: :info, template: ':time - :severity - :message', time_format: '%H:%M:%S' } } context 'with valid options' do it 'sets the logger log level' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :level => :error') - Guard::UI.options[:level].should eq :error + Guard::UI.options.level.should eq :error end it 'sets the logger log level and convert to a symbol' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :level => \'error\'') - Guard::UI.options[:level].should eq :error + Guard::UI.options.level.should eq :error end it 'sets the logger template' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :template => \':message - :severity\'') - Guard::UI.options[:template].should eq ':message - :severity' + Guard::UI.options.template.should eq ':message - :severity' end it 'sets the logger time format' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :time_format => \'%Y\'') - Guard::UI.options[:time_format].should eq '%Y' + Guard::UI.options.time_format.should eq '%Y' end it 'sets the logger only filter from a symbol' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :only => :cucumber') - Guard::UI.options[:only].should eq(/cucumber/i) + Guard::UI.options.only.should eq(/cucumber/i) end it 'sets the logger only filter from a string' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :only => \'jasmine\'') - Guard::UI.options[:only].should eq(/jasmine/i) + Guard::UI.options.only.should eq(/jasmine/i) end it 'sets the logger only filter from an array of symbols and string' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :only => [:rspec, \'cucumber\']') - Guard::UI.options[:only].should eq(/rspec|cucumber/i) + Guard::UI.options.only.should eq(/rspec|cucumber/i) end it 'sets the logger except filter from a symbol' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :except => :jasmine') - Guard::UI.options[:except].should eq(/jasmine/i) + Guard::UI.options.except.should eq(/jasmine/i) end it 'sets the logger except filter from a string' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :except => \'jasmine\'') - Guard::UI.options[:except].should eq(/jasmine/i) + Guard::UI.options.except.should eq(/jasmine/i) end it 'sets the logger except filter from an array of symbols and string' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :except => [:rspec, \'cucumber\', :jasmine]') - Guard::UI.options[:except].should eq(/rspec|cucumber|jasmine/i) + Guard::UI.options.except.should eq(/rspec|cucumber|jasmine/i) end end @@ -295,7 +295,7 @@ def self.call(plugin, event, args) it 'does not set the invalid value' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :level => :baz') - Guard::UI.options[:level].should eq :info + Guard::UI.options.level.should eq :info end end @@ -307,8 +307,8 @@ def self.call(plugin, event, args) it 'removes the options' do described_class.evaluate_guardfile(:guardfile_contents => 'logger :only => :jasmine, :except => :rspec') - Guard::UI.options[:only].should be_nil - Guard::UI.options[:except].should be_nil + Guard::UI.options.only.should be_nil + Guard::UI.options.except.should be_nil end end diff --git a/spec/guard/ui_spec.rb b/spec/guard/ui_spec.rb index b9124fd1f..d0461ee9e 100644 --- a/spec/guard/ui_spec.rb +++ b/spec/guard/ui_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Guard::UI do - after { Guard::UI.options = ::Guard::Options.new(level: :info, device: $stderr, template: ':time - :severity - :message', time_format: '%H:%M:%S') } + after { Guard::UI.options = { level: :info, device: $stderr, template: ':time - :severity - :message', time_format: '%H:%M:%S' } } before do # The spec helper stubs all UI classes, so other specs doesn't have @@ -40,7 +40,7 @@ describe '.options=' do it 'sets the logger options' do - Guard::UI.options = ::Guard::Options.new(hi: :ho) + Guard::UI.options = { hi: :ho } Guard::UI.options.hi.should eq :ho end end