Class: Jasminewebos::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/jasminewebos/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Server

Returns a new instance of Server.



3
4
5
# File 'lib/jasminewebos/server.rb', line 3

def initialize(configuration)
  @configuration = configuration
end

Instance Method Details

#dir_mappingsObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/jasminewebos/server.rb', line 47

def dir_mappings
  {
          "/framework" => framework_dir,
          "/app" => application_src_dir,
          "/spec" => @configuration.specs_dir,
          "/matchers" => @configuration.matchers_dir,
          "/lib" => jasmine_lib_dir,
          "/matchers" => @configuration.matchers_dir,
          "/javascripts" => javascripts_sources_dir
  }
end

#source_filesObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jasminewebos/server.rb', line 28

def source_files
  jasmine = Dir.glob(File.join(jasmine_lib_dir, "*"))
  jasmine = jasmine.collect {|f| f.sub(jasmine_lib_dir, "/lib")}
  
  matchers = Dir.glob(File.join(@configuration.matchers_dir, "**/*.js"))
  matchers = matchers.collect {|f| f.sub(@configuration.matchers_dir, "/matchers")}
  
  sources = Dir.glob(File.join(application_src_dir, "**/*.js"))
  sources = sources.collect {|f| f.sub(application_src_dir, "/app")}
  
  javascripts_sources = Dir.glob(File.join(javascripts_sources_dir, "**/*.js"))
  javascripts_sources = javascripts_sources.collect {|f| f.sub(javascripts_sources_dir, "/javascripts")}
  
  framework = Dir.glob(File.join(framework_dir, "**/*.js"))
  framework = framework.collect {|f| f.sub(framework_dir, "/framework")}
  
  framework + jasmine.sort.reverse + matchers.sort + sources.sort + javascripts_sources.sort
end

#spec_filesObject



23
24
25
26
# File 'lib/jasminewebos/server.rb', line 23

def spec_files
  raw_specs = Dir.glob(File.join(@configuration.specs_dir, "**/*[Ss]pec.js"))
  raw_specs.collect {|f| f.sub(@configuration.specs_dir, "/spec")}
end

#startObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jasminewebos/server.rb', line 7

def start
  puts "Starting JasmineWebOS Server from #{@configuration.application_root}"
  puts "on http://localhost:#{@configuration.port}"
  
  require File.expand_path(File.join(@configuration.jasmine_root, 
                                     "contrib", 
                                     "ruby", 
                                     "jasmine_spec_builder"))
                                     
  
  Jasmine::SimpleServer.start(@configuration.port,
                              lambda{spec_files},
                              dir_mappings,
                              lambda{source_files})
end