Class: BrowsingHistory::History
- Inherits:
-
Object
- Object
- BrowsingHistory::History
- 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
-
#browser ⇒ Object
Returns the value of attribute browser.
-
#expiration ⇒ Object
Returns the value of attribute expiration.
-
#historizable ⇒ Object
Returns the value of attribute historizable.
Class Method Summary collapse
- .count(browser: nil, historizable: nil) ⇒ Object
- .create(attributes = {}) ⇒ Object
- .create!(attributes = {}) ⇒ Object
- .where(browser: nil, historizable: nil, **opts) ⇒ Object
Instance Method Summary collapse
-
#initialize(browser: nil, historizable: nil) ⇒ History
constructor
A new instance of History.
- #save ⇒ Object
- #save! ⇒ Object
Methods included from Storage
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
#browser ⇒ Object
Returns the value of attribute browser.
13 14 15 |
# File 'lib/browsing_history/history.rb', line 13 def browser @browser end |
#expiration ⇒ Object
Returns the value of attribute expiration.
13 14 15 |
# File 'lib/browsing_history/history.rb', line 13 def expiration @expiration end |
#historizable ⇒ Object
Returns the value of attribute historizable.
13 14 15 |
# File 'lib/browsing_history/history.rb', line 13 def historizable @historizable end |
Class Method Details
.count(browser: nil, historizable: nil) ⇒ Object
52 53 54 55 |
# 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
#save ⇒ Object
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 |