Sha256: e5bac38747174a598e89868cd3f40c0f34f6131b6c6ccef029a33ab9accd45b0

Contents?: true

Size: 477 Bytes

Versions: 3

Compression:

Stored size: 477 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].cookie_jar.jar.any?
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-hackernews-1.1.0 lib/ruby-hackernews/services/mechanize_context.rb
ruby-hackernews-1.0.1 lib/ruby-hackernews/services/mechanize_context.rb
ruby-hackernews-1.0.0 lib/HNAPI/services/mechanize_context.rb