Module: Charty::Backends

Defined in:
lib/charty/backends.rb,
lib/charty/backends/bokeh.rb,
lib/charty/backends/gruff.rb,
lib/charty/backends/plotly.rb,
lib/charty/backends/pyplot.rb,
lib/charty/backends/rubyplot.rb,
lib/charty/backends/unicode_plot.rb,
lib/charty/backends/google_charts.rb,
lib/charty/backends/plotly_helpers/html_renderer.rb,
lib/charty/backends/plotly_helpers/plotly_renderer.rb,
lib/charty/backends/plotly_helpers/notebook_renderer.rb

Defined Under Namespace

Modules: PlotlyHelpers Classes: Bokeh, GoogleCharts, Gruff, Plotly, Pyplot, Rubyplot, UnicodePlot

Class Method Summary collapse

Class Method Details

.currentObject



11
12
13
# File 'lib/charty/backends.rb', line 11

def self.current
  @current
end

.current=(backend_name) ⇒ Object



15
16
17
18
# File 'lib/charty/backends.rb', line 15

def self.current=(backend_name)
  backend_class = Backends.find_backend_class(backend_name)
  @current = backend_class.new
end

.find_backend_class(name) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/charty/backends.rb', line 44

def self.find_backend_class(name)
  backend = @backends[normalize_name(name)]
  unless backend
    raise BackendNotFoundError, "Backend is not found: #{name.inspect}"
  end
  backend_class = backend[:class]
  unless backend[:prepared]
    if backend_class.respond_to?(:prepare)
      begin
        backend_class.prepare
      rescue LoadError
        raise BackendLoadError, "Backend load error: #{name.inspect}"
      end
    end
    backend[:prepared] = true
  end
  backend_class
end

.namesObject



33
34
35
# File 'lib/charty/backends.rb', line 33

def self.names
  @backends.keys
end

.register(name, backend_class) ⇒ Object



37
38
39
40
41
42
# File 'lib/charty/backends.rb', line 37

def self.register(name, backend_class)
  @backends[normalize_name(name)] = {
    class: backend_class,
    prepared: false,
  }
end

.use(backend) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/charty/backends.rb', line 20

def self.use(backend)
  if block_given?
    begin
      saved, self.current = self.current, backend
      yield
    ensure
      self.current = saved
    end
  else
    self.current = backend
  end
end