Permalink
Browse files

Remove Array(arbitrary_string) calls

In Ruby 1.8, calling Array() on a string splits on newlines.  Yuck!
  • Loading branch information...
1 parent 86dc24c commit 651e14b5b4668a7808cfe98a5b98ef6fa241ffef @tpope committed Feb 1, 2011
Showing with 4 additions and 4 deletions.
  1. +1 −1 lib/ldaptic/attribute_set.rb
  2. +1 −1 lib/ldaptic/entry.rb
  3. +2 −2 lib/ldaptic/methods.rb
@@ -297,7 +297,7 @@ def matchable(value)
end
def safe_array(attributes)
- Array(attributes).flatten.compact.map {|x| format(x)}
+ [attributes].flatten.compact.map {|x| format(x)}
end
def typecast(value)
@@ -151,7 +151,7 @@ def instantiate(attributes) #:nodoc:
logger.warn "#{name}: invalid object class for #{attributes.inspect}"
end
obj = allocate
- obj.instance_variable_set(:@dn, ::Ldaptic::DN(Array(attributes.delete('dn')).first, obj))
+ obj.instance_variable_set(:@dn, ::Ldaptic::DN([attributes.delete('dn')].flatten.first, obj))
obj.instance_variable_set(:@original_attributes, attributes)
obj.instance_variable_set(:@attributes, {})
obj.instance_eval { common_initializations; after_load }
@@ -242,7 +242,7 @@ def search(options = {}, &block)
def normalize_attributes(attributes)
attributes.inject({}) do |h, (k, v)|
- h.update(Ldaptic.encode(k) => v.respond_to?(:before_type_cast) ? v.before_type_cast : Array(v))
+ h.update(Ldaptic.encode(k) => v.respond_to?(:before_type_cast) ? v.before_type_cast : [v].flatten.compact)
end
end
private :normalize_attributes
@@ -260,7 +260,7 @@ def modify(dn, attributes)
attributes = normalize_attributes(attributes)
else
attributes = attributes.map do |(action, key, values)|
- [action, Ldaptic.encode(key), values.respond_to?(:before_type_cast) ? values.before_type_cast : Array(values)]
+ [action, Ldaptic.encode(key), values.respond_to?(:before_type_cast) ? values.before_type_cast : [values].flatten.compact]
end
end
log_dispatch(:modify, dn, attributes)

0 comments on commit 651e14b

Please sign in to comment.