commit rubygem-hashie for openSUSE:Factory
Hello community, here is the log from the commit of package rubygem-hashie for openSUSE:Factory checked in at 2015-10-30 21:53:03 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-hashie (Old) and /work/SRC/openSUSE:Factory/.rubygem-hashie.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "rubygem-hashie" Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-hashie/rubygem-hashie.changes 2015-06-12 20:30:46.000000000 +0200 +++ /work/SRC/openSUSE:Factory/.rubygem-hashie.new/rubygem-hashie.changes 2015-10-30 21:53:04.000000000 +0100 @@ -1,0 +2,15 @@ +Mon Oct 26 05:29:02 UTC 2015 - coolo@suse.com + +- updated to version 3.4.3 + see installed CHANGELOG.md + + ## 3.4.2 (10/25/2015) + + * [#314](https://github.com/intridea/hashie/pull/314): Added a `StrictKeyAccess` extension that will raise an error whenever a key is accessed that does not exist in the hash - [@pboling](https://github.com/pboling). + * [#304](https://github.com/intridea/hashie/pull/304): Ensured compatibility of `Hash` extensions with singleton objects - [@regexident](https://github.com/regexident). + * [#306](https://github.com/intridea/hashie/pull/306): Added `Hashie::Extensions::Dash::Coercion` - [@marshall-lee](https://github.com/marshall-lee). + * [#310](https://github.com/intridea/hashie/pull/310): Fixed `Hashie::Extensions::SafeAssignment` bug with private methods - [@marshall-lee](https://github.com/marshall-lee). + * [#313](https://github.com/intridea/hashie/pull/313): Restrict pending spec to only Ruby versions 2.2.0-2.2.2 - [@pboling](https://github.com/pboling). + * [#315](https://github.com/intridea/hashie/pull/315): Default `bin/` scripts: `console` and `setup` - [@pboling](https://github.com/pboling). + +------------------------------------------------------------------- Old: ---- hashie-3.4.2.gem New: ---- hashie-3.4.3.gem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-hashie.spec ++++++ --- /var/tmp/diff_new_pack.J0skFA/_old 2015-10-30 21:53:05.000000000 +0100 +++ /var/tmp/diff_new_pack.J0skFA/_new 2015-10-30 21:53:05.000000000 +0100 @@ -24,7 +24,7 @@ # Name: rubygem-hashie -Version: 3.4.2 +Version: 3.4.3 Release: 0 %define mod_name hashie %define mod_full_name %{mod_name}-%{version} ++++++ hashie-3.4.2.gem -> hashie-3.4.3.gem ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/CHANGELOG.md new/CHANGELOG.md --- old/CHANGELOG.md 2015-06-02 15:48:43.000000000 +0200 +++ new/CHANGELOG.md 2015-10-25 19:56:06.000000000 +0100 @@ -1,3 +1,12 @@ +## 3.4.2 (10/25/2015) + +* [#314](https://github.com/intridea/hashie/pull/314): Added a `StrictKeyAccess` extension that will raise an error whenever a key is accessed that does not exist in the hash - [@pboling](https://github.com/pboling). +* [#304](https://github.com/intridea/hashie/pull/304): Ensured compatibility of `Hash` extensions with singleton objects - [@regexident](https://github.com/regexident). +* [#306](https://github.com/intridea/hashie/pull/306): Added `Hashie::Extensions::Dash::Coercion` - [@marshall-lee](https://github.com/marshall-lee). +* [#310](https://github.com/intridea/hashie/pull/310): Fixed `Hashie::Extensions::SafeAssignment` bug with private methods - [@marshall-lee](https://github.com/marshall-lee). +* [#313](https://github.com/intridea/hashie/pull/313): Restrict pending spec to only Ruby versions 2.2.0-2.2.2 - [@pboling](https://github.com/pboling). +* [#315](https://github.com/intridea/hashie/pull/315): Default `bin/` scripts: `console` and `setup` - [@pboling](https://github.com/pboling). + ## 3.4.2 (6/2/2015) * [#292](https://github.com/intridea/hashie/pull/292): Removed `Mash#id` and `Mash#type` - [@jrochkind](https://github.com/jrochkind). diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/README.md new/README.md --- old/README.md 2015-06-02 15:48:43.000000000 +0200 +++ new/README.md 2015-10-25 19:56:06.000000000 +0100 @@ -18,9 +18,9 @@ $ gem install hashie ``` -## Upgrading +## Stable Release -You're reading the documentation for the stable release of Hashie, which is 3.4.2. Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version. +You're reading the documentation for the stable release [3.4.3](https://github.com/intridea/hashie/blob/v3.4.3/README.md). ## Hash Extensions @@ -392,6 +392,25 @@ # => [{:title=>"Ruby for beginners", :pages=>120}, {:title=>"CSS for intermediates", :pages=>80}] ``` +## StrictKeyAccess + +This extension can be mixed in to allow a Hash to raise an error when attempting to extract a value using a non-existent key. + +### Example: + +```ruby +class StrictKeyAccessHash < Hash + include Hashie::Extensions::StrictKeyAccess +end + +>> hash = StrictKeyAccessHash[foo: "bar"] +=> {:foo=>"bar"} +>> hash[:foo] +=> "bar" +>> hash[:cow] + KeyError: key not found: :cow +``` + ## Mash Mash is an extended Hash that gives simple pseudo-object functionality that can be built from hashes and easily extended. It is intended to give the user easier access to the objects within the Mash through a property-like syntax, while still retaining all Hash functionality. @@ -607,6 +626,36 @@ To enable compatibility with Rails 4 use the [hashie-forbidden_attributes](https://github.com/Maxim-Filimonov/hashie-forbidden_attributes) gem. +### Dash Extension: Coercion. + +If you want to use `Hashie::Extensions::Coercion` together with `Dash` then +you may probably want to use `Hashie::Extensions::Dash::Coercion` instead. +This extension automatically includes `Hashie::Extensions::Coercion` +and also adds a convenient `:coerce` option to `property` so you can define coercion in one line +instead of using `property` and `coerce_key` separate: + +```ruby +class UserHash < Hashie::Dash + include Hashie::Extensions::Coercion + + property :id + property :posts + + coerce_key :posts, Array[PostHash] +end +``` + +This is the same as: + +```ruby +class UserHash < Hashie::Dash + include Hashie::Extensions::Dash::Coercion + + property :id + property :posts, coerce: Array[PostHash] +end +``` + ## Trash A Trash is a Dash that allows you to translate keys on initialization. It mixes Files old/checksums.yaml.gz and new/checksums.yaml.gz differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hashie.gemspec new/hashie.gemspec --- old/hashie.gemspec 2015-06-02 15:48:43.000000000 +0200 +++ new/hashie.gemspec 2015-10-25 19:56:06.000000000 +0100 @@ -18,4 +18,5 @@ gem.add_development_dependency 'rake' gem.add_development_dependency 'rspec', '~> 3.0' + gem.add_development_dependency 'rspec-pending_for', '~> 0.1' end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/hashie/extensions/coercion.rb new/lib/hashie/extensions/coercion.rb --- old/lib/hashie/extensions/coercion.rb 2015-06-02 15:48:43.000000000 +0200 +++ new/lib/hashie/extensions/coercion.rb 2015-10-25 19:56:06.000000000 +0100 @@ -29,51 +29,17 @@ def set_value_with_coercion(key, value) into = self.class.key_coercion(key) || self.class.value_coercion(value) - return set_value_without_coercion(key, value) if value.nil? || into.nil? - - begin - return set_value_without_coercion(key, coerce_or_init(into).call(value)) unless into.is_a?(Enumerable) - - if into.class <= ::Hash - key_coerce = coerce_or_init(into.flatten[0]) - value_coerce = coerce_or_init(into.flatten[-1]) - value = into.class[value.map { |k, v| [key_coerce.call(k), value_coerce.call(v)] }] - else # Enumerable but not Hash: Array, Set - value_coerce = coerce_or_init(into.first) - value = into.class.new(value.map { |v| value_coerce.call(v) }) + unless value.nil? || into.nil? + begin + value = self.class.fetch_coercion(into).call(value) + rescue NoMethodError, TypeError => e + raise CoercionError, "Cannot coerce property #{key.inspect} from #{value.class} to #{into}: #{e.message}" end - rescue NoMethodError, TypeError => e - raise CoercionError, "Cannot coerce property #{key.inspect} from #{value.class} to #{into}: #{e.message}" end set_value_without_coercion(key, value) end - def coerce_or_init(type) - return type if type.is_a? Proc - - if CORE_TYPES.key?(type) - lambda do |v| - return v if v.is_a? type - return v.send(CORE_TYPES[type]) - end - elsif type.respond_to?(:coerce) - lambda do |v| - return v if v.is_a? type - type.coerce(v) - end - elsif type.respond_to?(:new) - lambda do |v| - return v if v.is_a? type - type.new(v) - end - else - fail TypeError, "#{type} is not a coercable type" - end - end - - private :coerce_or_init - def custom_writer(key, value, _convert = true) self[key] = value end @@ -175,6 +141,66 @@ strict_value_coercions[from] || lenient_value_coercions[from] end + def fetch_coercion(type) + return type if type.is_a? Proc + coercion_cache[type] + end + + def coercion_cache + @coercion_cache ||= ::Hash.new do |hash, type| + hash[type] = build_coercion(type) + end + end + + def build_coercion(type) + if type.is_a? Enumerable + if type.class <= ::Hash + type, key_type, value_type = type.class, *type.first + build_hash_coercion(type, key_type, value_type) + else # Enumerable but not Hash: Array, Set + type, value_type = type.class, type.first + build_container_coercion(type, value_type) + end + elsif CORE_TYPES.key? type + build_core_type_coercion(type) + elsif type.respond_to? :coerce + lambda do |value| + return value if value.is_a? type + type.coerce(value) + end + elsif type.respond_to? :new + lambda do |value| + return value if value.is_a? type + type.new(value) + end + else + fail TypeError, "#{type} is not a coercable type" + end + end + + def build_hash_coercion(type, key_type, value_type) + key_coerce = fetch_coercion(key_type) + value_coerce = fetch_coercion(value_type) + lambda do |value| + type[value.map { |k, v| [key_coerce.call(k), value_coerce.call(v)] }] + end + end + + def build_container_coercion(type, value_type) + value_coerce = fetch_coercion(value_type) + lambda do |value| + type.new(value.map { |v| value_coerce.call(v) }) + end + end + + def build_core_type_coercion(type) + name = CORE_TYPES[type] + lambda do |value| + return value if value.is_a? type + return value.send(name) + end + end + def inherited(klass) super diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/hashie/extensions/dash/coercion.rb new/lib/hashie/extensions/dash/coercion.rb --- old/lib/hashie/extensions/dash/coercion.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/hashie/extensions/dash/coercion.rb 2015-10-25 19:56:06.000000000 +0100 @@ -0,0 +1,25 @@ +module Hashie + module Extensions + module Dash + module Coercion + # Extends a Dash with the ability to define coercion for properties. + + def self.included(base) + base.send :include, Hashie::Extensions::Coercion + base.extend ClassMethods + end + + module ClassMethods + # Defines a property on the Dash. Options are the standard + # <tt>Hashie::Dash#property</tt> options plus: + # + # * <tt>:coerce</tt> - The class into which you want the property coerced. + def property(property_name, options = {}) + super + coerce_key property_name, options[:coerce] if options[:coerce] + end + end + end + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/hashie/extensions/dash/property_translation.rb new/lib/hashie/extensions/dash/property_translation.rb --- old/lib/hashie/extensions/dash/property_translation.rb 2015-06-02 15:48:43.000000000 +0200 +++ new/lib/hashie/extensions/dash/property_translation.rb 2015-10-25 19:56:06.000000000 +0100 @@ -72,8 +72,6 @@ def property(property_name, options = {}) super - options[:from] = options[:from] if options[:from] - if options[:from] if property_name == options[:from] fail ArgumentError, "Property name (#{property_name}) and :from option must not be the same" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/hashie/extensions/deep_merge.rb new/lib/hashie/extensions/deep_merge.rb --- old/lib/hashie/extensions/deep_merge.rb 2015-06-02 15:48:43.000000000 +0200 +++ new/lib/hashie/extensions/deep_merge.rb 2015-10-25 19:56:06.000000000 +0100 @@ -3,7 +3,9 @@ module DeepMerge # Returns a new hash with +self+ and +other_hash+ merged recursively. def deep_merge(other_hash, &block) - dup.deep_merge!(other_hash, &block) + copy = dup + copy.extend(Hashie::Extensions::DeepMerge) unless copy.respond_to?(:deep_merge!) + copy.deep_merge!(other_hash, &block) end # Returns a new hash with +self+ and +other_hash+ merged recursively. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/hashie/extensions/mash/safe_assignment.rb new/lib/hashie/extensions/mash/safe_assignment.rb --- old/lib/hashie/extensions/mash/safe_assignment.rb 2015-06-02 15:48:43.000000000 +0200 +++ new/lib/hashie/extensions/mash/safe_assignment.rb 2015-10-25 19:56:06.000000000 +0100 @@ -3,7 +3,7 @@ module Mash module SafeAssignment def custom_writer(key, *args) #:nodoc: - fail ArgumentError, "The property #{key} clashes with an existing method." if methods.include?(key.to_sym) + fail ArgumentError, "The property #{key} clashes with an existing method." if !key?(key) && respond_to?(key, true) super end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/hashie/extensions/strict_key_access.rb new/lib/hashie/extensions/strict_key_access.rb --- old/lib/hashie/extensions/strict_key_access.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/hashie/extensions/strict_key_access.rb 2015-10-25 19:56:06.000000000 +0100 @@ -0,0 +1,74 @@ +module Hashie + module Extensions + # SRP: This extension will fail an error whenever a key is accessed that does not exist in the hash. + # + # EXAMPLE: + # + # class StrictKeyAccessHash < Hash + # include Hashie::Extensions::StrictKeyAccess + # end + # + # >> hash = StrictKeyAccessHash[foo: "bar"] + # => {:foo=>"bar"} + # >> hash[:foo] + # => "bar" + # >> hash[:cow] + # KeyError: key not found: :cow + # + # NOTE: For googlers coming from Python to Ruby, this extension makes a Hash behave more like a "Dictionary". + # + module StrictKeyAccess + class DefaultError < StandardError + def initialize(msg = 'Setting or using a default with Hashie::Extensions::StrictKeyAccess does not make sense', *args) + super + end + end + + # NOTE: Defaults don't make any sense with a StrictKeyAccess. + # NOTE: When key lookup fails a KeyError is raised. + # + # Normal: + # + # >> a = Hash.new(123) + # => {} + # >> a["noes"] + # => 123 + # + # With StrictKeyAccess: + # + # >> a = StrictKeyAccessHash.new(123) + # => {} + # >> a["noes"] + # KeyError: key not found: "noes" + # + def [](key) + fetch(key) + end + + def default(_ = nil) + fail DefaultError + end + + def default=(_) + fail DefaultError + end + + def default_proc + fail DefaultError + end + + def default_proc=(_) + fail DefaultError + end + + def key(value) + result = super + if result.nil? && (!key?(result) || self[result] != value) + fail KeyError, "key not found with value of #{value.inspect}" + else + result + end + end + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/hashie/extensions/stringify_keys.rb new/lib/hashie/extensions/stringify_keys.rb --- old/lib/hashie/extensions/stringify_keys.rb 2015-06-02 15:48:43.000000000 +0200 +++ new/lib/hashie/extensions/stringify_keys.rb 2015-10-25 19:56:06.000000000 +0100 @@ -15,7 +15,7 @@ # Return a new hash with all keys converted # to strings. def stringify_keys - dup.stringify_keys! + StringifyKeys.stringify_keys(self) end module ClassMethods @@ -25,7 +25,7 @@ def stringify_keys_recursively!(object) case object when self.class - object.stringify_keys! + stringify_keys!(object) when ::Array object.each do |i| stringify_keys_recursively!(i) @@ -43,6 +43,7 @@ # test.stringify_keys! # test # => {'abc' => 'def'} def stringify_keys!(hash) + hash.extend(Hashie::Extensions::StringifyKeys) unless hash.respond_to?(:stringify_keys!) hash.keys.each do |k| stringify_keys_recursively!(hash[k]) hash[k.to_s] = hash.delete(k) @@ -54,8 +55,10 @@ # to strings. # @param [::Hash] hash def stringify_keys(hash) - hash.dup.tap do | new_hash | - stringify_keys! new_hash + copy = hash.dup + copy.extend(Hashie::Extensions::StringifyKeys) unless copy.respond_to?(:stringify_keys!) + copy.tap do |new_hash| + stringify_keys!(new_hash) end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/hashie/extensions/symbolize_keys.rb new/lib/hashie/extensions/symbolize_keys.rb --- old/lib/hashie/extensions/symbolize_keys.rb 2015-06-02 15:48:43.000000000 +0200 +++ new/lib/hashie/extensions/symbolize_keys.rb 2015-10-25 19:56:06.000000000 +0100 @@ -15,7 +15,7 @@ # Return a new hash with all keys converted # to symbols. def symbolize_keys - dup.symbolize_keys! + SymbolizeKeys.symbolize_keys(self) end module ClassMethods @@ -23,9 +23,9 @@ # hashes and arrays. # @api private def symbolize_keys_recursively!(object) - object.symbolize_keys! if object.respond_to? :symbolize_keys! - case object + when self.class + symbolize_keys!(object) when ::Array object.each do |i| symbolize_keys_recursively!(i) @@ -43,6 +43,7 @@ # Hashie.symbolize_keys! test # test # => {:abc => 'def'} def symbolize_keys!(hash) + hash.extend(Hashie::Extensions::SymbolizeKeys) unless hash.respond_to?(:symbolize_keys!) hash.keys.each do |k| symbolize_keys_recursively!(hash[k]) hash[k.to_sym] = hash.delete(k) @@ -54,8 +55,10 @@ # to symbols. # @param [::Hash] hash def symbolize_keys(hash) - hash.dup.tap do | new_hash | - symbolize_keys! new_hash + copy = hash.dup + copy.extend(Hashie::Extensions::SymbolizeKeys) unless copy.respond_to?(:symbolize_keys!) + copy.tap do |new_hash| + symbolize_keys!(new_hash) end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/hashie/mash.rb new/lib/hashie/mash.rb --- old/lib/hashie/mash.rb 2015-06-02 15:48:43.000000000 +0200 +++ new/lib/hashie/mash.rb 2015-10-25 19:56:06.000000000 +0100 @@ -58,7 +58,6 @@ include Hashie::Extensions::PrettyInspect ALLOWED_SUFFIXES = %w(? ! = _) - SUFFIXES_PARSER = /(.*?)([#{ALLOWED_SUFFIXES.join}]?)$/ def self.load(path, options = {}) @_mashes ||= new @@ -211,10 +210,9 @@ def respond_to_missing?(method_name, *args) return true if key?(method_name) - _, suffix = method_suffix(method_name) - case suffix - when '=', '?', '!', '_' - return true + suffix = method_suffix(method_name) + if suffix + true else super end @@ -227,15 +225,15 @@ def method_missing(method_name, *args, &blk) return self.[](method_name, &blk) if key?(method_name) - name, suffix = method_suffix(method_name) + name, suffix = method_name_and_suffix(method_name) case suffix - when '=' + when '='.freeze assign_property(name, args.first) - when '?' + when '?'.freeze !!self[name] - when '!' + when '!'.freeze initializing_reader(name) - when '_' + when '_'.freeze underbang_reader(name) else self[method_name] @@ -254,9 +252,18 @@ protected + def method_name_and_suffix(method_name) + method_name = method_name.to_s + if method_name.end_with?(*ALLOWED_SUFFIXES) + [method_name[0..-2], method_name[-1]] + else + [method_name[0..-1], nil] + end + end + def method_suffix(method_name) - match = method_name.to_s.match(SUFFIXES_PARSER) - [match[1], match[2]] + method_name = method_name.to_s + method_name[-1] if method_name.end_with?(*ALLOWED_SUFFIXES) end def convert_key(key) #:nodoc: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/hashie/version.rb new/lib/hashie/version.rb --- old/lib/hashie/version.rb 2015-06-02 15:48:43.000000000 +0200 +++ new/lib/hashie/version.rb 2015-10-25 19:56:06.000000000 +0100 @@ -1,3 +1,3 @@ module Hashie - VERSION = '3.4.2' + VERSION = '3.4.3' end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/hashie.rb new/lib/hashie.rb --- old/lib/hashie.rb 2015-06-02 15:48:43.000000000 +0200 +++ new/lib/hashie.rb 2015-10-25 19:56:06.000000000 +0100 @@ -26,6 +26,7 @@ autoload :PrettyInspect, 'hashie/extensions/pretty_inspect' autoload :KeyConversion, 'hashie/extensions/key_conversion' autoload :MethodAccessWithOverride, 'hashie/extensions/method_access' + autoload :StrictKeyAccess, 'hashie/extensions/strict_key_access' module Parsers autoload :YamlErbParser, 'hashie/extensions/parsers/yaml_erb_parser' @@ -34,6 +35,7 @@ module Dash autoload :IndifferentAccess, 'hashie/extensions/dash/indifferent_access' autoload :PropertyTranslation, 'hashie/extensions/dash/property_translation' + autoload :Coercion, 'hashie/extensions/dash/coercion' end module Mash diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 2015-06-02 15:48:43.000000000 +0200 +++ new/metadata 2015-10-25 19:56:06.000000000 +0100 @@ -1,7 +1,7 @@ --- !ruby/object:Gem::Specification name: hashie version: !ruby/object:Gem::Version - version: 3.4.2 + version: 3.4.3 platform: ruby authors: - Michael Bleigh @@ -9,7 +9,7 @@ autorequire: bindir: bin cert_chain: [] -date: 2015-06-02 00:00:00.000000000 Z +date: 2015-10-25 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: rake @@ -39,6 +39,20 @@ - - "~>" - !ruby/object:Gem::Version version: '3.0' +- !ruby/object:Gem::Dependency + name: rspec-pending_for + requirement: !ruby/object:Gem::Requirement + requirements: + - - "~>" + - !ruby/object:Gem::Version + version: '0.1' + type: :development + prerelease: false + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - "~>" + - !ruby/object:Gem::Version + version: '0.1' description: Hashie is a collection of classes and mixins that make hashes more powerful. email: - michael@intridea.com @@ -59,6 +73,7 @@ - lib/hashie/clash.rb - lib/hashie/dash.rb - lib/hashie/extensions/coercion.rb +- lib/hashie/extensions/dash/coercion.rb - lib/hashie/extensions/dash/indifferent_access.rb - lib/hashie/extensions/dash/property_translation.rb - lib/hashie/extensions/deep_fetch.rb @@ -73,6 +88,7 @@ - lib/hashie/extensions/method_access.rb - lib/hashie/extensions/parsers/yaml_erb_parser.rb - lib/hashie/extensions/pretty_inspect.rb +- lib/hashie/extensions/strict_key_access.rb - lib/hashie/extensions/stringify_keys.rb - lib/hashie/extensions/symbolize_keys.rb - lib/hashie/hash.rb @@ -84,6 +100,7 @@ - spec/hashie/dash_spec.rb - spec/hashie/extensions/autoload_spec.rb - spec/hashie/extensions/coercion_spec.rb +- spec/hashie/extensions/dash/coercion_spec.rb - spec/hashie/extensions/dash/indifferent_access_spec.rb - spec/hashie/extensions/deep_fetch_spec.rb - spec/hashie/extensions/deep_find_spec.rb @@ -96,6 +113,7 @@ - spec/hashie/extensions/mash/safe_assignment_spec.rb - spec/hashie/extensions/merge_initializer_spec.rb - spec/hashie/extensions/method_access_spec.rb +- spec/hashie/extensions/strict_key_access_spec.rb - spec/hashie/extensions/stringify_keys_spec.rb - spec/hashie/extensions/symbolize_keys_spec.rb - spec/hashie/hash_spec.rb @@ -106,7 +124,6 @@ - spec/hashie/version_spec.rb - spec/spec_helper.rb - spec/support/module_context.rb -- spec/support/ruby_version.rb homepage: https://github.com/intridea/hashie licenses: - MIT @@ -127,35 +144,36 @@ version: '0' requirements: [] rubyforge_project: -rubygems_version: 2.4.5 +rubygems_version: 2.4.8 signing_key: specification_version: 4 summary: Your friendly neighborhood hash library. test_files: -- spec/spec_helper.rb -- spec/support/ruby_version.rb -- spec/support/module_context.rb -- spec/hashie/parsers/yaml_erb_parser_spec.rb -- spec/hashie/version_spec.rb -- spec/hashie/rash_spec.rb -- spec/hashie/dash_spec.rb -- spec/hashie/hash_spec.rb - spec/hashie/clash_spec.rb -- spec/hashie/mash_spec.rb -- spec/hashie/trash_spec.rb +- spec/hashie/dash_spec.rb +- spec/hashie/extensions/autoload_spec.rb +- spec/hashie/extensions/coercion_spec.rb +- spec/hashie/extensions/dash/coercion_spec.rb +- spec/hashie/extensions/dash/indifferent_access_spec.rb - spec/hashie/extensions/deep_fetch_spec.rb -- spec/hashie/extensions/method_access_spec.rb -- spec/hashie/extensions/key_conversion_spec.rb +- spec/hashie/extensions/deep_find_spec.rb - spec/hashie/extensions/deep_locate_spec.rb - spec/hashie/extensions/deep_merge_spec.rb -- spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb -- spec/hashie/extensions/symbolize_keys_spec.rb -- spec/hashie/extensions/mash/safe_assignment_spec.rb -- spec/hashie/extensions/deep_find_spec.rb - spec/hashie/extensions/ignore_undeclared_spec.rb -- spec/hashie/extensions/autoload_spec.rb -- spec/hashie/extensions/stringify_keys_spec.rb - spec/hashie/extensions/indifferent_access_spec.rb -- spec/hashie/extensions/coercion_spec.rb +- spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb +- spec/hashie/extensions/key_conversion_spec.rb +- spec/hashie/extensions/mash/safe_assignment_spec.rb - spec/hashie/extensions/merge_initializer_spec.rb -- spec/hashie/extensions/dash/indifferent_access_spec.rb +- spec/hashie/extensions/method_access_spec.rb +- spec/hashie/extensions/strict_key_access_spec.rb +- spec/hashie/extensions/stringify_keys_spec.rb +- spec/hashie/extensions/symbolize_keys_spec.rb +- spec/hashie/hash_spec.rb +- spec/hashie/mash_spec.rb +- spec/hashie/parsers/yaml_erb_parser_spec.rb +- spec/hashie/rash_spec.rb +- spec/hashie/trash_spec.rb +- spec/hashie/version_spec.rb +- spec/spec_helper.rb +- spec/support/module_context.rb diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/hashie/extensions/dash/coercion_spec.rb new/spec/hashie/extensions/dash/coercion_spec.rb --- old/spec/hashie/extensions/dash/coercion_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/hashie/extensions/dash/coercion_spec.rb 2015-10-25 19:56:07.000000000 +0100 @@ -0,0 +1,13 @@ +require 'spec_helper' + +describe Hashie::Extensions::Dash::Coercion do + class DashWithCoercion < Hashie::Dash + include Hashie::Extensions::Dash::Coercion + + property :type, coerce: Symbol + end + + it 'does the coercion of properties' do + expect(DashWithCoercion.new(type: 'something')).to eq(type: :something) + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/hashie/extensions/deep_merge_spec.rb new/spec/hashie/extensions/deep_merge_spec.rb --- old/spec/hashie/extensions/deep_merge_spec.rb 2015-06-02 15:48:43.000000000 +0200 +++ new/spec/hashie/extensions/deep_merge_spec.rb 2015-10-25 19:56:07.000000000 +0100 @@ -42,4 +42,24 @@ expect(h1).to eq expected_hash end end + + context 'from extended object' do + subject { Hash } + let(:h1) { subject.new.merge(a: 100, c: { c1: 100 }).extend(Hashie::Extensions::DeepMerge) } + let(:h2) { { b: 250, c: { c1: 200 } } } + let(:expected_hash) { { a: 100, b: 250, c: { c1: 200 } } } + + it 'does not raise error' do + expect { h1.deep_merge(h2) } .not_to raise_error + end + + it 'deep merges two hashes' do + expect(h1.deep_merge(h2)).to eq expected_hash + end + + it 'deep merges another hash in place via bang method' do + h1.deep_merge!(h2) + expect(h1).to eq expected_hash + end + end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/hashie/extensions/mash/safe_assignment_spec.rb new/spec/hashie/extensions/mash/safe_assignment_spec.rb --- old/spec/hashie/extensions/mash/safe_assignment_spec.rb 2015-06-02 15:48:43.000000000 +0200 +++ new/spec/hashie/extensions/mash/safe_assignment_spec.rb 2015-10-25 19:56:07.000000000 +0100 @@ -3,17 +3,44 @@ describe Hashie::Extensions::Mash::SafeAssignment do class MashWithSafeAssignment < Hashie::Mash include Hashie::Extensions::Mash::SafeAssignment + + private + + def my_own_private + :hello! + end end context 'when included in Mash' do subject { MashWithSafeAssignment.new } + context 'when not attempting to override a method' do + it 'assigns just fine' do + expect do + subject.blabla = 'Test' + subject.blabla = 'Test' + end.to_not raise_error + end + end + context 'when attempting to override a method' do it 'raises an error' do expect { subject.zip = 'Test' }.to raise_error(ArgumentError) end end + context 'when attempting to override a private method' do + it 'raises an error' do + expect { subject.my_own_private = 'Test' }.to raise_error(ArgumentError) + end + end + + context 'when attempting to initialize with predefined method' do + it 'raises an error' do + expect { MashWithSafeAssignment.new(zip: true) }.to raise_error(ArgumentError) + end + end + context 'when setting as a hash key' do it 'still raises if conflicts with a method' do expect { subject[:zip] = 'Test' }.to raise_error(ArgumentError) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/hashie/extensions/strict_key_access_spec.rb new/spec/hashie/extensions/strict_key_access_spec.rb --- old/spec/hashie/extensions/strict_key_access_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/hashie/extensions/strict_key_access_spec.rb 2015-10-25 19:56:07.000000000 +0100 @@ -0,0 +1,110 @@ +require 'spec_helper' + +describe Hashie::Extensions::StrictKeyAccess do + class StrictKeyAccessHash < Hash + include Hashie::Extensions::StrictKeyAccess + end + + shared_examples_for 'StrictKeyAccess with valid key' do |options = {}| + before { pending_for(options[:pending]) } if options[:pending] + context 'set' do + let(:new_value) { 42 } + it('returns value') do + expect(instance.send(:[]=, valid_key, new_value)).to eq new_value + end + end + context 'access' do + it('returns value') do + expect(instance[valid_key]).to eq valid_value + end + end + context 'lookup' do + it('returns key') do + expect(instance.key(valid_value)).to eq valid_key + end + end + end + shared_examples_for 'StrictKeyAccess with invalid key' do |options = {}| + before { pending_for(options[:pending]) } if options[:pending] + context 'access' do + it('raises an error') do + # Formatting of the error message varies on Rubinius and ruby-head + expect { instance[invalid_key] }.to raise_error KeyError + end + end + context 'lookup' do + it('raises an error') do + # Formatting of the error message does not vary here because raised by StrictKeyAccess + expect { instance.key(invalid_value) }.to raise_error KeyError, + %(key not found with value of #{invalid_value.inspect}) + end + end + end + shared_examples_for 'StrictKeyAccess raises KeyError instead of allowing defaults' do + context '#default' do + it 'raises an error' do + expect { instance.default(invalid_key) }.to raise_error Hashie::Extensions::StrictKeyAccess::DefaultError, + 'Setting or using a default with Hashie::Extensions::StrictKeyAccess does not make sense' + end + end + context '#default=' do + it 'raises an error' do + expect { instance.default = invalid_key }.to raise_error Hashie::Extensions::StrictKeyAccess::DefaultError, + 'Setting or using a default with Hashie::Extensions::StrictKeyAccess does not make sense' + end + end + context '#default_proc' do + it 'raises an error' do + expect { instance.default_proc }.to raise_error Hashie::Extensions::StrictKeyAccess::DefaultError, + 'Setting or using a default with Hashie::Extensions::StrictKeyAccess does not make sense' + end + end + context '#default_proc=' do + it 'raises an error' do + expect { instance.default_proc = proc {} }.to raise_error Hashie::Extensions::StrictKeyAccess::DefaultError, + 'Setting or using a default with Hashie::Extensions::StrictKeyAccess does not make sense' + end + end + end + + let(:klass) { StrictKeyAccessHash } + let(:instance) { StrictKeyAccessHash.new(*initialization_args) } + let(:initialization_args) do + [ + { valid_key => valid_value } + ] + end + let(:valid_key) { :abc } + let(:valid_value) { 'def' } + let(:invalid_key) { :mega } + let(:invalid_value) { 'death' } + + context '.new' do + context 'no defaults at initialization' do + let(:initialization_args) { [] } + before do + instance.merge!(valid_key => valid_value) + end + it_behaves_like 'StrictKeyAccess with valid key' + it_behaves_like 'StrictKeyAccess with invalid key' + it_behaves_like 'StrictKeyAccess raises KeyError instead of allowing defaults' + end + context 'with defaults at initialization' do + before do + instance.merge!(valid_key => valid_value) + end + it_behaves_like 'StrictKeyAccess with valid key' + it_behaves_like 'StrictKeyAccess with invalid key' + it_behaves_like 'StrictKeyAccess raises KeyError instead of allowing defaults' + end + it_behaves_like 'StrictKeyAccess with invalid key' + it_behaves_like 'StrictKeyAccess raises KeyError instead of allowing defaults' + end + + context '.[]' do + let(:instance) { StrictKeyAccessHash[*initialization_args] } + it_behaves_like 'StrictKeyAccess with valid key', pending: { engine: 'rbx' } + it_behaves_like 'StrictKeyAccess with invalid key', pending: { engine: 'rbx' } + it_behaves_like 'StrictKeyAccess raises KeyError instead of allowing defaults' + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/hashie/extensions/stringify_keys_spec.rb new/spec/hashie/extensions/stringify_keys_spec.rb --- old/spec/hashie/extensions/stringify_keys_spec.rb 2015-06-02 15:48:43.000000000 +0200 +++ new/spec/hashie/extensions/stringify_keys_spec.rb 2015-10-25 19:56:07.000000000 +0100 @@ -80,6 +80,29 @@ include_examples 'stringify_keys!' end end + + context 'singleton methods' do + subject { Hash } + let(:object) { subject.new.merge(a: 1, b: { c: 2 }).extend(Hashie::Extensions::StringifyKeys) } + let(:expected_hash) { { 'a' => 1, 'b' => { 'c' => 2 } } } + + describe '.stringify_keys' do + it 'does not raise error' do + expect { object.stringify_keys } .not_to raise_error + end + it 'produces expected stringified hash' do + expect(object.stringify_keys).to eq(expected_hash) + end + end + describe '.stringify_keys!' do + it 'does not raise error' do + expect { object.stringify_keys! } .not_to raise_error + end + it 'produces expected stringified hash' do + expect(object.stringify_keys!).to eq(expected_hash) + end + end + end end describe Hashie do diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/hashie/extensions/symbolize_keys_spec.rb new/spec/hashie/extensions/symbolize_keys_spec.rb --- old/spec/hashie/extensions/symbolize_keys_spec.rb 2015-06-02 15:48:43.000000000 +0200 +++ new/spec/hashie/extensions/symbolize_keys_spec.rb 2015-10-25 19:56:07.000000000 +0100 @@ -85,6 +85,29 @@ include_examples 'symbolize_keys!' end end + + context 'singleton methods' do + subject { Hash } + let(:object) { subject.new.merge('a' => 1, 'b' => { 'c' => 2 }).extend(Hashie::Extensions::SymbolizeKeys) } + let(:expected_hash) { { a: 1, b: { c: 2 } } } + + describe '.symbolize_keys' do + it 'does not raise error' do + expect { object.symbolize_keys }.not_to raise_error + end + it 'produces expected symbolized hash' do + expect(object.symbolize_keys).to eq(expected_hash) + end + end + describe '.symbolize_keys!' do + it 'does not raise error' do + expect { object.symbolize_keys! }.not_to raise_error + end + it 'produces expected symbolized hash' do + expect(object.symbolize_keys!).to eq(expected_hash) + end + end + end end describe Hashie do diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/hashie/mash_spec.rb new/spec/hashie/mash_spec.rb --- old/spec/hashie/mash_spec.rb 2015-06-02 15:48:43.000000000 +0200 +++ new/spec/hashie/mash_spec.rb 2015-10-25 19:56:07.000000000 +0100 @@ -1,6 +1,5 @@ require 'spec_helper' require 'delegate' -require 'support/ruby_version' describe Hashie::Mash do subject { Hashie::Mash.new } @@ -364,9 +363,7 @@ it 'is able to access an unknown suffixed key as a method' do # See https://github.com/intridea/hashie/pull/285 for more information - if mri22? - pending 'Bug in MRI 2.2.x means this behavior is broken in those versions' - end + pending_for(engine: 'ruby', versions: %w(2.2.0 2.2.1 2.2.2)) %w(= ? ! _).each do |suffix| expect(subject.method(:"xyz#{suffix}")).to_not be_nil diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/spec_helper.rb new/spec/spec_helper.rb --- old/spec/spec_helper.rb 2015-06-02 15:48:43.000000000 +0200 +++ new/spec/spec_helper.rb 2015-10-25 19:56:07.000000000 +0100 @@ -7,6 +7,7 @@ require 'rspec' require 'hashie' +require 'rspec/pending_for' RSpec.configure do |config| config.expect_with :rspec do |expect| diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/support/ruby_version.rb new/spec/support/ruby_version.rb --- old/spec/support/ruby_version.rb 2015-06-02 15:48:43.000000000 +0200 +++ new/spec/support/ruby_version.rb 1970-01-01 01:00:00.000000000 +0100 @@ -1,10 +0,0 @@ -def mri22? - ruby_version.start_with?('ruby_2.2') -end - -def ruby_version - interpreter = Object.const_defined?(:RUBY_ENGINE) && RUBY_ENGINE - version = Object.const_defined?(:RUBY_VERSION) && RUBY_VERSION - - "#{interpreter}_#{version}" -end
participants (1)
-
root@hilbert.suse.de