Class: BrowsingHistory::History

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Callbacks
Includes:
ActiveModel::Model, ActiveModel::Validations, Storage
Defined in:
lib/browsing_history/history.rb

Defined Under Namespace

Classes: ArgumentError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Storage

included

Constructor Details

#initialize(browser: nil, historizable: nil) ⇒ History

Returns a new instance of History.



21
22
23
24
# File 'lib/browsing_history/history.rb', line 21

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

Instance Attribute Details

#browserObject

Returns the value of attribute browser.



13
14
15
# File 'lib/browsing_history/history.rb', line 13

def browser
  @browser
end

#expirationObject

Returns the value of attribute expiration.



13
14
15
# File 'lib/browsing_history/history.rb', line 13

def expiration
  @expiration
end

#historizableObject

Returns the value of attribute historizable.



13
14
15
# File 'lib/browsing_history/history.rb', line 13

def historizable
  @historizable
end

Class Method Details

.clear(browser: nil, historizable: nil, **opts) ⇒ Object



58
59
60
61
62
# File 'lib/browsing_history/history.rb', line 58

def clear(browser: nil, historizable: nil, **opts)
  return 0 if !browser && !historizable

  current_storage.clear(browser, historizable, **opts)
end

.count(browser: nil, historizable: nil) ⇒ Object



52
53
54
55
56
# File 'lib/browsing_history/history.rb', line 52

def count(browser: nil, historizable: nil)
  return 0 if !browser && !historizable

  current_storage.count(browser, historizable)
end

.create(attributes = {}) ⇒ Object



35
36
37
38
# File 'lib/browsing_history/history.rb', line 35

def create(attributes = {})
  instance = new(**attributes)
  instance.save ? instance : false
end

.create!(attributes = {}) ⇒ Object



40
41
42
43
44
# File 'lib/browsing_history/history.rb', line 40

def create!(attributes = {})
  instance = new(**attributes)
  instance.save!
  instance
end

.where(browser: nil, historizable: nil, **opts) ⇒ Object



46
47
48
49
50
# File 'lib/browsing_history/history.rb', line 46

def where(browser: nil, historizable: nil, **opts)
  return [] if !browser && !historizable

  current_storage.fetch(browser, historizable, opts)
end

Instance Method Details

#saveObject



26
27
28
# File 'lib/browsing_history/history.rb', line 26

def save
  valid? ? run_callbacks(:save) { true } : false
end

#save!Object



30
31
32
# File 'lib/browsing_history/history.rb', line 30

def save!
  valid? ? run_callbacks(:save) { true } : raise_errors
end