Class: CoffeeGrounds::Grinder

Inherits:
Object
  • Object
show all
Defined in:
lib/coffee-grounds/grinder.rb

Instance Method Summary collapse

Constructor Details

#initialize(rails_app, options = {}) ⇒ Grinder

Returns a new instance of Grinder.



3
4
5
6
7
# File 'lib/coffee-grounds/grinder.rb', line 3

def initialize( rails_app, options = {} )
  @rails = rails_app
  config = @rails.application.config
  @target_dir = ( options[:output_dir] ) ? options[:output_dir] : File.join(@rails.root, "app/assets/javascripts")
end

Instance Method Details

#grindObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/coffee-grounds/grinder.rb', line 9

def grind
  if !Dir.exists?( @target_dir )
    Dir.mkdir( @target_dir )
  end
  route_hash = Hash.new
  @rails.application.routes.routes.to_a.each do |route|
    if route.name && !route.name.empty?
      route_hash[ route.name.to_s] = route.path.spec.to_s
    end
  end
  save_routes_to_js( @target_dir, route_hash )
end