Module: CloudflareWorkers::BuildSupport

Defined in:
lib/cloudflare_workers/build_support.rb

Constant Summary collapse

RUNTIME_GEM_NAME =
'homura-runtime'
SINATRA_GEM_NAME =
'sinatra-homura'

Class Method Summary collapse

Class Method Details

.gem_lib(name, loaded_specs: Gem.loaded_specs) ⇒ Object



22
23
24
25
26
27
# File 'lib/cloudflare_workers/build_support.rb', line 22

def gem_lib(name, loaded_specs: Gem.loaded_specs)
  spec = loaded_spec(name, loaded_specs: loaded_specs)
  return File.join(spec.full_gem_path, 'lib') if spec

  raise("cloudflare-workers-build: gem #{name} not loaded; use bundle exec from app root")
end

.loaded_spec(name, loaded_specs: Gem.loaded_specs) ⇒ Object



11
12
13
# File 'lib/cloudflare_workers/build_support.rb', line 11

def loaded_spec(name, loaded_specs: Gem.loaded_specs)
  loaded_specs[name]
end

.runtime_root(current_file:, loaded_specs: Gem.loaded_specs) ⇒ Object



15
16
17
18
19
20
# File 'lib/cloudflare_workers/build_support.rb', line 15

def runtime_root(current_file:, loaded_specs: Gem.loaded_specs)
  spec = loaded_spec(RUNTIME_GEM_NAME, loaded_specs: loaded_specs)
  return Pathname(spec.full_gem_path) if spec

  Pathname(current_file).expand_path.join('../..')
end

.vendor_from_gemfile(project_root) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cloudflare_workers/build_support.rb', line 29

def vendor_from_gemfile(project_root)
  gf = Pathname(project_root).join('Gemfile')
  return unless gf.file?

  txt = gf.read
  return unless (m = txt.match(/#{Regexp.escape(RUNTIME_GEM_NAME)}['"]\s*,\s*path:\s*['"]([^'"]+)['"]/))

  runtime_path = Pathname.new(m[1]).expand_path(project_root)
  vend = runtime_path.join('..', '..', 'vendor').expand_path
  vend if vend.directory?
end