Class: Lucid::CLI::Configuration

Inherits:
Object
  • Object
show all
Includes:
ObjectFactory
Defined in:
lib/lucid/cli/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ObjectFactory

#create_object_of, #underscore

Constructor Details

#initialize(out_stream = STDOUT, err_stream = STDERR) ⇒ Configuration

Returns a new instance of Configuration.



16
17
18
19
20
# File 'lib/lucid/cli/configuration.rb', line 16

def initialize(out_stream = STDOUT, err_stream = STDERR)
  @out_stream   = out_stream
  @err_stream = err_stream
  @options = Options.new(@out_stream, @err_stream, :default_profile => 'default')
end

Instance Attribute Details

#out_streamObject (readonly)

Returns the value of attribute out_stream.



14
15
16
# File 'lib/lucid/cli/configuration.rb', line 14

def out_stream
  @out_stream
end

Instance Method Details

#debug?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/lucid/cli/configuration.rb', line 39

def debug?
  @options[:debug]
end

#definition_contextObject

See Also:

  • Runtime.load_execution_context


106
107
108
# File 'lib/lucid/cli/configuration.rb', line 106

def definition_context
  spec_requires.reject { |f| f=~ %r{#{library_path}} }
end

#driver_fileObject



165
166
167
# File 'lib/lucid/cli/configuration.rb', line 165

def driver_file
  @options[:driver_file].empty? ? 'driver' : @options[:driver_file]
end

#dry_run?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/lucid/cli/configuration.rb', line 55

def dry_run?
  @options[:dry_run]
end

#establish_tdl_walker(runtime) ⇒ Object



71
72
73
# File 'lib/lucid/cli/configuration.rb', line 71

def establish_tdl_walker(runtime)
  AST::TDLWalker.new(runtime, formatters(runtime), self)
end

#expand?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/lucid/cli/configuration.rb', line 59

def expand?
  @options[:expand]
end

#filtersObject



182
183
184
# File 'lib/lucid/cli/configuration.rb', line 182

def filters
  @options.filters
end

#formatsObject



186
187
188
# File 'lib/lucid/cli/configuration.rb', line 186

def formats
  @options[:formats]
end

#formatter_class(name) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/lucid/cli/configuration.rb', line 75

def formatter_class(name)
  if(lucid_format = Options::LUCID_FORMATS[name])
    create_object_of(lucid_format[0])
  else
    create_object_of(name)
  end
end

#guess?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/lucid/cli/configuration.rb', line 51

def guess?
  @options[:guess]
end

#library_contextObject

See Also:

  • Runtime.load_execution_context


111
112
113
114
115
116
117
118
119
120
# File 'lib/lucid/cli/configuration.rb', line 111

def library_context
  library_files = spec_requires.select { |f| f =~ %r{#{library_path}} }
  driver = library_files.select {|f| f =~ %r{#{driver_file}} }

  log.info("Driver File Found: #{driver}")

  non_driver_files = library_files - driver

  @options[:dry_run] ? non_driver_files : driver + non_driver_files
end

#library_pathObject



161
162
163
# File 'lib/lucid/cli/configuration.rb', line 161

def library_path
  @options[:library_path].empty? ? 'common' : @options[:library_path]
end

#logObject



169
170
171
172
173
174
175
176
# File 'lib/lucid/cli/configuration.rb', line 169

def log
  logger = Logger.new(@out_stream)
  logger.formatter = LogFormatter.new
  logger.level = Logger::WARN
  logger.level = Logger::INFO  if self.verbose?
  logger.level = Logger::DEBUG if self.debug?
  logger
end

#matcher_typeObject



67
68
69
# File 'lib/lucid/cli/configuration.rb', line 67

def matcher_type
  @options[:matcher_type] || :regexp
end

#parse(args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/lucid/cli/configuration.rb', line 22

def parse(args)
  @args = args
  @options.parse(args)
  log.debug("Options: #{@options.inspect}")

  prepare_output_formatting
  raise('You cannot use both --strict and --wip tags.') if strict? && wip?

  @options[:tag_expression] = Gherkin::TagExpression.new(@options[:tag_expressions])

  set_environment_variables
end

#spec_filesObject

See Also:

  • Runtime.specs


123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/lucid/cli/configuration.rb', line 123

def spec_files
  files = specs_path(spec_source).map do |path|
    path = path.gsub(/\\/, '/')  # convert \ to /
    path = path.chomp('/')       # removing trailing /

    files_to_sort = []

    if File.directory?(path)
      spec_type.each do |type|
        files_to_sort << Dir["#{path}/**/*.#{type}"].sort
      end

      files_to_sort
    elsif path[0..0] == '@' and # @listfile.txt
        File.file?(path[1..-1]) # listfile.txt is a file
      IO.read(path[1..-1]).split
    else
      path
    end
  end.flatten.uniq

  extract_excluded_files(files)

  files
end

#spec_locationObject



149
150
151
152
153
154
# File 'lib/lucid/cli/configuration.rb', line 149

def spec_location
  dirs = spec_source.map { |f| File.directory?(f) ? f : File.dirname(f) }.uniq
  dirs.delete('.') unless spec_source.include?('.')

  specs_path(dirs)
end

#spec_requiresObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/lucid/cli/configuration.rb', line 83

def spec_requires
  requires = @options[:require].empty? ? require_dirs : @options[:require]

  files = requires.map do |path|
    path = path.gsub(/\\/, '/')   # convert \ to /
    path = path.gsub(/\/$/, '')   # removing trailing /
    File.directory?(path) ? Dir["#{path}/**/*"] : path
  end.flatten.uniq

  extract_excluded_files(files)

  files.reject! {|f| !File.file?(f)}

  spec_types = spec_type.each do |type|
    files.reject! {|f| File.extname(f) == ".#{type}" }
  end

  files.reject! {|f| f =~ /^http/}

  files.sort
end

#spec_sourceObject



190
191
192
# File 'lib/lucid/cli/configuration.rb', line 190

def spec_source
  @options[:spec_source]
end

#spec_typeObject



156
157
158
159
# File 'lib/lucid/cli/configuration.rb', line 156

def spec_type
  @options[:spec_type]

end

#strict?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/lucid/cli/configuration.rb', line 43

def strict?
  @options[:strict]
end

#tag_expressionObject



178
179
180
# File 'lib/lucid/cli/configuration.rb', line 178

def tag_expression
  Gherkin::TagExpression.new(@options[:tag_expressions])
end

#testdefsObject



63
64
65
# File 'lib/lucid/cli/configuration.rb', line 63

def testdefs
  @options[:testdefs]
end

#verbose?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/lucid/cli/configuration.rb', line 35

def verbose?
  @options[:verbose]
end

#wip?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/lucid/cli/configuration.rb', line 47

def wip?
  @options[:wip]
end