Class: Nomo::Page
- Inherits:
-
Object
- Object
- Nomo::Page
- Defined in:
- lib/nomo/page.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #cache_key ⇒ Object
-
#initialize(record, name, options = {}) ⇒ Page
constructor
A new instance of Page.
- #key ⇒ Object
- #last_modified ⇒ Object
- #modify(options = {}) ⇒ Object
- #realtime? ⇒ Boolean
Constructor Details
#initialize(record, name, options = {}) ⇒ Page
Returns a new instance of Page.
5 6 7 8 9 |
# File 'lib/nomo/page.rb', line 5 def initialize(record, name, = {}) @record = record @name = name @options = end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/nomo/page.rb', line 3 def name @name end |
Instance Method Details
#cache_key ⇒ Object
29 30 31 |
# File 'lib/nomo/page.rb', line 29 def cache_key "#{key}/#{last_modified.to_f}" end |
#key ⇒ Object
33 34 35 36 37 38 |
# File 'lib/nomo/page.rb', line 33 def key model = @record.class.model_name.cache_key id = @record.id "#{model}/#{id}/#{name}" end |
#last_modified ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/nomo/page.rb', line 11 def last_modified if @last_modified.nil? && redis_last_modified = redis.get(key) @last_modified = Time.at(redis_last_modified.to_f).utc elsif @last_modified.nil? modify(publish: false) end @last_modified end |
#modify(options = {}) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/nomo/page.rb', line 21 def modify( = {}) @last_modified = Time.now.utc Nomo.logger.debug("(nomo) #{key} modified by #{([:modified_by] || @record).class.model_name.cache_key}/#{@record.id}") redis.set(key, last_modified.to_f) Nomo.publish("updates", key) unless [:publish].eql?(false) || !realtime? end |
#realtime? ⇒ Boolean
40 41 42 |
# File 'lib/nomo/page.rb', line 40 def realtime? @options.has_key?(:realtime) ? @options[:realtime] : true end |