Class: BrowsingHistory::Storages::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/browsing_history/storages/base.rb

Direct Known Subclasses

ActiveRecord, Redis

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(browser, historizable) ⇒ Base

Returns a new instance of Base.



9
10
11
12
# File 'lib/browsing_history/storages/base.rb', line 9

def initialize(browser, historizable)
  @browser      = browser
  @historizable = historizable
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/browsing_history/storages/base.rb', line 14

def method_missing(method, *args)
  if method.in?(IOMethods)
    raise NotOverideError
  else
    super
  end
end

Instance Attribute Details

#browserObject

Returns the value of attribute browser.



7
8
9
# File 'lib/browsing_history/storages/base.rb', line 7

def browser
  @browser
end

#historizableObject

Returns the value of attribute historizable.



7
8
9
# File 'lib/browsing_history/storages/base.rb', line 7

def historizable
  @historizable
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/browsing_history/storages/base.rb', line 7

def options
  @options
end

Class Method Details

.connectObject



23
24
25
26
27
28
29
30
# File 'lib/browsing_history/storages/base.rb', line 23

def connect
  IOMethods.each do |method|
    define_singleton_method(method) do |browser, historizable, *_args|
      opts = _args.dup.extract_options!.merge(default_options)
      new(browser, historizable).send(method, **opts)
    end
  end
end

.default_optionsObject



32
33
34
# File 'lib/browsing_history/storages/base.rb', line 32

def default_options
  {}
end