Sha256: 1d7f84c4bf6c9fc5fde50d5d30194012880499324310d38d3eb33e4a2051aee9

Contents?: true

Size: 495 Bytes

Versions: 3

Compression:

Stored size: 495 Bytes

Contents

module MechanizeContext

  @@contexts = {}

  def self.agent=(key)
    @@default = key
  end

  def agent
    @@default ||= :default
    @@contexts[@@default] = Mechanize.new unless @@contexts[@@default]
    return @@contexts[@@default]
  end

  def [](key)
    return @@contexts[key]
  end

  def require_authentication
    raise NotAuthenticatedError unless authenticated?
  end

  def authenticated?(key = :default)
    return @@contexts[key] && @@contexts[key].cookie_jar.jar.any?
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-hackernews-1.1.3 lib/ruby-hackernews/services/mechanize_context.rb
ruby-hackernews-1.1.2 lib/ruby-hackernews/services/mechanize_context.rb
ruby-hackernews-1.1.1 lib/ruby-hackernews/services/mechanize_context.rb