Module: Smoke
- Defined in:
- lib/smoke.rb,
lib/smoke/cache.rb,
lib/smoke/origin.rb,
lib/smoke/request.rb,
lib/smoke/source/csv.rb,
lib/smoke/source/yql.rb,
lib/smoke/source/data.rb,
lib/smoke/source/feed.rb,
lib/smoke/source/join.rb,
lib/smoke/transformer.rb,
lib/smoke/transformers/xml.rb,
lib/smoke/transformers/json.rb,
lib/smoke/transformers/ruby.rb,
lib/smoke/transformers/yaml.rb
Defined Under Namespace
Modules: Transformers Classes: CSV, Cache, Data, Feed, Join, NotRegistered, Origin, Request, Transformer, YQL
Constant Summary collapse
- @@active_sources =
{}
- @@config =
{ :enable_logging => true, :user_agent => "Ruby/#{RUBY_VERSION}/Smoke", :cache => { :enabled => false, :store => :memory, :options => {}, :expiry => 1800 } }
Class Method Summary collapse
-
.[](source) ⇒ Object
Access registered smoke source instances.
-
.activate(name, source) ⇒ Object
Activates new instances of sources Source instances are stored within the @@active_sources class variable for later use.
-
.active_sources ⇒ Object
Returns all activated smoke sources.
-
.concealed_sources ⇒ Object
Returns all concealed sources.
-
.config ⇒ Object
Access configuration options.
-
.configure {|@@config| ... } ⇒ Object
Set any configurable options.
- .csv(name, &block) ⇒ Object
- .data(name, &block) ⇒ Object
-
.exposed_sources ⇒ Object
Returns all exposed sources.
- .feed(name, &block) ⇒ Object
-
.join(*names, &block) ⇒ Object
Join multiple sources together into a single feed Usage: Smoke.join(:delicious, :twitter, :flickr) do name :stream path :photos, :photo end.
-
.log ⇒ Object
Log for info, debug, error and warn with:.
-
.method_missing(sym, args = {}) ⇒ Object
Access registered smoke source instances.
-
.rename(candidates) ⇒ Object
Rename a source.
- .root ⇒ Object
- .version ⇒ Object
- .yql(name, &block) ⇒ Object
Class Method Details
.[](source) ⇒ Object
Access registered smoke source instances
Define your source:
Smoke.yql(:ruby) do ....
Then access it:
Smoke[:ruby]
=> #<Smoke::YQL::0x18428d4...
46 47 48 |
# File 'lib/smoke.rb', line 46 def [](source) active_sources[source] end |
.activate(name, source) ⇒ Object
Activates new instances of sources Source instances are stored within the @@active_sources class variable for later use
65 66 67 68 69 70 |
# File 'lib/smoke.rb', line 65 def activate(name, source) if active_sources.key?(name) Smoke.log.warn "Smoke source activation: Source with identical name already initialized" end active_sources.update({ name => source }) end |
.active_sources ⇒ Object
Returns all activated smoke sources
73 |
# File 'lib/smoke.rb', line 73 def active_sources; @@active_sources; end |
.concealed_sources ⇒ Object
Returns all concealed sources
81 82 83 |
# File 'lib/smoke.rb', line 81 def concealed_sources active_sources.reject{|k,v| !v.concealed? } end |
.config ⇒ Object
Access configuration options
Smoke.config[:option_name]
=> true
118 119 120 |
# File 'lib/smoke.rb', line 118 def config @@config end |
.configure {|@@config| ... } ⇒ Object
Set any configurable options
Smoke.configure do |c|
c[:user_agent] = "Some other site"
end
110 111 112 |
# File 'lib/smoke.rb', line 110 def configure(&block) yield @@config end |
.csv(name, &block) ⇒ Object
125 |
# File 'lib/smoke.rb', line 125 def csv(name, &block); Smoke::CSV.new(name, &block); end |
.data(name, &block) ⇒ Object
123 |
# File 'lib/smoke.rb', line 123 def data(name, &block); Smoke::Data.new(name, &block); end |
.exposed_sources ⇒ Object
Returns all exposed sources
76 77 78 |
# File 'lib/smoke.rb', line 76 def exposed_sources active_sources.reject{|k,v| !v.exposed? } end |
.feed(name, &block) ⇒ Object
124 |
# File 'lib/smoke.rb', line 124 def feed(name, &block); Smoke::Feed.new(name, &block); end |
.join(*names, &block) ⇒ Object
Join multiple sources together into a single feed Usage:
Smoke.join(:delicious, :twitter, :flickr) do
name :stream
path :photos, :photo
end
133 |
# File 'lib/smoke.rb', line 133 def join(*names, &block); Smoke::Join.new(names, &block); end |
.log ⇒ Object
100 101 102 |
# File 'lib/smoke.rb', line 100 def log @@log ||= Logger.new(config[:enable_logging] ? $stdout : "/dev/null") end |
.method_missing(sym, args = {}) ⇒ Object
Access registered smoke source instances
Arguments can be sent as key/value pairs to inject abstract properties: Usage:
Smoke.twitter(:username => "benschwarz")
55 56 57 58 59 60 |
# File 'lib/smoke.rb', line 55 def method_missing(sym, args = {}) raise NotRegistered, "Smoke source not registered" if self[sym].nil? args.each_pair {|k, v| self[sym].send(k, v) } self[sym] end |
.rename(candidates) ⇒ Object
Rename a source
86 87 88 89 90 91 92 |
# File 'lib/smoke.rb', line 86 def rename(candidates) candidates.each do |o, n| active_sources[o].name = n.to_s active_sources.rename(o => n) return active_sources[n] end end |
.root ⇒ Object
30 31 32 |
# File 'lib/smoke.rb', line 30 def root File.join(File.dirname(__FILE__)) end |
.version ⇒ Object
34 35 36 37 |
# File 'lib/smoke.rb', line 34 def version @@version ||= YAML::load(File.read("#{root}/../VERSION.YML")) "#{@@version[:major]}.#{@@version[:minor]}.#{@@version[:patch]}" end |