Class: N::App::Fragment

Inherits:
Object
  • Object
show all
Includes:
Expirable, LRUCache::Item
Defined in:
lib/n/app/fragment.rb

Constant Summary collapse

ADMIN_FLAG =

precompiled flags for fragment key “customization”

"-a"
OWNER_FLAG =
"-o"
EDITOR_FLAG =
"-e"
VIEWER_FLAG =
"-f"
MY_FLAG =
"-m"
ANONYMOUS_FLAG =
"-n"

Instance Attribute Summary collapse

Attributes included from LRUCache::Item

#lru_key, #lru_next, #lru_prev

Instance Method Summary collapse

Methods included from Expirable

#expires_after, #expires_spread

Constructor Details

#initialize(body = "", lm = Time.now) ⇒ Fragment

Returns a new instance of Fragment.



49
50
51
52
# File 'lib/n/app/fragment.rb', line 49

def initialize(body = "", lm = Time.now)
	@body = body
	@lm = lm
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



42
43
44
# File 'lib/n/app/fragment.rb', line 42

def body
  @body
end

#expiresObject

another method for invalidation, allows for more flexible invalidation strategies. also used by the legacy autoinvalidate code.



47
48
49
# File 'lib/n/app/fragment.rb', line 47

def expires
  @expires
end

#lmObject

Returns the value of attribute lm.



42
43
44
# File 'lib/n/app/fragment.rb', line 42

def lm
  @lm
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/n/app/fragment.rb', line 58

def expired?
	return true if @expires.nil? || (Time.now > @expires)
end

#expires_after!(ea = (60*60*24)) ⇒ Object



54
55
56
# File 'lib/n/app/fragment.rb', line 54

def expires_after!(ea = (60*60*24))
	@expires = @lm + ea
end

#to_strObject



62
63
64
# File 'lib/n/app/fragment.rb', line 62

def to_str
	return @body
end