Module: RubyHackernews::MechanizeContext
- Included in:
- CommentService, EntryService, LoginService, PageFetcher, SignupService, TextService, UserInfoService, VotingService
- Defined in:
- lib/ruby-hackernews/services/mechanize_context.rb
Constant Summary collapse
- @@contexts =
{}
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #agent ⇒ Object
- #authenticated?(key = :default) ⇒ Boolean
- #require_authentication ⇒ Object
Class Method Details
.agent=(key) ⇒ Object
7 8 9 |
# File 'lib/ruby-hackernews/services/mechanize_context.rb', line 7 def self.agent=(key) @@default = key end |
Instance Method Details
#[](key) ⇒ Object
17 18 19 |
# File 'lib/ruby-hackernews/services/mechanize_context.rb', line 17 def [](key) return @@contexts[key] end |
#agent ⇒ Object
11 12 13 14 15 |
# File 'lib/ruby-hackernews/services/mechanize_context.rb', line 11 def agent @@default ||= :default @@contexts[@@default] = Mechanize.new unless @@contexts[@@default] return @@contexts[@@default] end |
#authenticated?(key = :default) ⇒ Boolean
25 26 27 |
# File 'lib/ruby-hackernews/services/mechanize_context.rb', line 25 def authenticated?(key = :default) return @@contexts[key] && @@contexts[key]..jar.any? end |
#require_authentication ⇒ Object
21 22 23 |
# File 'lib/ruby-hackernews/services/mechanize_context.rb', line 21 def require_authentication raise NotAuthenticatedError unless authenticated? end |