Class: BlackBoard

Inherits:
Object
  • Object
show all
Defined in:
lib/blackboard.rb

Defined Under Namespace

Classes: Data, Folder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}, &block) ⇒ BlackBoard

Returns a new instance of BlackBoard.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
# File 'lib/blackboard.rb', line 11

def initialize opts = {}, &block
  @folders = {}
  @ttl = opts[:ttl] || 60
  raise ArgumentError, "BlackBoard.new should not receive ttl bigger than #seconds in 30 days" if @ttl > 2592000
  @store = opts[:store] || Moneta::Memcache.new(:server => "127.0.0.1:11411")
  instance_eval(&block) unless block.nil?
  instance_eval "def method_missing folder; raise BlackBoardError, \"Folder \#{folder} not found\"; end"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

Raises:



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/blackboard.rb', line 32

def method_missing name, *args, &block

  raise BlackBoardError, "Folder #{name} already exists" if @folders.has_key?(name)
  instance_eval %Q{def #{name}; @folders[:#{name}]._update; @folders[:#{name}]; end}

  options = args[-1].is_a?(Hash) ? args.delete_at(-1) : {}
  options[:ttl] ||= @ttl
  options[:store] ||= @store

  @folders[name] = Folder.new name, args, options, &block

end

Instance Attribute Details

#foldersObject (readonly)

Returns the value of attribute folders.



9
10
11
# File 'lib/blackboard.rb', line 9

def folders
  @folders
end

Instance Method Details

#clearObject



28
29
30
# File 'lib/blackboard.rb', line 28

def clear
  @store.clear
end

#empty?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/blackboard.rb', line 24

def empty? 
  true
end

#has_folders?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/blackboard.rb', line 20

def has_folders?
  !@folders.empty?
end