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