Class: Gon

Inherits:
Object
  • Object
show all
Defined in:
lib/gon.rb,
lib/gon/base.rb,
lib/gon/rabl.rb,
lib/gon/watch.rb,
lib/gon/global.rb,
lib/gon/escaper.rb,
lib/gon/helpers.rb,
lib/gon/request.rb,
lib/gon/version.rb,
lib/gon/jbuilder.rb

Direct Known Subclasses

Global, Watch

Defined Under Namespace

Modules: Base, Escaper, GonHelpers, Helpers, Jbuilder, Rabl, Request Classes: Global, Watch

Constant Summary collapse

VERSION =
'4.1.1'

Class Method Summary collapse

Class Method Details

.all_variablesObject



51
52
53
# File 'lib/gon.rb', line 51

def all_variables
  Request.gon
end

.clearObject



55
56
57
# File 'lib/gon.rb', line 55

def clear
  Request.clear
end

.get_variable(name) ⇒ Object



35
36
37
# File 'lib/gon.rb', line 35

def get_variable(name)
  Request.gon[name]
end

.globalObject



15
16
17
# File 'lib/gon.rb', line 15

def global
  Gon::Global
end

.inspectObject



70
71
72
# File 'lib/gon.rb', line 70

def inspect
  'Gon'
end

.jbuilder(*args) ⇒ Object



64
65
66
67
68
# File 'lib/gon.rb', line 64

def jbuilder(*args)
  ensure_template_handler_is_defined
  data, options = Gon::Jbuilder.handler(args)
  store_builder_data 'jbuilder', data, options
end

.method_missing(method, *args, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gon.rb', line 23

def method_missing(method, *args, &block)
  if ( method.to_s =~ /=$/ )
    if public_method_name? method
      raise "You can't use Gon public methods for storing data"
    end

    set_variable(method.to_s.delete('='), args[0])
  else
    get_variable(method.to_s)
  end
end

.push(data = {}) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/gon.rb', line 43

def push(data = {})
  raise "Object must have each_pair method" unless data.respond_to? :each_pair

  data.each_pair do |name, value|
    set_variable(name.to_s, value)
  end
end

.rabl(*args) ⇒ Object



59
60
61
62
# File 'lib/gon.rb', line 59

def rabl(*args)
  data, options = Gon::Rabl.handler(args)
  store_builder_data 'rabl', data, options
end

.set_variable(name, value) ⇒ Object



39
40
41
# File 'lib/gon.rb', line 39

def set_variable(name, value)
  Request.gon[name] = value
end

.watchObject



19
20
21
# File 'lib/gon.rb', line 19

def watch
  Gon::Watch
end