Class: Speckle::CLI::RakeApp

Inherits:
Object
  • Object
show all
Defined in:
lib/speckle/cli/rake_app.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ RakeApp

Returns a new instance of RakeApp.



13
14
15
# File 'lib/speckle/cli/rake_app.rb', line 13

def initialize(options)
  @options = options
end

Instance Method Details

#configure_rakeObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/speckle/cli/rake_app.rb', line 58

def configure_rake
  rake_env('TEST_SOURCES', test_sources)
  rake_env('TEST_LIBS', test_libs)
  rake_env('BUILD_DIR', test_build_dir)
  rake_env('TEST_COMPILED', test_compiled)
  rake_env('TEST_VIM', @options.vim)
  rake_env('TEST_REPORTER', @options.reporter)
  rake_env('SLOW_THRESHOLD', @options.slow_threshold.to_s)
  rake_env('SKIP_VIMRC', to_int(@options.skip_vimrc))
  rake_env('COLORIZE', to_int(@options.colorize))
  rake_env('BAIL', to_int(@options.bail))
  rake_env('TAG', @options.tag)

  if @options.verbose
    rake_env('VERBOSE', 'yes')
  end

  if @options.debug
    rake_env('DEBUG', 'yes')
  end
end

#debugObject



25
26
27
# File 'lib/speckle/cli/rake_app.rb', line 25

def debug
  @options.debug
end

#get_builderObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/speckle/cli/rake_app.rb', line 99

def get_builder
  if @source_builder.nil?
    @source_builder = Speckle::List::Builder.new
    @options.inputs.each do |input|
      @source_builder.add_source input
    end

    @source_builder.add_filter Speckle::List::DirExpander.new('**/*_spec.riml')

    unless @options.tag.nil?
      @source_builder.add_filter Speckle::List::FileContentFilter.new(@options.tag, false)
    end

    unless @options.grep_pattern.nil?
      @source_builder.add_filter Speckle::List::PatternFilter.new(@options.grep_pattern, @options.grep_invert)
    end

    # Not using this at the moment, as it's simpler to not rebuild the source paths for test_compiled
    #@source_builder.add_filter Speckle::List::AbsolutePathTransformer.new
    #@source_builder.add_filter Speckle::List::ExtensionTransformer.new('vim')
  end

  @source_builder
end

#inputsObject



17
18
19
# File 'lib/speckle/cli/rake_app.rb', line 17

def inputs
  @options.inputs
end

#invoke_task(name) ⇒ Object



45
46
47
48
49
# File 'lib/speckle/cli/rake_app.rb', line 45

def invoke_task(name)
  #puts "invoke_task: #{name}"
  #rake
  rake.invoke_task("speckle:#{name.to_s}")
end

#rakeObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/speckle/cli/rake_app.rb', line 29

def rake
  if @rake_app
    return @rake_app
  end

  configure_rake
  Dir.chdir @options.root_dir

  @rake_app = Rake.application
  @rake_app.init
  @rake_app.load_rakefile

  Dir.chdir @options.cwd
  @rake_app
end

#rake_env(key, value) ⇒ Object



51
52
53
54
55
56
# File 'lib/speckle/cli/rake_app.rb', line 51

def rake_env(key, value)
  unless value.nil?
    ENV[key] = if value.is_a?(Array) then value.join(';') else value end
    puts "rake_env: #{key} = #{ENV[key]}" if debug
  end
end

#test_build_dirObject



84
85
86
# File 'lib/speckle/cli/rake_app.rb', line 84

def test_build_dir
  "#{@options.cwd}/build"
end

#test_compiledObject



92
93
94
95
96
97
# File 'lib/speckle/cli/rake_app.rb', line 92

def test_compiled
  sources = test_sources
  sources.collect do |source|
    source.ext('vim')
  end
end

#test_libsObject



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/speckle/cli/rake_app.rb', line 124

def test_libs
  input_libs = @options.libs
  return nil if input_libs.nil?

  input_libs = input_libs.split(':')
  input_libs << 'spec'
  if File.directory?(@options.speckle_lib_dir)
    input_libs << @options.speckle_lib_dir
  end

  libs = []
  input_libs.each do |lib|
    libs << File.absolute_path(lib)
  end

  libs.join(':')
end

#test_sourcesObject



88
89
90
# File 'lib/speckle/cli/rake_app.rb', line 88

def test_sources
  get_builder.build
end

#to_int(option) ⇒ Object



80
81
82
# File 'lib/speckle/cli/rake_app.rb', line 80

def to_int(option)
  option ? '1' : '0'
end

#verboseObject



21
22
23
# File 'lib/speckle/cli/rake_app.rb', line 21

def verbose
  @options.verbose
end