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
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_directory ⇒ Object
33
34
35
|
# File 'lib/global/base.rb', line 33
def config_directory
@config_directory || raise('config_directory should be defined')
end
|
#environment ⇒ Object
29
30
31
|
# File 'lib/global/base.rb', line 29
def environment
@environment || raise('environment should be defined')
end
|
#except ⇒ Object
41
42
43
|
# File 'lib/global/base.rb', line 41
def except
@except ||= :all
end
|
#namespace ⇒ Object
37
38
39
|
# File 'lib/global/base.rb', line 37
def namespace
@namespace ||= 'Global'
end
|
#only ⇒ Object
45
46
47
|
# File 'lib/global/base.rb', line 45
def only
@only ||= []
end
|
Instance Method Details
#configuration ⇒ Object
20
21
22
|
# File 'lib/global/base.rb', line 20
def configuration
@configuration ||= load_configuration(config_directory, environment)
end
|
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
|