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

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_sourcesObject

Returns all activated smoke sources



73
# File 'lib/smoke.rb', line 73

def active_sources; @@active_sources; end

.concealed_sourcesObject

Returns all concealed sources



81
82
83
# File 'lib/smoke.rb', line 81

def concealed_sources
  active_sources.reject{|k,v| !v.concealed? }
end

.configObject

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

Yields:



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_sourcesObject

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

.logObject

Log for info, debug, error and warn with:

Smoke.log.info "message"
Smoke.log.debug "message"
Smoke.log.error "message"
Smoke.log.warn "message"


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")

Raises:



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

.rootObject



30
31
32
# File 'lib/smoke.rb', line 30

def root
  File.join(File.dirname(__FILE__))
end

.versionObject



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

.yql(name, &block) ⇒ Object



122
# File 'lib/smoke.rb', line 122

def yql(name, &block);  Smoke::YQL.new(name, &block);  end