Module: Global::Base

Extended by:
Base
Included in:
Global, Base
Defined in:
lib/global/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (protected)



89
90
91
# File 'lib/global/base.rb', line 89

def method_missing(method, *args, &block)
  configuration.key?(method) ? configuration[method] : super
end

Instance Attribute Details

#config_directoryObject



29
30
31
# File 'lib/global/base.rb', line 29

def config_directory
  @config_directory || raise("config_directory should be defined")
end

#environmentObject



25
26
27
# File 'lib/global/base.rb', line 25

def environment
  @environment || raise("environment should be defined")
end

#exceptObject



37
38
39
# File 'lib/global/base.rb', line 37

def except
  @except ||= :all
end

#namespaceObject



33
34
35
# File 'lib/global/base.rb', line 33

def namespace
  @namespace ||= 'Global'
end

#onlyObject



41
42
43
# File 'lib/global/base.rb', line 41

def only
  @only ||= []
end

Instance Method Details

#configurationObject



16
17
18
# File 'lib/global/base.rb', line 16

def configuration
  @configuration ||= load_configuration(config_directory, environment)
end

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Global::Base)

    the object that the method was called on



12
13
14
# File 'lib/global/base.rb', line 12

def configure
  yield self
end

#generate_js(options = {}) ⇒ Object



45
46
47
48
49
50
# File 'lib/global/base.rb', line 45

def generate_js(options = {})
  current_namespace = options[:namespace] || namespace

  js_options = { except: except, only: only }.merge(options)
  "window.#{current_namespace} = #{configuration.filter(js_options).to_json}"
end

#reload!Object



20
21
22
23
# File 'lib/global/base.rb', line 20

def reload!
  @configuration = nil
  configuration
end