Class: Dam::TemplatedStream

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

Overview

a templated stream is one which contains placeholders, and thus will only be defined through his instances

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, definition) ⇒ TemplatedStream

Returns a new instance of TemplatedStream.



47
48
49
50
51
52
53
54
# File 'lib/dam/stream.rb', line 47

def initialize(name, definition)
  @name = name
  @definition = definition
  
  extract_placeholders!
  make_glob_pattern!
  make_regexp!
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



45
46
47
# File 'lib/dam/stream.rb', line 45

def name
  @name
end

Instance Method Details

#apply(params) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/dam/stream.rb', line 56

def apply(params)
  if params.is_a? String
    name = params
    params = extract_params(name)
  else
    name = replace_placeholders(params)
  end
  Stream.new(name, @definition, :params => params)
end

#instancesObject



66
67
68
69
# File 'lib/dam/stream.rb', line 66

def instances
  elems = Dam::Storage.database.keys("stream:" + @glob_pattern)
  elems.collect {|elem| apply(elem) }
end

#matches?(what) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/dam/stream.rb', line 71

def matches? what
  what =~ @regexp
end