Module: Global::Base

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

Constant Summary collapse

FILE_ENV_SPLIT =
'.'
YAML_EXT =
'.yml'

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)



109
110
111
# File 'lib/global/base.rb', line 109

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

Instance Attribute Details

#config_directoryObject



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

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

#environmentObject



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

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

#exceptObject



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

def except
  @except ||= :all
end

#namespaceObject



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

def namespace
  @namespace ||= 'Global'
end

#onlyObject



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

def only
  @only ||= []
end

Instance Method Details

#configurationObject



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

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



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

def configure
  yield self
end

#generate_js(options = {}) ⇒ Object



49
50
51
52
53
54
# File 'lib/global/base.rb', line 49

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



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

def reload!
  @configuration = nil
  configuration
end