hashie 3.5.1 → 3.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e68805c828e2bfe9d5921050a82bb0ac4d58428
4
- data.tar.gz: 37906b7b9d2cd7f123b9968e9e67e2076c4e7bc5
3
+ metadata.gz: ee11cc424479d1ff5f737d9279f60e182adb0553
4
+ data.tar.gz: 7bae504b1c65b8cf79909c3180cf5084771efb5e
5
5
  SHA512:
6
- metadata.gz: f1723cc215b0fbadd587e7f48827126e3d254b501498954a757ae445dc40eb8213d6499832182548387469b022f2f9b7af73085ecb1dbcdc6e3813d861b4ad60
7
- data.tar.gz: fca4da7f4d73669f12c3e2f7b696ce2ffbde9aba07b33f61c0879e5f8428d59c441b5dedbc59db003bb42a4fecafd202cdc6f2145183dcdd407dbabdd3508d01
6
+ metadata.gz: 6af54aa6435ee5df457614baf9a60a0d3660e7066229e90a74109ff38999afda2444a02e965ec9f5422e4ddd85e6a493d3cb52ff735712d8dfd8d02c84f504f8
7
+ data.tar.gz: a2ed6b577219d2a7e6ebaca2ca5589b29af9b89a1201580707ab39d4895c0cbee63f4dd4e92a5c3ccda1409f226fc0ccbce41e0b7f8e6a694f6d85df7e598d60
@@ -6,13 +6,31 @@ scheme are considered to be bugs.
6
6
 
7
7
  [semver]: http://semver.org/spec/v2.0.0.html
8
8
 
9
+ ## [3.5.2] - 2017-02-10
10
+
11
+ [3.5.2]: https://github.com/intridea/hashie/compare/v3.5.1...v3.5.2
12
+
13
+ ### Added
14
+
15
+ * [#395](https://github.com/intridea/hashie/pull/395): Add the ability to disable warnings in Mash subclasses - [@michaelherold](https://github.com/michaelherold).
16
+ * [#400](https://github.com/intridea/hashie/pull/400): Fix Hashie.logger load and set the Hashie logger to the Rails logger in a Rails environment - [@michaelherold](https://github.com/michaelherold).
17
+
18
+ ### Fixed
19
+
20
+ * [#396](https://github.com/intridea/hashie/pull/396): Fix for specs in #381: Incorrect use of shared context meant example was not being run - [@biinari](https://github.com/biinari).
21
+ * [#399](https://github.com/intridea/hashie/pull/399): Fix passing Pathname object to Hashie::Mesh.load() - [@albb0920](https://github.com/albb0920).
22
+
23
+ ### Miscellanous
24
+
25
+ * [#397](https://github.com/intridea/hashie/pull/397): Add the integration specs harness into the main test tasks - [@michaelherold](https://github.com/michaelherold).
26
+
9
27
  ## [3.5.1] - 2017-01-31
10
28
 
11
29
  * [#392](https://github.com/intridea/hashie/pull/392): Fix for #391: Require all dependencies of Hashie::Mash - [@dblock](https://github.com/dblock).
12
30
 
13
31
  [3.5.1]: https://github.com/intridea/hashie/compare/v3.5.0...v3.5.1
14
32
 
15
- ## [3.5.0] - 2017-01-31 (YANKED)
33
+ ## [3.5.0] - 2017-01-31
16
34
 
17
35
  * [#386](https://github.com/intridea/hashie/pull/386): Fix for #385: Make `deep_merge` always `deep_dup` nested hashes before merging them in so that there are no shared references between the two hashes being merged. - [@mltsy](https://github.com/mltsy).
18
36
  * [#389](https://github.com/intridea/hashie/pull/389): Support Ruby 2.4.0 - [@camelmasa](https://github.com/camelmasa).
data/README.md CHANGED
@@ -20,7 +20,7 @@ $ gem install hashie
20
20
 
21
21
  ## Upgrading
22
22
 
23
- You're reading the documentation for the stable release of Hashie, 3.5.1. Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version.
23
+ You're reading the documentation for the stable release of Hashie, 3.5.2. Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version.
24
24
 
25
25
  ## Hash Extensions
26
26
 
@@ -531,6 +531,20 @@ mash = Mash.load('data/user.csv', parser: MyCustomCsvParser)
531
531
  mash[1] #=> { name: 'John', lastname: 'Doe' }
532
532
  ```
533
533
 
534
+ Since Mash gives you the ability to set arbitrary keys that then act as methods, Hashie logs when there is a conflict between a key and a pre-existing method. You can set the logger that this logs message to via the global Hashie logger:
535
+
536
+ ```ruby
537
+ Hashie.logger = Rails.logger
538
+ ```
539
+
540
+ You can also disable the logging in subclasses of Mash:
541
+
542
+ ```ruby
543
+ class Response < Hashie::Mash
544
+ disable_warnings
545
+ end
546
+ ```
547
+
534
548
  ### Mash Extension: SafeAssignment
535
549
 
536
550
  This extension can be mixed into a Mash to guard the attempted overwriting of methods by property setters. When mixed in, the Mash will raise an `ArgumentError` if you attempt to write a property with the same name as an existing method.
data/Rakefile CHANGED
@@ -13,4 +13,20 @@ end
13
13
  require 'rubocop/rake_task'
14
14
  RuboCop::RakeTask.new(:rubocop)
15
15
 
16
- task default: [:rubocop, :spec]
16
+ require_relative 'spec/support/integration_specs'
17
+ task :integration_specs do
18
+ next if ENV['CI']
19
+ status_codes = []
20
+ handler = lambda do |status_code|
21
+ status_codes << status_code unless status_code.zero?
22
+ end
23
+
24
+ run_all_integration_specs(handler: handler, logger: ->(msg) { puts msg })
25
+
26
+ if status_codes.any?
27
+ $stderr.puts "#{status_codes.size} integration test(s) failed"
28
+ exit status_codes.last
29
+ end
30
+ end
31
+
32
+ task default: [:rubocop, :spec, :integration_specs]
@@ -1,6 +1,19 @@
1
1
  Upgrading Hashie
2
2
  ================
3
3
 
4
+ ### Upgrading to 3.5.2
5
+
6
+ #### Disable logging in Mash subclasses
7
+
8
+ If you subclass `Hashie::Mash`, you can now disable the logging we do about
9
+ overriding existing methods with keys. This looks like:
10
+
11
+ ```ruby
12
+ class MyMash < Hashie::Mash
13
+ disable_warnings
14
+ end
15
+ ```
16
+
4
17
  ### Upgrading to 3.4.7
5
18
 
6
19
  #### Procs as default values for Dash
@@ -11,7 +24,7 @@ class MyHash < Hashie::Dash
11
24
  end
12
25
  ```
13
26
 
14
- In versions < 3.4.7 `Time.now` will be evaluated when `time` property is accessed directly first time.
27
+ In versions < 3.4.7 `Time.now` will be evaluated when `time` property is accessed directly first time.
15
28
  In version >= 3.4.7 `Time.now` is evaluated in time of object initialization.
16
29
  ### Upgrading to 3.4.4
17
30
 
@@ -1,8 +1,7 @@
1
- require 'logger'
1
+ require 'hashie/logger'
2
2
  require 'hashie/version'
3
3
 
4
4
  module Hashie
5
- autoload :Logger, 'hashie/logger'
6
5
  autoload :Clash, 'hashie/clash'
7
6
  autoload :Dash, 'hashie/dash'
8
7
  autoload :Hash, 'hashie/hash'
@@ -1,9 +1,16 @@
1
+ require 'logger'
2
+
1
3
  module Hashie
2
4
  # The logger that Hashie uses for reporting errors.
3
5
  #
4
6
  # @return [Logger]
5
7
  def self.logger
6
- @logger ||= Logger.new(STDOUT)
8
+ @logger ||=
9
+ if defined?(::Rails)
10
+ Rails.logger
11
+ else
12
+ Logger.new(STDOUT)
13
+ end
7
14
  end
8
15
 
9
16
  # Sets the logger that Hashie uses for reporting errors.
@@ -63,6 +63,29 @@ module Hashie
63
63
 
64
64
  ALLOWED_SUFFIXES = %w(? ! = _)
65
65
 
66
+ class CannotDisableMashWarnings < StandardError
67
+ def initialize(message = 'You cannot disable warnings on the base Mash class. Please subclass the Mash and disable it in the subclass.')
68
+ super(message)
69
+ end
70
+ end
71
+
72
+ # Disable the logging of warnings based on keys conflicting keys/methods
73
+ #
74
+ # @api semipublic
75
+ # @return [void]
76
+ def self.disable_warnings
77
+ fail CannotDisableMashWarnings if self == Hashie::Mash
78
+ @disable_warnings = true
79
+ end
80
+
81
+ # Checks whether this class disables warnings for conflicting keys/methods
82
+ #
83
+ # @api semipublic
84
+ # @return [Boolean]
85
+ def self.disable_warnings?
86
+ !!@disable_warnings
87
+ end
88
+
66
89
  def self.load(path, options = {})
67
90
  @_mashes ||= new
68
91
 
@@ -111,9 +134,10 @@ module Hashie
111
134
  # a string before it is set, and Hashes will be converted
112
135
  # into Mashes for nesting purposes.
113
136
  def custom_writer(key, value, convert = true) #:nodoc:
114
- key_as_symbol = key.to_sym
137
+ key_as_symbol = (key = convert_key(key)).to_sym
138
+
115
139
  log_built_in_message(key_as_symbol) if methods.include?(key_as_symbol)
116
- regular_writer(convert_key(key), convert ? convert_value(value) : value)
140
+ regular_writer(key, convert ? convert_value(value) : value)
117
141
  end
118
142
 
119
143
  alias_method :[], :custom_reader
@@ -303,6 +327,8 @@ module Hashie
303
327
  private
304
328
 
305
329
  def log_built_in_message(method_key)
330
+ return if self.class.disable_warnings?
331
+
306
332
  method_information = Hashie::Utils.method_information(method(method_key))
307
333
 
308
334
  Hashie.logger.warn(
@@ -1,3 +1,3 @@
1
1
  module Hashie
2
- VERSION = '3.5.1'
2
+ VERSION = '3.5.2'
3
3
  end
@@ -1,9 +1,10 @@
1
1
  require 'spec_helper'
2
- require 'delegate'
3
2
 
4
3
  describe Hashie::Mash do
5
4
  subject { Hashie::Mash.new }
6
5
 
6
+ include_context 'with a logger'
7
+
7
8
  it 'inherits from Hash' do
8
9
  expect(subject.is_a?(Hash)).to be_truthy
9
10
  end
@@ -134,12 +135,26 @@ describe Hashie::Mash do
134
135
  expect(subject.type).to eq 'Steve'
135
136
  end
136
137
 
137
- shared_context 'with a logger' do
138
+ include_context 'with a logger' do
138
139
  it 'logs a warning when overriding built-in methods' do
139
140
  Hashie::Mash.new('trust' => { 'two' => 2 })
140
141
 
141
142
  expect(logger_output).to match('Hashie::Mash#trust')
142
143
  end
144
+
145
+ it 'does not write to the logger when warnings are disabled' do
146
+ mash_class = Class.new(Hashie::Mash) do
147
+ disable_warnings
148
+ end
149
+
150
+ mash_class.new('trust' => { 'two' => 2 })
151
+
152
+ expect(logger_output).to be_blank
153
+ end
154
+
155
+ it 'cannot disable logging on the base Mash' do
156
+ expect { Hashie::Mash.disable_warnings }.to raise_error(Hashie::Mash::CannotDisableMashWarnings)
157
+ end
143
158
  end
144
159
 
145
160
  context 'updating' do
@@ -617,6 +632,20 @@ describe Hashie::Mash do
617
632
  end
618
633
  end
619
634
 
635
+ context 'if the file is passed as Pathname' do
636
+ require 'pathname'
637
+ let(:path) { Pathname.new('database.yml') }
638
+
639
+ before do
640
+ expect(File).to receive(:file?).with(path).and_return(true)
641
+ expect(parser).to receive(:perform).with(path).and_return(config)
642
+ end
643
+
644
+ it 'return a Mash from a file' do
645
+ expect(subject.production.foo).to eq config['production']['foo']
646
+ end
647
+ end
648
+
620
649
  describe 'results are cached' do
621
650
  let(:parser) { double(:parser) }
622
651
 
@@ -2,12 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe Hashie do
4
4
  describe '.logger' do
5
- shared_context 'with a logger' do
6
- it 'is available via an accessor' do
7
- Hashie.logger.info('Fee fi fo fum')
5
+ include_context 'with a logger'
8
6
 
9
- expect(logger_output).to match('Fee fi fo fum')
10
- end
7
+ it 'is available via an accessor' do
8
+ Hashie.logger.info('Fee fi fo fum')
9
+
10
+ expect(logger_output).to match('Fee fi fo fum')
11
11
  end
12
12
  end
13
13
  end
@@ -6,7 +6,7 @@ require 'sinatra'
6
6
  require 'omniauth'
7
7
 
8
8
  class MyApplication < Sinatra::Base
9
- use Rack::Session::Cookie
9
+ use Rack::Session::Cookie, secret: 'hashie integration tests'
10
10
  use OmniAuth::Strategies::Developer
11
11
 
12
12
  get '/' do
@@ -0,0 +1,66 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+
3
+ require 'rspec/core'
4
+ require 'rails'
5
+ require 'rails/all'
6
+ require 'action_view/testing/resolvers'
7
+
8
+ module RailsApp
9
+ class Application < ::Rails::Application
10
+ config.action_dispatch.show_exceptions = false
11
+ config.active_support.deprecation = :stderr
12
+ config.eager_load = false
13
+ config.root = __dir__
14
+ config.secret_key_base = 'hashieintegrationtest'
15
+
16
+ routes.append do
17
+ get '/' => 'application#index'
18
+ end
19
+
20
+ config.assets.paths << File.join(__dir__, 'assets/javascripts')
21
+ config.assets.debug = true
22
+ end
23
+ end
24
+
25
+ LAYOUT = <<-HTML
26
+ <!DOCTYPE html>
27
+ <html>
28
+ <head>
29
+ <title>TestApp</title>
30
+ <%= stylesheet_link_tag "application", :media => "all" %>
31
+ <%= javascript_include_tag "application" %>
32
+ <%= csrf_meta_tags %>
33
+ </head>
34
+ <body>
35
+ <%= yield %>
36
+ </body>
37
+ </html>
38
+ HTML
39
+
40
+ INDEX = <<-HTML
41
+ <h1>Hello, world!</h1>
42
+ HTML
43
+
44
+ class ApplicationController < ActionController::Base
45
+ include Rails.application.routes.url_helpers
46
+
47
+ layout 'application'
48
+
49
+ self.view_paths = [ActionView::FixtureResolver.new(
50
+ 'layouts/application.html.erb' => LAYOUT,
51
+ 'application/index.html.erb' => INDEX
52
+ )]
53
+
54
+ def index
55
+ end
56
+ end
57
+
58
+ RailsApp::Application.initialize!
59
+
60
+ require 'hashie'
61
+
62
+ RSpec.describe 'the Hashie logger' do
63
+ it 'is set to the Rails logger' do
64
+ expect(Hashie.logger).to eq(Rails.logger)
65
+ end
66
+ end
@@ -9,6 +9,7 @@ require 'rspec'
9
9
  require 'hashie'
10
10
  require 'rspec/pending_for'
11
11
  require './spec/support/ruby_version_check'
12
+ require './spec/support/logger'
12
13
 
13
14
  require 'active_support'
14
15
  require 'active_support/core_ext'
@@ -0,0 +1,36 @@
1
+ # Generates the bundle command for running an integration test
2
+ #
3
+ # @param [String] integration the integration folder to run
4
+ # @param [String] command the command to run
5
+ # @return [String]
6
+ def integration_command(integration, command)
7
+ "#{integration_gemfile(integration)} #{command}"
8
+ end
9
+
10
+ # Generates the Gemfile for an integration
11
+ #
12
+ # @param [String] integration the integration test name
13
+ # @return [String]
14
+ def integration_gemfile(integration)
15
+ "BUNDLE_GEMFILE=#{integration_path(integration)}/Gemfile"
16
+ end
17
+
18
+ # Generates the path to the integration
19
+ #
20
+ # @param [String] integration the integration test name
21
+ # @return [String]
22
+ def integration_path(integration)
23
+ "spec/integration/#{integration}"
24
+ end
25
+
26
+ # Runs all integration specs in their own environment
27
+ def run_all_integration_specs(handler: ->(_code) {}, logger: ->(_msg) {})
28
+ Dir['spec/integration/*']
29
+ .map { |directory| directory.split('/').last }
30
+ .each do |integration|
31
+ logger.call(%(Running "#{integration}" integration spec))
32
+ system(integration_command(integration, 'bundle --quiet'))
33
+ system(integration_command(integration, "bundle exec rspec #{integration_path(integration)}"))
34
+ handler.call($CHILD_STATUS.exitstatus)
35
+ end
36
+ end
@@ -1,7 +1,9 @@
1
1
  # A shared context that allows you to check the output of Hashie's logger.
2
2
  #
3
3
  # @example
4
- # shared_context 'with a logger' do
4
+ # include_context 'with a logger'
5
+ #
6
+ # it 'logs info message' do
5
7
  # Hashie.logger.info 'What is happening in here?!'
6
8
  #
7
9
  # expect(logger_output).to match('What is happening in here?!')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashie
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.1
4
+ version: 3.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-01-31 00:00:00.000000000 Z
12
+ date: 2017-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -132,7 +132,9 @@ files:
132
132
  - spec/hashie/version_spec.rb
133
133
  - spec/hashie_spec.rb
134
134
  - spec/integration/omniauth/integration_spec.rb
135
+ - spec/integration/rails/integration_spec.rb
135
136
  - spec/spec_helper.rb
137
+ - spec/support/integration_specs.rb
136
138
  - spec/support/logger.rb
137
139
  - spec/support/module_context.rb
138
140
  - spec/support/ruby_version_check.rb
@@ -191,7 +193,9 @@ test_files:
191
193
  - spec/hashie/version_spec.rb
192
194
  - spec/hashie_spec.rb
193
195
  - spec/integration/omniauth/integration_spec.rb
196
+ - spec/integration/rails/integration_spec.rb
194
197
  - spec/spec_helper.rb
198
+ - spec/support/integration_specs.rb
195
199
  - spec/support/logger.rb
196
200
  - spec/support/module_context.rb
197
201
  - spec/support/ruby_version_check.rb