Class: Proscenium::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/proscenium/builder.rb

Defined Under Namespace

Modules: Request Classes: BuildError, CompileResult, ResolveError, Result

Constant Summary collapse

ENVIRONMENTS =
{ development: 1, test: 2, production: 3 }.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root: nil) ⇒ Builder

Returns a new instance of Builder.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/proscenium/builder.rb', line 88

def initialize(root: nil)
  @request_config = FFI::MemoryPointer.from_string({
    RootPath: (root || Rails.root).to_s,
    OutputDir: "public#{Proscenium.config.output_dir}",
    GemPath: gem_root,
    Environment: ENVIRONMENTS.fetch(Rails.env.to_sym, 2),
    EnvVars: env_vars,
    CodeSplitting: Proscenium.config.code_splitting,
    RubyGems: Proscenium::BundledGems.paths,
    Bundle: Proscenium.config.bundle,
    Aliases: Proscenium.config.aliases,
    Precompile: Proscenium.config.precompile,
    QueryString: Proscenium.config.cache_query_string.presence || '',
    Debug: Proscenium.config.debug
  }.to_json)
end

Class Method Details

.build_to_string(path, cache_query_string: '', root: nil) ⇒ Object



71
72
73
# File 'lib/proscenium/builder.rb', line 71

def self.build_to_string(path, cache_query_string: '', root: nil)
  new(root:).build_to_string(path, cache_query_string:)
end

.compile(root: nil) ⇒ Object



79
80
81
# File 'lib/proscenium/builder.rb', line 79

def self.compile(root: nil)
  new(root:).compile
end

.reset_config!Object

Intended for tests only.



84
85
86
# File 'lib/proscenium/builder.rb', line 84

def self.reset_config!
  Request.reset_config
end

.resolve(path, root: nil) ⇒ Object



75
76
77
# File 'lib/proscenium/builder.rb', line 75

def self.resolve(path, root: nil)
  new(root:).resolve(path)
end

Instance Method Details

#build_to_string(path, cache_query_string: '') ⇒ Object



105
106
107
108
109
110
111
112
113
# File 'lib/proscenium/builder.rb', line 105

def build_to_string(path, cache_query_string: '')
  ActiveSupport::Notifications.instrument('build.proscenium', identifier: path) do
    result = Request.build_to_string(path, cache_query_string, @request_config)

    raise BuildError.new(path, result[:response]) unless result[:success]

    result
  end
end

#compileObject



125
126
127
128
# File 'lib/proscenium/builder.rb', line 125

def compile
  result = Request.compile(@request_config)
  result[:success]
end

#resolve(path) ⇒ Object



115
116
117
118
119
120
121
122
123
# File 'lib/proscenium/builder.rb', line 115

def resolve(path)
  ActiveSupport::Notifications.instrument('resolve.proscenium', identifier: path) do
    result = Request.resolve(path, @request_config)

    raise ResolveError.new(path, result[:response]) unless result[:success]

    result[:response]
  end
end