Class: Propshaft::Assembly

Inherits:
Object
  • Object
show all
Defined in:
lib/propshaft/assembly.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Assembly

Returns a new instance of Assembly.



13
14
15
# File 'lib/propshaft/assembly.rb', line 13

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/propshaft/assembly.rb', line 11

def config
  @config
end

Instance Method Details

#compilersObject



38
39
40
41
42
43
44
45
# File 'lib/propshaft/assembly.rb', line 38

def compilers
  @compilers ||=
    Propshaft::Compilers.new(self).tap do |compilers|
      Array(config.compilers).each do |(mime_type, klass)|
        compilers.register mime_type, klass
      end
    end
end

#load_pathObject



17
18
19
# File 'lib/propshaft/assembly.rb', line 17

def load_path
  @load_path ||= Propshaft::LoadPath.new(config.paths, version: config.version)
end

#processorObject



33
34
35
36
# File 'lib/propshaft/assembly.rb', line 33

def processor
  Propshaft::Processor.new \
    load_path: load_path, output_path: config.output_path, compilers: compilers
end

#resolverObject



21
22
23
24
25
26
27
# File 'lib/propshaft/assembly.rb', line 21

def resolver
  @resolver ||= if manifest_path.exist?
    Propshaft::Resolver::Static.new manifest_path: manifest_path, prefix: config.prefix
  else
    Propshaft::Resolver::Dynamic.new load_path: load_path, prefix: config.prefix
  end
end

#reveal(path_type = :logical_path) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/propshaft/assembly.rb', line 47

def reveal(path_type = :logical_path)
  path_type = path_type.presence_in(%i[ logical_path path ]) || raise(ArgumentError, "Unknown path_type: #{path_type}")
  
  load_path.assets.collect do |asset|
    asset.send(path_type)
  end
end

#serverObject



29
30
31
# File 'lib/propshaft/assembly.rb', line 29

def server
  Propshaft::Server.new(self)
end