Class: HashPipe::ArchivedAttribute
- Inherits:
-
Object
- Object
- HashPipe::ArchivedAttribute
- Defined in:
- lib/hashpipe/archived_attribute.rb
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#scope ⇒ Object
Returns the value of attribute scope.
Instance Method Summary collapse
- #destroy ⇒ Object
- #dirty? ⇒ Boolean
-
#initialize(name, scope, backend, opts = {}) ⇒ ArchivedAttribute
constructor
A new instance of ArchivedAttribute.
- #key ⇒ Object
- #options ⇒ Object
- #save ⇒ Object
- #value ⇒ Object
- #value=(other) ⇒ Object
Constructor Details
#initialize(name, scope, backend, opts = {}) ⇒ ArchivedAttribute
Returns a new instance of ArchivedAttribute.
10 11 12 13 14 15 16 |
# File 'lib/hashpipe/archived_attribute.rb', line 10 def initialize(name, scope, backend, opts = {}) @name = name @scope = scope @dirty = false @options = HashPipe::GlobalConfiguration.instance.to_hash.merge(opts) @backend = backend end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
7 8 9 |
# File 'lib/hashpipe/archived_attribute.rb', line 7 def backend @backend end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/hashpipe/archived_attribute.rb', line 7 def name @name end |
#scope ⇒ Object
Returns the value of attribute scope.
8 9 10 |
# File 'lib/hashpipe/archived_attribute.rb', line 8 def scope @scope end |
Instance Method Details
#destroy ⇒ Object
40 41 42 |
# File 'lib/hashpipe/archived_attribute.rb', line 40 def destroy backend.delete(key) end |
#dirty? ⇒ Boolean
31 32 33 |
# File 'lib/hashpipe/archived_attribute.rb', line 31 def dirty? @dirty end |
#key ⇒ Object
48 49 50 |
# File 'lib/hashpipe/archived_attribute.rb', line 48 def key [scope, name].join('_') end |
#options ⇒ Object
44 45 46 |
# File 'lib/hashpipe/archived_attribute.rb', line 44 def @options end |
#save ⇒ Object
35 36 37 38 |
# File 'lib/hashpipe/archived_attribute.rb', line 35 def save backend[key] = @stashed_value if self.dirty? @dirty = false end |
#value ⇒ Object
18 19 20 21 22 |
# File 'lib/hashpipe/archived_attribute.rb', line 18 def value val = defined?(@stashed_value) ? @stashed_value : backend[key] val = compress? && !val.nil? ? Zlib::Inflate.inflate(val) : val val = marshal? ? Marshal.load(val) : val end |
#value=(other) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/hashpipe/archived_attribute.rb', line 24 def value=(other) other = marshal? ? Marshal.dump(other) : other other = compress? && !other.nil? ? Zlib::Deflate.deflate(other) : other @stashed_value = other @dirty = true end |