Class: Rack::ScriptStackerUtils::SpecSolidifier

Inherits:
BasicObject
Defined in:
lib/rack/scriptstacker.rb

Instance Method Summary collapse

Constructor Details

#initialize(stacker_names) ⇒ SpecSolidifier

Returns a new instance of SpecSolidifier.



80
81
82
83
# File 'lib/rack/scriptstacker.rb', line 80

def initialize stacker_names
  @stacker_names = stacker_names
  @specs = ::Hash.new { |hash, key|  hash[key] = [] }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/rack/scriptstacker.rb', line 90

def method_missing name, *args
  if !@stacker_names.include? name
    ::Kernel.raise ::ArgumentError.new(
      "Expected one of #{@stacker_names}, but got #{name.inspect}."
    )
  end
  if args.size != 1
    ::Kernel.raise ::ArgumentError.new(
      "Expected a path spec like 'static/css' => 'stylesheets', " +
      "but got #{args.inspect} instead."
    )
  end
  @specs[name].push ::Rack::ScriptStackerUtils::PathSpec.new(args[0])
end

Instance Method Details

#call(stack_spec) ⇒ Object



85
86
87
88
# File 'lib/rack/scriptstacker.rb', line 85

def call stack_spec
  instance_eval &stack_spec
  @specs
end