Class: Docspec::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target = nil) ⇒ CLI

Returns a new instance of CLI.



8
9
10
# File 'lib/docspec/cli.rb', line 8

def initialize(target=nil)
  @target = target || 'README.md'
end

Instance Attribute Details

#exit_codeObject (readonly)

Returns the value of attribute exit_code.



6
7
8
# File 'lib/docspec/cli.rb', line 6

def exit_code
  @exit_code
end

#failed_examplesObject (readonly)

Returns the value of attribute failed_examples.



6
7
8
# File 'lib/docspec/cli.rb', line 6

def failed_examples
  @failed_examples
end

#targetObject (readonly)

Returns the value of attribute target.



6
7
8
# File 'lib/docspec/cli.rb', line 6

def target
  @target
end

#total_examplesObject (readonly)

Returns the value of attribute total_examples.



6
7
8
# File 'lib/docspec/cli.rb', line 6

def total_examples
  @total_examples
end

Instance Method Details

#modeObject



12
13
14
# File 'lib/docspec/cli.rb', line 12

def mode
  File.directory?(target) ? :dir : :file
end

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/docspec/cli.rb', line 16

def run
  abort "Target not found: #{target}" unless File.exist? target

  @exit_code = 0
  @total_examples = 0
  @failed_examples = 0

  if mode == :dir
    run_dir
  else
    run_file target
  end

  show_footer
end