Class: Dam::Stream
- Inherits:
-
Object
- Object
- Dam::Stream
- Defined in:
- lib/dam/stream.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .[](name) ⇒ Object
- .all ⇒ Object
- .has_placeholder?(string) ⇒ Boolean
- .lookup(name) ⇒ Object
- .register(name, stream) ⇒ Object
Instance Method Summary collapse
- #all ⇒ Object
- #filters ⇒ Object
- #first ⇒ Object
-
#initialize(name, definition, params = {}) ⇒ Stream
constructor
A new instance of Stream.
- #instantiate! ⇒ Object
- #limit ⇒ Object
- #matches?(activity) ⇒ Boolean
Constructor Details
#initialize(name, definition, params = {}) ⇒ Stream
Returns a new instance of Stream.
139 140 141 142 143 |
# File 'lib/dam/stream.rb', line 139 def initialize(name, definition, params = {}) @name = name @definition = definition @params = params.delete(:params) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
137 138 139 |
# File 'lib/dam/stream.rb', line 137 def name @name end |
Class Method Details
.[](name) ⇒ Object
118 119 120 |
# File 'lib/dam/stream.rb', line 118 def Stream.[](name) lookup(name) end |
.all ⇒ Object
132 133 134 |
# File 'lib/dam/stream.rb', line 132 def Stream.all @streams.values.collect {|stream| stream.respond_to?(:instances) ? stream.instances : stream }.flatten end |
.has_placeholder?(string) ⇒ Boolean
128 129 130 |
# File 'lib/dam/stream.rb', line 128 def Stream.has_placeholder? string string =~ PLACEHOLDER_PATTERN end |
.lookup(name) ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/dam/stream.rb', line 108 def Stream.lookup(name) @streams ||= {} if @streams.has_key? name @streams[name] else template = @streams.values.find {|stream| stream.respond_to?(:instances) && stream.matches?(name) } template.apply(name) if template end end |
.register(name, stream) ⇒ Object
122 123 124 125 126 |
# File 'lib/dam/stream.rb', line 122 def Stream.register(name, stream) @streams ||= {} @streams[name] = stream stream end |
Instance Method Details
#all ⇒ Object
153 154 155 156 157 |
# File 'lib/dam/stream.rb', line 153 def all Dam::Storage.get(self.name).collect do |json| Activity.from_json json end end |
#filters ⇒ Object
149 150 151 |
# File 'lib/dam/stream.rb', line 149 def filters @definition.filters end |
#first ⇒ Object
159 160 161 |
# File 'lib/dam/stream.rb', line 159 def first Activity.from_json(Dam::Storage.head(self.name)) end |
#instantiate! ⇒ Object
173 174 175 176 |
# File 'lib/dam/stream.rb', line 173 def instantiate! ensure_exists! self end |
#limit ⇒ Object
145 146 147 |
# File 'lib/dam/stream.rb', line 145 def limit @definition.limit end |
#matches?(activity) ⇒ Boolean
163 164 165 166 167 168 169 170 171 |
# File 'lib/dam/stream.rb', line 163 def matches? activity filters.any? do |filter| return true if filter == :all filter.any? do |key, value| attr_match(value, activity.attributes[key.to_s]) end end end |