Class: Hammerspace::Hash
- Inherits:
-
Object
- Object
- Hammerspace::Hash
- Extended by:
- Forwardable
- Defined in:
- lib/hammerspace/hash.rb
Overview
“Frontend” class
All hammerspace functionality is exposed through this class’s interface. Responsible for setting up the backend and delegating methods to the backend. Also handles default values. This functionality is designed to be consistent across backends; backends cannot be override this functionality.
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :backend => Hammerspace::Backend::Sparkey }
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#default_proc ⇒ Object
Returns the value of attribute default_proc.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #default(*args) ⇒ Object
- #default=(value) ⇒ Object
-
#initialize(path, options = {}, *args, &block) ⇒ Hash
constructor
A new instance of Hash.
Constructor Details
#initialize(path, options = {}, *args, &block) ⇒ Hash
Returns a new instance of Hash.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hammerspace/hash.rb', line 27 def initialize(path, ={}, *args, &block) raise ArgumentError, "wrong number of arguments" if args.size > 1 @path = path @options = DEFAULT_OPTIONS.merge() @backend = @options[:backend].new(self, @path, @options) if block_given? self.default_proc=(block) raise ArgumentError, "wrong number of arguments" if args.size == 1 else self.default=args.first end end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
16 17 18 |
# File 'lib/hammerspace/hash.rb', line 16 def backend @backend end |
#default_proc ⇒ Object
Returns the value of attribute default_proc.
17 18 19 |
# File 'lib/hammerspace/hash.rb', line 17 def default_proc @default_proc end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/hammerspace/hash.rb', line 15 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/hammerspace/hash.rb', line 14 def path @path end |
Instance Method Details
#default(*args) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/hammerspace/hash.rb', line 42 def default(*args) if @default_proc && args.size @default_proc.call(self, args.first) else @default end end |
#default=(value) ⇒ Object
50 51 52 53 |
# File 'lib/hammerspace/hash.rb', line 50 def default=(value) @default_proc = nil @default = value end |