Class: Stapler::Bundle

Inherits:
Object
  • Object
show all
Defined in:
lib/stapler/bundle.rb,
lib/stapler/bundle/key.rb,
lib/stapler/bundle/serialized_key.rb

Defined Under Namespace

Classes: SerializedKey

Constant Summary collapse

Key =
SerializedKey
@@asset_id =
Time.now.to_i.to_s

Instance Method Summary collapse

Constructor Details

#initialize(config, bundle) ⇒ Bundle

Returns a new instance of Bundle.



9
10
11
12
# File 'lib/stapler/bundle.rb', line 9

def initialize(config, bundle)
  @config = config
  @paths = Key.to_paths(bundle.to_s)
end

Instance Method Details

#response(env) ⇒ Object

Collect asset responses and build the collective response



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/stapler/bundle.rb', line 15

def response(env)
  if not @paths.is_a?(Array)
    @config.rack_file.not_found
  else
    @paths.inject([200, {}, '']) do |sum, path|
      # Fetch the response
      item = Stapler::Asset.new(@config, path).response(env)

      # Add the file title
      sum[2] << "\n\n\n/***** #{path} *****/\n\n\n"

      if item[0] != 200
        sum[2] << "/* [#{item[0]}] Asset problem */\n\n\n"
      else
        # Headers are merged
        sum[1].merge!(item[1])
        # Body is concatenated
        sum[2] << Stapler::Utils.response_body(item)
      end

      # Return the response
      sum
    end
  end
end