mwmitchell-rsolr 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,3 +1,6 @@
1
+ 0.8.6 - April 25, 2009
2
+ Removed the Mash stuff -- which means the response keys from solr are only accessable using String based keys. Why? RSolr has an aim to be lean and mean. Solr::Ext will maybe provide the Symbol/Mash stuff.
3
+
1
4
  0.8.5 - April 7, 2009
2
5
  The RSolr::Message #add method now accepts a single Message::Document or an array of Message::Document objects
3
6
  The Message::Document class has a new method: #add_field
data/README.rdoc CHANGED
@@ -7,7 +7,11 @@ A Ruby client for Apache Solr. Has transparent JRuby support by using "org.apach
7
7
  sudo gem install mwmitchell-rsolr
8
8
 
9
9
  ==Community
10
- http://groups.google.com/group/rsolr
10
+ http://groups.google.com/group/rsolr
11
+
12
+ ==Related Projects
13
+ http://github.com/mwmitchell/rsolr-ext
14
+ http://wiki.apache.org/solr/solr-ruby
11
15
 
12
16
  ==Simple usage:
13
17
  require 'rubygems'
data/Rakefile CHANGED
@@ -59,7 +59,7 @@ end
59
59
  desc 'Generate documentation for the rsolr gem.'
60
60
  Rake::RDocTask.new(:doc) do |rdoc|
61
61
  rdoc.rdoc_dir = 'doc'
62
- rdoc.title = 'Solr-Ruby'
62
+ rdoc.title = 'RSolr'
63
63
  rdoc.options << '--line-numbers' << '--inline-source'
64
64
  rdoc.rdoc_files.include('README.rdoc')
65
65
  rdoc.rdoc_files.include('lib/**/*.rb')
data/examples/direct.rb CHANGED
@@ -16,10 +16,10 @@ puts
16
16
 
17
17
  response = solr.select :q=>'ipod', :fq=>'price:[0 TO 50]', :rows=>2, :start=>0
18
18
 
19
- docs = response[:response][:docs]
19
+ docs = response['response']['docs']
20
20
 
21
21
  docs.each do |doc|
22
- puts doc[:timestamp]
22
+ puts doc['timestamp']
23
23
  end
24
24
 
25
25
  solr.delete_by_query('*:*') and solr.commit
data/examples/http.rb CHANGED
@@ -16,8 +16,8 @@ response = solr.select(:q=>'ipod', :fq=>'price:[0 TO 50]', :rows=>2, :start=>0)
16
16
 
17
17
  puts "URL : #{response.adapter_response[:url]} -> #{response.adapter_response[:status_code]}"
18
18
 
19
- solr_response[:response][:docs].each do |doc|
20
- puts doc[:timestamp]
19
+ solr_response['response']['docs'].each do |doc|
20
+ puts doc['timestamp']
21
21
  end
22
22
 
23
23
  solr.delete_by_query('*:*') and solr.commit
data/lib/core_ext.rb CHANGED
@@ -8,13 +8,13 @@
8
8
 
9
9
  #end
10
10
 
11
- class Hash
12
-
13
- def to_mash
14
- self.is_a?(Mash) ? self : Mash.new(self)
15
- end
16
-
17
- end
11
+ #class Hash
12
+ #
13
+ # def to_mash
14
+ # self.is_a?(Mash) ? self : Mash.new(self)
15
+ # end
16
+ #
17
+ #end
18
18
 
19
19
  unless Array.respond_to?(:extract_options!)
20
20
  class Array
data/lib/rsolr.rb CHANGED
@@ -1,15 +1,12 @@
1
1
  # add this directory to the load path if it hasn't already been added
2
2
 
3
- if ! $:.include? File.dirname(__FILE__) or ! $:.include? File.expand_path(File.dirname(__FILE__))
4
- $: << File.dirname(__FILE__)
5
- end
3
+ $: << File.dirname(__FILE__) unless $:.include?(File.dirname(__FILE__))
6
4
 
7
5
  require 'core_ext'
8
- require 'mash'
9
6
 
10
7
  module RSolr
11
8
 
12
- VERSION = '0.8.5'
9
+ VERSION = '0.8.6'
13
10
 
14
11
  autoload :Message, 'rsolr/message'
15
12
  autoload :Connection, 'rsolr/connection'
@@ -102,7 +102,7 @@ class RSolr::Connection
102
102
  data = adapter_response[:body]
103
103
  # if the wt is :ruby, evaluate the ruby string response
104
104
  if adapter_response[:params][:wt] == :ruby
105
- data = Kernel.eval(data).to_mash
105
+ data = Kernel.eval(data)
106
106
  end
107
107
  # attach a method called #adapter_response that returns the original adapter response value
108
108
  def data.adapter_response
data/rsolr.gemspec ADDED
@@ -0,0 +1,46 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "rsolr"
3
+ s.version = "0.8.6"
4
+ s.date = "2009-04-25"
5
+ s.summary = "A Ruby client for Apache Solr"
6
+ s.email = "goodieboy@gmail.com"
7
+ s.homepage = "http://github.com/mwmitchell/rsolr"
8
+ s.description = "RSolr is a Ruby gem for working with Apache Solr!"
9
+ s.has_rdoc = true
10
+ s.authors = ["Matt Mitchell"]
11
+ s.files = [
12
+ "examples/http.rb",
13
+ "examples/direct.rb",
14
+ "lib/core_ext.rb",
15
+ "lib/rsolr.rb",
16
+ "lib/rsolr/adapter/direct.rb",
17
+ "lib/rsolr/adapter/http.rb",
18
+ "lib/rsolr/adapter.rb",
19
+ "lib/rsolr/connection.rb",
20
+ "lib/rsolr/http_client/adapter/curb.rb",
21
+ "lib/rsolr/http_client/adapter/net_http.rb",
22
+ "lib/rsolr/http_client/adapter.rb",
23
+ "lib/rsolr/http_client.rb",
24
+ "lib/rsolr/message.rb",
25
+ "LICENSE",
26
+ "Rakefile",
27
+ "README.rdoc",
28
+ "rsolr.gemspec",
29
+ "CHANGES.txt"
30
+ ]
31
+ s.test_files = [
32
+ "test/connection/direct_test.rb",
33
+ "test/connection/http_test.rb",
34
+ "test/connection/test_methods.rb",
35
+ "test/helper.rb",
36
+ "test/http_client/curb_test.rb",
37
+ "test/http_client/net_http_test.rb",
38
+ "test/http_client/test_methods.rb",
39
+ "test/http_client/util_test.rb",
40
+ "test/message_test.rb",
41
+ "test/rsolr_test.rb"
42
+ ]
43
+ #s.rdoc_options = ["--main", "README.rdoc"]
44
+ s.extra_rdoc_files = %w(LICENSE Rakefile README.rdoc CHANGES.txt)
45
+ s.add_dependency("builder", [">= 2.1.2"])
46
+ end
@@ -9,7 +9,7 @@ module ConnectionTestMethods
9
9
  def teardown
10
10
  @solr.delete_by_query('id:[* TO *]')
11
11
  @solr.commit
12
- assert_equal 0, @solr.select(:q=>'*:*')[:response][:docs].size
12
+ assert_equal 0, @solr.select(:q=>'*:*')['response']['docs'].size
13
13
  end
14
14
 
15
15
  # If :wt is NOT :ruby, the format doesn't get converted into a Mash (special Hash; see lib/mash.rb)
@@ -38,60 +38,60 @@ module ConnectionTestMethods
38
38
  @solr.add(:id=>1, :price=>1.00, :cat=>['electronics', 'something else'])
39
39
  @solr.commit
40
40
  r = @solr.select(:q=>'*:*')
41
- assert r.is_a?(Mash)
41
+ assert r.is_a?(Hash)
42
42
 
43
- docs = r[:response][:docs]
43
+ docs = r['response']['docs']
44
44
  assert_equal Array, docs.class
45
45
  first = docs.first
46
46
 
47
47
  # test the has? method
48
- assert_equal 1.00, first[:price]
48
+ assert_equal 1.00, first['price']
49
49
 
50
- assert_equal Array, first[:cat].class
51
- assert first[:cat].include?('electronics')
52
- assert first[:cat].include?('something else')
53
- assert first[:cat].include?('something else')
50
+ assert_equal Array, first['cat'].class
51
+ assert first['cat'].include?('electronics')
52
+ assert first['cat'].include?('something else')
53
+ assert first['cat'].include?('something else')
54
54
 
55
55
  end
56
56
 
57
57
  def test_add
58
- assert_equal 0, @solr.select(:q=>'*:*')[:response][:numFound]
58
+ assert_equal 0, @solr.select(:q=>'*:*')['response']['numFound']
59
59
  update_response = @solr.add({:id=>100})
60
- assert update_response.is_a?(Mash)
60
+ assert update_response.is_a?(Hash)
61
61
  #
62
62
  @solr.commit
63
- assert_equal 1, @solr.select(:q=>'*:*')[:response][:numFound]
63
+ assert_equal 1, @solr.select(:q=>'*:*')['response']['numFound']
64
64
  end
65
65
 
66
66
  def test_delete_by_id
67
67
  @solr.add(:id=>100)
68
68
  @solr.commit
69
- total = @solr.select(:q=>'*:*')[:response][:numFound]
69
+ total = @solr.select(:q=>'*:*')['response']['numFound']
70
70
  assert_equal 1, total
71
71
  delete_response = @solr.delete_by_id(100)
72
72
  @solr.commit
73
- assert delete_response.is_a?(Mash)
74
- total = @solr.select(:q=>'*:*')[:response][:numFound]
73
+ assert delete_response.is_a?(Hash)
74
+ total = @solr.select(:q=>'*:*')['response']['numFound']
75
75
  assert_equal 0, total
76
76
  end
77
77
 
78
78
  def test_delete_by_query
79
79
  @solr.add(:id=>1, :name=>'BLAH BLAH BLAH')
80
80
  @solr.commit
81
- assert_equal 1, @solr.select(:q=>'*:*')[:response][:numFound]
81
+ assert_equal 1, @solr.select(:q=>'*:*')['response']['numFound']
82
82
  response = @solr.delete_by_query('name:"BLAH BLAH BLAH"')
83
83
  @solr.commit
84
- assert response.is_a?(Mash)
85
- assert_equal 0, @solr.select(:q=>'*:*')[:response][:numFound]
84
+ assert response.is_a?(Hash)
85
+ assert_equal 0, @solr.select(:q=>'*:*')['response']['numFound']
86
86
  end
87
87
 
88
88
  def test_admin_luke_index_info
89
89
  response = @solr.send_request('/admin/luke', :numTerms=>0)
90
- assert response.is_a?(Mash)
90
+ assert response.is_a?(Hash)
91
91
  # make sure the ? methods are true/false
92
- assert [true, false].include?(response[:index][:current])
93
- assert [true, false].include?(response[:index][:optimized])
94
- assert [true, false].include?(response[:index][:hasDeletions])
92
+ assert [true, false].include?(response['index']['current'])
93
+ assert [true, false].include?(response['index']['optimized'])
94
+ assert [true, false].include?(response['index']['hasDeletions'])
95
95
  end
96
96
 
97
97
  end
data/test/helper.rb ADDED
@@ -0,0 +1,61 @@
1
+
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'rsolr')
3
+ require 'test/unit'
4
+
5
+ #
6
+ class Test::Unit::TestCase
7
+
8
+ def self.test(name, &block)
9
+ test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
10
+ defined = instance_method(test_name) rescue false
11
+ raise "#{test_name} is already defined in #{self}" if defined
12
+ if block_given?
13
+ define_method(test_name, &block)
14
+ else
15
+ define_method(test_name) do
16
+ flunk "No implementation provided for #{name}"
17
+ end
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+ class RSolrBaseTest < Test::Unit::TestCase
24
+
25
+ def assert_class(expected, instance)
26
+ assert_equal expected, instance.class
27
+ end
28
+
29
+ def default_test
30
+
31
+ end
32
+
33
+ end
34
+
35
+ begin
36
+ require 'rubygems'
37
+ require 'redgreen'
38
+ rescue LoadError
39
+ end
40
+
41
+ def mock_query_response
42
+ %({'responseHeader'=>{
43
+ 'status'=>0,'QTime'=>43,'params'=>{
44
+ 'q'=>'*:*','wt'=>'ruby','echoParams'=>'EXPLICIT'
45
+ }
46
+ },
47
+ 'response'=>{
48
+ 'numFound'=>26,'start'=>0,'docs'=>[
49
+ {'id'=>'SP2514N','inStock'=>true,'manu'=>'Samsung Electronics Co. Ltd.','name'=>'Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133','popularity'=>6,'price'=>92.0,'sku'=>'SP2514N','timestamp'=>'2008-11-21T17:21:55.601Z','cat'=>['electronics','hard drive'],'spell'=>['Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133'],'features'=>['7200RPM, 8MB cache, IDE Ultra ATA-133','NoiseGuard, SilentSeek technology, Fluid Dynamic Bearing (FDB) motor']},
50
+ {'id'=>'6H500F0','inStock'=>true,'manu'=>'Maxtor Corp.','name'=>'Maxtor DiamondMax 11 - hard drive - 500 GB - SATA-300','popularity'=>6,'price'=>350.0,'sku'=>'6H500F0','timestamp'=>'2008-11-21T17:21:55.617Z','cat'=>['electronics','hard drive'],'spell'=>['Maxtor DiamondMax 11 - hard drive - 500 GB - SATA-300'],'features'=>['SATA 3.0Gb/s, NCQ','8.5ms seek','16MB cache']},
51
+ {'id'=>'F8V7067-APL-KIT','inStock'=>false,'manu'=>'Belkin','name'=>'Belkin Mobile Power Cord for iPod w/ Dock','popularity'=>1,'price'=>19.95,'sku'=>'F8V7067-APL-KIT','timestamp'=>'2008-11-21T17:21:55.652Z','weight'=>4.0,'cat'=>['electronics','connector'],'spell'=>['Belkin Mobile Power Cord for iPod w/ Dock'],'features'=>['car power adapter, white']},
52
+ {'id'=>'IW-02','inStock'=>false,'manu'=>'Belkin','name'=>'iPod & iPod Mini USB 2.0 Cable','popularity'=>1,'price'=>11.5,'sku'=>'IW-02','timestamp'=>'2008-11-21T17:21:55.657Z','weight'=>2.0,'cat'=>['electronics','connector'],'spell'=>['iPod & iPod Mini USB 2.0 Cable'],'features'=>['car power adapter for iPod, white']},
53
+ {'id'=>'MA147LL/A','inStock'=>true,'includes'=>'earbud headphones, USB cable','manu'=>'Apple Computer Inc.','name'=>'Apple 60 GB iPod with Video Playback Black','popularity'=>10,'price'=>399.0,'sku'=>'MA147LL/A','timestamp'=>'2008-11-21T17:21:55.681Z','weight'=>5.5,'cat'=>['electronics','music'],'spell'=>['Apple 60 GB iPod with Video Playback Black'],'features'=>['iTunes, Podcasts, Audiobooks','Stores up to 15,000 songs, 25,000 photos, or 150 hours of video','2.5-inch, 320x240 color TFT LCD display with LED backlight','Up to 20 hours of battery life','Plays AAC, MP3, WAV, AIFF, Audible, Apple Lossless, H.264 video','Notes, Calendar, Phone book, Hold button, Date display, Photo wallet, Built-in games, JPEG photo playback, Upgradeable firmware, USB 2.0 compatibility, Playback speed control, Rechargeable capability, Battery level indication']},
54
+ {'id'=>'TWINX2048-3200PRO','inStock'=>true,'manu'=>'Corsair Microsystems Inc.','name'=>'CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail','popularity'=>5,'price'=>185.0,'sku'=>'TWINX2048-3200PRO','timestamp'=>'2008-11-21T17:21:55.706Z','cat'=>['electronics','memory'],'spell'=>['CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail'],'features'=>['CAS latency 2, 2-3-3-6 timing, 2.75v, unbuffered, heat-spreader']},
55
+ {'id'=>'VS1GB400C3','inStock'=>true,'manu'=>'Corsair Microsystems Inc.','name'=>'CORSAIR ValueSelect 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - Retail','popularity'=>7,'price'=>74.99,'sku'=>'VS1GB400C3','timestamp'=>'2008-11-21T17:21:55.71Z','cat'=>['electronics','memory'],'spell'=>['CORSAIR ValueSelect 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - Retail']},
56
+ {'id'=>'VDBDB1A16','inStock'=>true,'manu'=>'A-DATA Technology Inc.','name'=>'A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM','popularity'=>5,'sku'=>'VDBDB1A16','timestamp'=>'2008-11-21T17:21:55.712Z','cat'=>['electronics','memory'],'spell'=>['A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM'],'features'=>['CAS latency 3, 2.7v']},
57
+ {'id'=>'3007WFP','inStock'=>true,'includes'=>'USB cable','manu'=>'Dell, Inc.','name'=>'Dell Widescreen UltraSharp 3007WFP','popularity'=>6,'price'=>2199.0,'sku'=>'3007WFP','timestamp'=>'2008-11-21T17:21:55.724Z','weight'=>401.6,'cat'=>['electronics','monitor'],'spell'=>['Dell Widescreen UltraSharp 3007WFP'],'features'=>['30" TFT active matrix LCD, 2560 x 1600, .25mm dot pitch, 700:1 contrast']},
58
+ {'id'=>'VA902B','inStock'=>true,'manu'=>'ViewSonic Corp.','name'=>'ViewSonic VA902B - flat panel display - TFT - 19"','popularity'=>6,'price'=>279.95,'sku'=>'VA902B','timestamp'=>'2008-11-21T17:21:55.734Z','weight'=>190.4,'cat'=>['electronics','monitor'],'spell'=>['ViewSonic VA902B - flat panel display - TFT - 19"'],'features'=>['19" TFT active matrix LCD, 8ms response time, 1280 x 1024 native resolution']}]
59
+ }
60
+ })
61
+ end
@@ -0,0 +1,21 @@
1
+ require 'helper'
2
+
3
+ class SolrTest < RSolrBaseTest
4
+
5
+ def setup
6
+ if defined?(JRUBY_VERSION)
7
+ @solr = RSolr.connect(:adapter=>:direct)
8
+ else
9
+ @solr = RSolr.connect
10
+ end
11
+ end
12
+
13
+ def test_escape
14
+ expected = %q(http\:\/\/lucene\.apache\.org\/solr)
15
+ source = "http://lucene.apache.org/solr"
16
+ assert_equal expected, RSolr.escape(source)
17
+ assert @solr.respond_to?(:escape)
18
+ assert_equal expected, @solr.escape(source)
19
+ end
20
+
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mwmitchell-rsolr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Mitchell
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-07 00:00:00 -07:00
12
+ date: 2009-04-25 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -37,9 +37,7 @@ files:
37
37
  - examples/http.rb
38
38
  - examples/direct.rb
39
39
  - lib/core_ext.rb
40
- - lib/mash.rb
41
40
  - lib/rsolr.rb
42
- - lib/rsolr/adapter/common_methods.rb
43
41
  - lib/rsolr/adapter/direct.rb
44
42
  - lib/rsolr/adapter/http.rb
45
43
  - lib/rsolr/adapter.rb
@@ -52,7 +50,7 @@ files:
52
50
  - LICENSE
53
51
  - Rakefile
54
52
  - README.rdoc
55
- - rsolr-ruby.gemspec
53
+ - rsolr.gemspec
56
54
  - CHANGES.txt
57
55
  has_rdoc: true
58
56
  homepage: http://github.com/mwmitchell/rsolr
@@ -84,10 +82,10 @@ test_files:
84
82
  - test/connection/direct_test.rb
85
83
  - test/connection/http_test.rb
86
84
  - test/connection/test_methods.rb
85
+ - test/helper.rb
87
86
  - test/http_client/curb_test.rb
88
87
  - test/http_client/net_http_test.rb
89
88
  - test/http_client/test_methods.rb
90
89
  - test/http_client/util_test.rb
91
90
  - test/message_test.rb
92
- - test/rsolr_test
93
- - test/test_helpers.rb
91
+ - test/rsolr_test.rb
data/lib/mash.rb DELETED
@@ -1,148 +0,0 @@
1
- # This class has dubious semantics and we only have it so that people can write
2
- # params[:key] instead of params['key'].
3
- class Mash < Hash
4
-
5
- # @param constructor<Object>
6
- # The default value for the mash. Defaults to an empty hash.
7
- #
8
- # @details [Alternatives]
9
- # If constructor is a Hash, a new mash will be created based on the keys of
10
- # the hash and no default value will be set.
11
- def initialize(constructor = {})
12
- if constructor.is_a?(Hash)
13
- super()
14
- update(constructor)
15
- else
16
- super(constructor)
17
- end
18
- end
19
-
20
- # @param key<Object> The default value for the mash. Defaults to nil.
21
- #
22
- # @details [Alternatives]
23
- # If key is a Symbol and it is a key in the mash, then the default value will
24
- # be set to the value matching the key.
25
- def default(key = nil)
26
- if key.is_a?(Symbol) && include?(key = key.to_s)
27
- self[key]
28
- else
29
- super
30
- end
31
- end
32
-
33
- alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
34
- alias_method :regular_update, :update unless method_defined?(:regular_update)
35
-
36
- # @param key<Object> The key to set.
37
- # @param value<Object>
38
- # The value to set the key to.
39
- #
40
- # @see Mash#convert_key
41
- # @see Mash#convert_value
42
- def []=(key, value)
43
- regular_writer(convert_key(key), convert_value(value))
44
- end
45
-
46
- # @param other_hash<Hash>
47
- # A hash to update values in the mash with. The keys and the values will be
48
- # converted to Mash format.
49
- #
50
- # @return <Mash> The updated mash.
51
- def update(other_hash)
52
- other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
53
- self
54
- end
55
-
56
- alias_method :merge!, :update
57
-
58
- # @param key<Object> The key to check for. This will be run through convert_key.
59
- #
60
- # @return <TrueClass, FalseClass> True if the key exists in the mash.
61
- def key?(key)
62
- super(convert_key(key))
63
- end
64
-
65
- # def include? def has_key? def member?
66
- alias_method :include?, :key?
67
- alias_method :has_key?, :key?
68
- alias_method :member?, :key?
69
-
70
- # @param key<Object> The key to fetch. This will be run through convert_key.
71
- # @param *extras<Array> Default value.
72
- #
73
- # @return <Object> The value at key or the default value.
74
- def fetch(key, *extras)
75
- super(convert_key(key), *extras)
76
- end
77
-
78
- # @param *indices<Array>
79
- # The keys to retrieve values for. These will be run through +convert_key+.
80
- #
81
- # @return <Array> The values at each of the provided keys
82
- def values_at(*indices)
83
- indices.collect {|key| self[convert_key(key)]}
84
- end
85
-
86
- # @param hash<Hash> The hash to merge with the mash.
87
- #
88
- # @return <Mash> A new mash with the hash values merged in.
89
- def merge(hash)
90
- self.dup.update(hash)
91
- end
92
-
93
- # @param key<Object>
94
- # The key to delete from the mash.\
95
- def delete(key)
96
- super(convert_key(key))
97
- end
98
-
99
- # @param *rejected<Array[(String, Symbol)] The mash keys to exclude.
100
- #
101
- # @return <Mash> A new mash without the selected keys.
102
- #
103
- # @example
104
- # { :one => 1, :two => 2, :three => 3 }.except(:one)
105
- # #=> { "two" => 2, "three" => 3 }
106
- def except(*keys)
107
- super(*keys.map {|k| convert_key(k)})
108
- end
109
-
110
- # Used to provide the same interface as Hash.
111
- #
112
- # @return <Mash> This mash unchanged.
113
- def stringify_keys!; self end
114
-
115
- # @return <Hash> The mash as a Hash with string keys.
116
- def to_hash
117
- Hash.new(default).merge(self)
118
- end
119
-
120
- protected
121
- # @param key<Object> The key to convert.
122
- #
123
- # @param <Object>
124
- # The converted key. If the key was a symbol, it will be converted to a
125
- # string.
126
- #
127
- # @api private
128
- def convert_key(key)
129
- key.kind_of?(Symbol) ? key.to_s : key
130
- end
131
-
132
- # @param value<Object> The value to convert.
133
- #
134
- # @return <Object>
135
- # The converted value. A Hash or an Array of hashes, will be converted to
136
- # their Mash equivalents.
137
- #
138
- # @api private
139
- def convert_value(value)
140
- if value.class == Hash
141
- value.to_mash
142
- elsif value.is_a?(Array)
143
- value.collect { |e| convert_value(e) }
144
- else
145
- value
146
- end
147
- end
148
- end