Class: GDK::Templates::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/gdk/templates/context.rb

Overview

Context to which a template is run

This includes all available helper methods and data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**locals) ⇒ Context

Returns a new instance of Context.



11
12
13
# File 'lib/gdk/templates/context.rb', line 11

def initialize(**locals)
  @locals = locals
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object (private)



42
43
44
45
46
# File 'lib/gdk/templates/context.rb', line 42

def method_missing(method_name)
  return locals[method_name] if locals.include?(method_name)

  super
end

Instance Attribute Details

#localsObject (readonly)

Returns the value of attribute locals.



9
10
11
# File 'lib/gdk/templates/context.rb', line 9

def locals
  @locals
end

Instance Method Details

#configGDK::Config

Return config data structure

Returns:



25
26
27
# File 'lib/gdk/templates/context.rb', line 25

def config
  GDK.config
end

#context_bindingsObject



36
37
38
# File 'lib/gdk/templates/context.rb', line 36

def context_bindings
  binding
end

#gdk_rootString

Return path to GDK root directory

Returns:

  • (String)

    root path



18
19
20
# File 'lib/gdk/templates/context.rb', line 18

def gdk_root
  GDK.root
end

#service(name) ⇒ GDK::Services::Base|nil

Returns an instance of the service that matches the given name

Returns:



32
33
34
# File 'lib/gdk/templates/context.rb', line 32

def service(name)
  GDK::Services.fetch(name) || raise("No service named #{name} found")
end