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.



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

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,
    External: Proscenium.config.external,
    Precompile: Proscenium.config.precompile,
    Debug: Proscenium.config.debug
  }.to_json)
end

Class Method Details

.build_to_string(path, root: nil) ⇒ Object



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

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

.compile(root: nil) ⇒ Object



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

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

.reset_config!Object

Intended for tests only.



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

def self.reset_config!
  Request.reset_config
end

.resolve(path, root: nil) ⇒ Object



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

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

Instance Method Details

#build_to_string(path) ⇒ Object



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

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

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

    result
  end
end

#compileObject



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

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

#resolve(path) ⇒ Object



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

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