Module: Hippo::Extensions
- Extended by:
- Enumerable
- Defined in:
- lib/hippo/extension.rb,
lib/hippo/extension/definition.rb
Defined Under Namespace
Classes: Base, Definition
Constant Summary
collapse
- ALL =
Array.new
Class Method Summary
collapse
Class Method Details
._maybe_fail(should_raise) ⇒ Object
92
93
94
95
|
# File 'lib/hippo/extension.rb', line 92
def _maybe_fail(should_raise)
raise Thor::Error.new("Unable to locate Hippo environment.\nDoes ./lib/*/extension.rb exist?") if should_raise
return nil
end
|
.add(klass) ⇒ Object
19
20
21
22
|
# File 'lib/hippo/extension.rb', line 19
def add(klass)
@cached_instances = nil
ALL << klass
end
|
.all ⇒ Object
24
25
26
|
# File 'lib/hippo/extension.rb', line 24
def all
ALL
end
|
.bootstrap(raise_on_fail: false) ⇒ Extension
Loads the code for the extension that the user is currently working inside. The ‘hippo` command uses this to detect what actions should be taken.
Will silently swallow any exceptions that are raised when the file is required and return nil
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/hippo/extension.rb', line 77
def bootstrap(raise_on_fail:false)
ext = Dir.glob("./lib/*/extension.rb").first
if ext
begin
require(ext)
rescue =>e
stack = e.backtrace[0..4].join("\n")
raise Thor::Error.new("Loading ./lib/*/extension.rb failed with: #{e}\n#{stack}")
end
Extensions.controlling
else
return _maybe_fail(raise_on_fail)
end
end
|
.client_module_paths ⇒ Object
134
135
136
137
138
|
# File 'lib/hippo/extension.rb', line 134
def client_module_paths
map { |e| e.root_path.join('client').to_s }.reverse + [
controlling.root_path.join('node_modules').to_s
]
end
|
.controlling ⇒ Object
64
65
66
67
68
|
# File 'lib/hippo/extension.rb', line 64
def controlling
last = ALL.last
each{|ext| return ext if ext.is_a?(last) }
Hippo.logger.error "Unable to find controlling extension. #{sorted} are loaded"
end
|
.each(reversed: false) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/hippo/extension.rb', line 57
def each(reversed: false)
@cached_instances ||= sorted.map{ |klass| klass.new }
(reversed ? @cached_instances.reverse : @cached_instances).each do |ext|
yield ext
end
end
|
.for_identifier(identifier) ⇒ Object
28
29
30
31
|
# File 'lib/hippo/extension.rb', line 28
def for_identifier(identifier)
each{|ext| return ext if ext.identifier == identifier }
nil
end
|
.load_controlling_config ⇒ Object
127
128
129
130
131
132
|
# File 'lib/hippo/extension.rb', line 127
def load_controlling_config
config_file = self.controlling.root_path.join('config','initialize.rb')
if config_file.exist?
require config_file
end
end
|
.load_screens ⇒ Object
10
11
12
13
14
15
16
17
|
# File 'lib/hippo/extension.rb', line 10
def load_screens
each do | ext |
screens_config = ext.root_path.join('config','screens.rb')
if screens_config.exist?
require screens_config
end
end
end
|
.sorted ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/hippo/extension.rb', line 33
def sorted
unmapped = all
mapped = []
while unmapped.any?
mapped_count = mapped.length
unmapped.each do | ext |
if !ext.before && !ext.after
mapped.push(ext)
end
if ext.before && (position = mapped.find_index(ext.before))
mapped.insert(position, ext)
end
if ext.after && (position = mapped.find_index(ext.after))
mapped.insert(position+1, ext)
end
end
if mapped_count == mapped.length Hippo.logger.info "Conflicting load directives. Some extensions will not be available"
end
unmapped -= mapped
end
mapped
end
|
.static_bootstrap_data ⇒ Object
Data returned will be included in the JS build; it should not be Tenant specific
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/hippo/extension.rb', line 99
def static_bootstrap_data
data = {}
%w{
api_path print_path_prefix environment assets_path_prefix
website_domain product_name support_email
}.each do |config|
data[config.to_sym] = Hippo.config.send(config)
end
data.merge!(
controlling_extension: controlling.identifier,
)
each do | ext |
ext_data = ext.static_bootstrap_data
data[ext.identifier] = ext_data unless ext_data.nil?
end
data[:subscription_plans] = Subscription.all.as_json
return data
end
|
.tenant_bootstrap_data(tenant) ⇒ Object
118
119
120
121
122
123
124
125
|
# File 'lib/hippo/extension.rb', line 118
def tenant_bootstrap_data(tenant)
data = {}
each do | ext |
tenant_data = ext.tenant_bootstrap_data(tenant)
data[ext.identifier] = tenant_data unless tenant_data.nil?
end
data
end
|