Class: Hammerspace::Backend::Base
- Inherits:
-
Object
- Object
- Hammerspace::Backend::Base
- Includes:
- Enumerable, HashMethods
- Defined in:
- lib/hammerspace/backend.rb
Overview
“Backend” class from which concrete backends extend
Mixes in Enumerable and HashMethods to provide default implementations of most methods that Ruby’s hash supports. Also provides some basic file and lock handling methods common to backends.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#frontend ⇒ Object
readonly
Returns the value of attribute frontend.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #check_fs ⇒ Object
-
#close ⇒ Object
HashMethods (mixed in above) defines four methods that must be overridden.
- #flock_works? ⇒ Boolean
-
#initialize(frontend, path, options = {}) ⇒ Base
constructor
A new instance of Base.
- #uid ⇒ Object
Methods included from HashMethods
#==, #[], #[]=, #assoc, #clear, #delete, #delete_if, #each, #each_key, #each_value, #empty?, #eql?, #fetch, #flatten, #has_key?, #has_value?, #include?, #keep_if, #key, #keys, #member?, #merge!, #rassoc, #reject!, #replace, #select!, #shift, #size, #to_hash, #values, #values_at
Constructor Details
#initialize(frontend, path, options = {}) ⇒ Base
Returns a new instance of Base.
20 21 22 23 24 25 26 |
# File 'lib/hammerspace/backend.rb', line 20 def initialize(frontend, path, ={}) @frontend = frontend @path = path @options = check_fs unless File.exist?(lockfile_path) end |
Instance Attribute Details
#frontend ⇒ Object (readonly)
Returns the value of attribute frontend.
16 17 18 |
# File 'lib/hammerspace/backend.rb', line 16 def frontend @frontend end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
18 19 20 |
# File 'lib/hammerspace/backend.rb', line 18 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
17 18 19 |
# File 'lib/hammerspace/backend.rb', line 17 def path @path end |
Instance Method Details
#check_fs ⇒ Object
40 41 42 |
# File 'lib/hammerspace/backend.rb', line 40 def check_fs warn_flock unless flock_works? end |
#close ⇒ Object
HashMethods (mixed in above) defines four methods that must be overridden. The default implementations simply raise NotImplementedError. The four methods are: [], []=, delete, and each.
32 33 34 |
# File 'lib/hammerspace/backend.rb', line 32 def close # No-op, should probably be overridden end |
#flock_works? ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/hammerspace/backend.rb', line 44 def flock_works? flock_works = false ensure_path_exists(path) lockfile = Tempfile.new(['flock_works.', '.lock'], path) begin lockfile.close File.open(lockfile.path) do |outer| outer.flock(File::LOCK_EX) File.open(lockfile.path) do |inner| flock_works = inner.flock(File::LOCK_EX | File::LOCK_NB) == false end end rescue ensure lockfile.unlink end flock_works end |
#uid ⇒ Object
36 37 38 |
# File 'lib/hammerspace/backend.rb', line 36 def uid # No-op, should probably be overridden end |