Class: Hammerspace::Hash

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}, *args, &block) ⇒ Hash

Returns a new instance of Hash.

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/hammerspace/hash.rb', line 27

def initialize(path, options={}, *args, &block)
  raise ArgumentError, "wrong number of arguments" if args.size > 1

  @path    = path
  @options = DEFAULT_OPTIONS.merge(options)
  @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

#backendObject (readonly)

Returns the value of attribute backend.



16
17
18
# File 'lib/hammerspace/hash.rb', line 16

def backend
  @backend
end

#default_procObject

Returns the value of attribute default_proc.



17
18
19
# File 'lib/hammerspace/hash.rb', line 17

def default_proc
  @default_proc
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/hammerspace/hash.rb', line 15

def options
  @options
end

#pathObject (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