Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

yaml configuration to hash with indifferent access #23

Closed
wants to merge 4 commits into from

3 participants

@formigarafa

The method #with_indifferent_access is not available at the point when the Yell is loaded with rails.
The classes autoloads are set but the hash core extensions that adds this method into it don't.
Workaround: pass the hash through the HashWithIndifferentAccess initializer.
This resolve yell-rails gem issue rudionrails/yell-rails#1

@formigarafa formigarafa fixed hash loading with indifferent access.
the method #with_indifferent_access is not available at the point when
the Yell is loaded. The classes autoloads are ready but the hash core
extensions that adds this method to it it is nos loaded, yet.
Workaround: pass the hash through the HashWithIndifferentAccess
initializer.
53ef818
@coveralls

Coverage Status

Coverage decreased (-0%) when pulling 53ef818 on formigarafa:master into 6230ed5 on rudionrails:master.

@formigarafa formigarafa fixed inconsistent adapter search
conventionalized registered adapter names to be symbols and its search
made using symbols as keys.
This help to fix rudionrails/yell-rails#1
when loading an external loaded adapter as yell-adapter-gelf with
yell-rails.
b09e470
@coveralls

Coverage Status

Coverage decreased (-0%) when pulling b09e470 on formigarafa:master into 6230ed5 on rudionrails:master.

formigarafa added some commits
@formigarafa formigarafa added specs for recent Yell::Adapters changes
added specs that verifies registering and fetching adapters by its keys
ins string or symbol format.
45ed536
@formigarafa formigarafa added tests for loading adapters from yaml as strings or symbols 3c0f787
@rudionrails
Owner

Your commits address different things. Please provide a single pull request for HashWithIndifferentAccess and another one for the Adapters change and I will merge them into the main branch.

@rudionrails
Owner

Closing due to inactivity

@rudionrails rudionrails closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 9, 2013
  1. @formigarafa

    fixed hash loading with indifferent access.

    formigarafa authored
    the method #with_indifferent_access is not available at the point when
    the Yell is loaded. The classes autoloads are ready but the hash core
    extensions that adds this method to it it is nos loaded, yet.
    Workaround: pass the hash through the HashWithIndifferentAccess
    initializer.
  2. @formigarafa

    fixed inconsistent adapter search

    formigarafa authored
    conventionalized registered adapter names to be symbols and its search
    made using symbols as keys.
    This help to fix rudionrails/yell-rails#1
    when loading an external loaded adapter as yell-adapter-gelf with
    yell-rails.
  3. @formigarafa

    added specs for recent Yell::Adapters changes

    formigarafa authored
    added specs that verifies registering and fetching adapters by its keys
    ins string or symbol format.
  4. @formigarafa
This page is out of date. Refresh to see the latest.
View
4 lib/yell/adapters.rb
@@ -18,7 +18,7 @@ module Adapters
# @example
# Yell::Adapters.register( :myadapter, MyAdapter )
def self.register( name, klass )
- @adapters[name] = klass
+ @adapters[name.to_sym] = klass
end
# Returns an instance of the given processor type.
@@ -31,7 +31,7 @@ def self.new( name, options = {}, &block )
adapter = case name
when STDOUT then @adapters[:stdout]
when STDERR then @adapters[:stderr]
- else @adapters[name]
+ else @adapters[name.to_sym]
end
raise AdapterNotFound.new(name) if adapter.nil?
View
5 lib/yell/configuration.rb
@@ -12,9 +12,8 @@ class Configuration
def self.load!( file )
yaml = YAML.load( ERB.new(File.read(file)).result )
- # in case we have ActiveSupport
- if yaml.respond_to?(:with_indifference_access)
- yaml = yaml.with_indifferent_access
+ if defined? ActiveSupport::HashWithIndifferentAccess
+ yaml = ActiveSupport::HashWithIndifferentAccess.new(yaml)
end
yaml[Yell.env] || {}
View
34 spec/yell/adapters_spec.rb
@@ -42,4 +42,38 @@
end
end
+ context "keys for registering and search registered adapters" do
+ let(:adapter_class) do
+ klass = mock
+ mock(klass).new(anything) { :adapter_instance }
+ klass
+ end
+
+ before { Yell::Adapters.register(adapter_name, adapter_class) }
+
+ context "registered with string" do
+ let(:adapter_name) { "mocked_adapter" }
+
+ it "can be found using string as key" do
+ Yell::Adapters.new(adapter_name.to_s).should == :adapter_instance
+ end
+
+ it "can be found using symbol as key" do
+ Yell::Adapters.new(adapter_name.to_sym).should == :adapter_instance
+ end
+ end
+
+ context "registered with symbol" do
+ let(:adapter_name) { :mocked_adapter }
+
+ it "can be found using string as key" do
+ Yell::Adapters.new(adapter_name.to_s).should == :adapter_instance
+ end
+
+ it "can be found using symbol as key" do
+ Yell::Adapters.new(adapter_name.to_sym).should == :adapter_instance
+ end
+ end
+ end
+
end
View
15 spec/yell_spec.rb
@@ -33,6 +33,21 @@
it { should be_kind_of Yell::Logger }
end
+ context ".load! understand adapters set as symbols or strings" do
+ subject { Yell.load!( 'yell.yml' ) }
+
+ before do
+ mock(Yell::Configuration).load!('yell.yml') { {:adapters => [:stdout, {'stderr' => {:level => "gte.error"}} ] } }
+ end
+
+ it "something" do
+ should be_kind_of Yell::Logger
+
+ subject.adapters.map(&:class).should include Yell::Adapters::Stderr
+ subject.adapters.map(&:class).should include Yell::Adapters::Stdout
+ end
+ end
+
context ".[]" do
let(:name) { 'test' }
Something went wrong with that request. Please try again.