Sha256: 33704166a4fd24b7fe86b727a06105569b66ddce4b946dc3851a0e9c31b7e494

Contents?: true

Size: 1.43 KB

Versions: 27

Compression:

Stored size: 1.43 KB

Contents

# these are extensions I've found useful for this project
class String
  # normalizes an OpenID according to http://openid.net/specs/openid-authentication-2_0.html#normalization
  def normalize_identifier
    # clean up whitespace
    identifier = self.dup.strip

    # if an XRI has a prefix, strip it.
    identifier.gsub!(/xri:\/\//i, '')

    # dodge XRIs -- TODO: validate, don't just skip.
    unless ['=', '@', '+', '$', '!', '('].include?(identifier.at(0))
      # does it begin with http?  if not, add it.
      identifier = "http://#{identifier}" unless identifier =~ /^http/i

      # strip any fragments
      identifier.gsub!(/\#(.*)$/, '')

      begin
        uri = URI.parse(identifier)
        uri.scheme = uri.scheme.downcase  # URI should do this
        identifier = uri.normalize.to_s
      rescue URI::InvalidURIError
        raise InvalidOpenId.new("#{identifier} is not an OpenID identifier")
      end
    end

    return identifier
  end
end

class Hash
  def recursively_symbolize_keys!
    self.symbolize_keys!
    self.values.each do |v|
      if v.is_a? Hash
        v.recursively_symbolize_keys!
      elsif v.is_a? Array
        v.recursively_symbolize_keys!
      end
    end
    self
  end
end

class Array
  def recursively_symbolize_keys!
    self.each do |item|
      if item.is_a? Hash
        item.recursively_symbolize_keys!
      elsif item.is_a? Array
        item.recursively_symbolize_keys!
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 8 rubygems

Version Path
robdimarco-authlogic-connect-0.0.6 lib/authlogic_connect/ext.rb
anideo-authlogic-connect-0.0.6 lib/authlogic_connect/ext.rb
jspooner-authlogic-connect-0.0.20 lib/authlogic_connect/ext.rb
jspooner-authlogic-connect-0.0.19 lib/authlogic_connect/ext.rb
foreverman-authlogic-connect-0.0.4 lib/authlogic_connect/ext.rb
foreverman-authlogic-connect-0.0.3 lib/authlogic_connect/ext.rb
foreverman-authlogic-connect-0.0.2 lib/authlogic_connect/ext.rb
foreverman-authlogic-connect-0.0.1 lib/authlogic_connect/ext.rb
foreverman-authlogic-connect-0.0.6 lib/authlogic_connect/ext.rb
authlogic-connect-andrewacove-0.5.7 lib/authlogic_connect/ext.rb
authlogic-connect-0.0.6 lib/authlogic_connect/ext.rb
authlogic-connect-0.0.5.1 lib/authlogic_connect/ext.rb
authlogic-connect-0.0.5 lib/authlogic_connect/ext.rb
authlogic-connect-andrewacove-0.5.6 lib/authlogic_connect/ext.rb
authlogic-connect-andrewacove-0.5.5 lib/authlogic_connect/ext.rb
authlogic-connect-andrewacove-0.5.4 lib/authlogic_connect/ext.rb
authlogic-connect-andrewacove-0.5.2 lib/authlogic_connect/ext.rb
authlogic-connect-andrewacove-0.5.0 lib/authlogic_connect/ext.rb
authlogic-connect-0.0.4.06 lib/authlogic_connect/ext.rb
authlogic-connect-x-0.0.4.05x lib/authlogic_connect/ext.rb