mdwan-rsolr 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/core_ext/array.rb +7 -0
- data/lib/core_ext/hash.rb +42 -0
- data/lib/core_ext/object.rb +9 -0
- data/lib/core_ext.rb +1 -25
- data/lib/rsolr/connection.rb +1 -1
- data/lib/rsolr.rb +1 -1
- metadata +8 -5
- data/lib/mash.rb +0 -148
@@ -0,0 +1,42 @@
|
|
1
|
+
# TODO: test this
|
2
|
+
class Hash
|
3
|
+
# This is straight from ActiveSupport
|
4
|
+
unless Hash.respond_to?(:symbolize_keys) || Hash.respond_to?(:symbolize_keys)
|
5
|
+
# Return a new hash with all keys converted to symbols.
|
6
|
+
def symbolize_keys
|
7
|
+
inject({}) do |options, (key, value)|
|
8
|
+
options[(key.to_sym rescue key) || key] = value
|
9
|
+
options
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Destructively convert all keys to symbols.
|
14
|
+
def symbolize_keys!
|
15
|
+
self.replace(self.symbolize_keys)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# This is absent for some reason in Rails, at least for now. Merb has it and will probably make its way in with Rails 3.0
|
20
|
+
unless Hash.respond_to?(:recursive_symbolize_keys) || Hash.respond_to?(:recursive_symbolize_keys!)
|
21
|
+
def recursive_symbolize_keys
|
22
|
+
Hash.recursive_symbolize_keys(self.deep_clone)
|
23
|
+
end
|
24
|
+
|
25
|
+
def recursive_symbolize_keys!
|
26
|
+
Hash.recursive_symbolize_keys(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def self.recursive_symbolize_keys(hash)
|
31
|
+
hash = hash.symbolize_keys!
|
32
|
+
hash.each do |key, value|
|
33
|
+
if value.is_a?(Hash)
|
34
|
+
Hash.recursive_symbolize_keys(value)
|
35
|
+
elsif value.is_a?(Array)
|
36
|
+
value.each { |v| Hash.recursive_symbolize_keys(v) if v.is_a?(Hash)}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
hash
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Need to perform destructive operations on a clone without affecting referenced objects? BAM!
|
2
|
+
# This REALLY should be in Ruby. Perhaps Ruby 1.9 will have it...
|
3
|
+
unless Object.respond_to?(:deep_clone)
|
4
|
+
class Object
|
5
|
+
def deep_clone
|
6
|
+
Marshal::load(Marshal.dump(self))
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
data/lib/core_ext.rb
CHANGED
@@ -1,25 +1 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# allow symbol chaining: :one.two.three
|
4
|
-
# This breaks Rails, probably lots of other things too :(
|
5
|
-
#def method_missing(m)
|
6
|
-
# [self.to_s, m.to_s].join('.').to_sym
|
7
|
-
#end
|
8
|
-
|
9
|
-
#end
|
10
|
-
|
11
|
-
class Hash
|
12
|
-
|
13
|
-
def to_mash
|
14
|
-
self.is_a?(Mash) ? self : Mash.new(self)
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
unless Array.respond_to?(:extract_options!)
|
20
|
-
class Array
|
21
|
-
def extract_options!
|
22
|
-
last.is_a?(::Hash) ? pop : {}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
1
|
+
Dir[File.dirname(__FILE__) + '/core_ext/*.rb'].each { |file| require file }
|
data/lib/rsolr/connection.rb
CHANGED
@@ -97,7 +97,7 @@ class RSolr::Connection
|
|
97
97
|
#
|
98
98
|
def adapt_response(adapter_response)
|
99
99
|
if adapter_response[:params][:wt] == :ruby
|
100
|
-
data = Kernel.eval(adapter_response[:body]).
|
100
|
+
data = Kernel.eval(adapter_response[:body]).recursive_symbolize_keys
|
101
101
|
else
|
102
102
|
data = adapter_response[:body]
|
103
103
|
end
|
data/lib/rsolr.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mdwan-rsolr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- Michael Dwan
|
7
8
|
- Matt Mitchell
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
12
|
|
12
|
-
date: 2009-
|
13
|
+
date: 2009-04-02 00:00:00 -07:00
|
13
14
|
default_executable:
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
@@ -23,7 +24,7 @@ dependencies:
|
|
23
24
|
version: 2.1.2
|
24
25
|
version:
|
25
26
|
description: RSolr is a Ruby gem for working with Apache Solr!
|
26
|
-
email:
|
27
|
+
email: mpdwan@gmail.com
|
27
28
|
executables: []
|
28
29
|
|
29
30
|
extensions: []
|
@@ -37,7 +38,9 @@ files:
|
|
37
38
|
- examples/http.rb
|
38
39
|
- examples/direct.rb
|
39
40
|
- lib/core_ext.rb
|
40
|
-
- lib/
|
41
|
+
- lib/core_ext/hash.rb
|
42
|
+
- lib/core_ext/array.rb
|
43
|
+
- lib/core_ext/object.rb
|
41
44
|
- lib/rsolr.rb
|
42
45
|
- lib/rsolr/adapter/common_methods.rb
|
43
46
|
- lib/rsolr/adapter/direct.rb
|
@@ -55,7 +58,7 @@ files:
|
|
55
58
|
- rsolr-ruby.gemspec
|
56
59
|
- CHANGES.txt
|
57
60
|
has_rdoc: true
|
58
|
-
homepage: http://github.com/
|
61
|
+
homepage: http://github.com/mdwan/rsolr
|
59
62
|
post_install_message:
|
60
63
|
rdoc_options: []
|
61
64
|
|
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
|