Class: SBConstants::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/sbconstants/options.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



62
63
64
65
# File 'lib/sbconstants/options.rb', line 62

def initialize
  self.query_file = File.expand_path('../../sbconstants/identifiers.yml', __FILE__)
  self.source_dir = Dir.pwd
end

Instance Attribute Details

#destinationObject

Returns the value of attribute destination.



6
7
8
# File 'lib/sbconstants/options.rb', line 6

def destination
  @destination
end

#dry_runObject

Returns the value of attribute dry_run.



6
7
8
# File 'lib/sbconstants/options.rb', line 6

def dry_run
  @dry_run
end

#output_pathObject

Returns the value of attribute output_path.



6
7
8
# File 'lib/sbconstants/options.rb', line 6

def output_path
  @output_path
end

#prefixObject

Returns the value of attribute prefix.



6
7
8
# File 'lib/sbconstants/options.rb', line 6

def prefix
  @prefix
end

#query_configObject

Returns the value of attribute query_config.



6
7
8
# File 'lib/sbconstants/options.rb', line 6

def query_config
  @query_config
end

#query_fileObject

Returns the value of attribute query_file.



6
7
8
# File 'lib/sbconstants/options.rb', line 6

def query_file
  @query_file
end

#source_dirObject

Returns the value of attribute source_dir.



6
7
8
# File 'lib/sbconstants/options.rb', line 6

def source_dir
  @source_dir
end

#templates_dirObject

Returns the value of attribute templates_dir.



6
7
8
# File 'lib/sbconstants/options.rb', line 6

def templates_dir
  @templates_dir
end

#use_swiftObject

Returns the value of attribute use_swift.



6
7
8
# File 'lib/sbconstants/options.rb', line 6

def use_swift
  @use_swift
end

Class Method Details

.parse(argv) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/sbconstants/options.rb', line 19

def self.parse argv
  options = self.new
  OptionParser.new do |opts|
    opts.banner = "Usage: DESTINATION_FILE [options]"

    opts.on('-d', '--dry-run', 'Output to STDOUT') do |dry_run|
      options.dry_run = dry_run
    end
    
    opts.on('-p', '--prefix=<prefix>', 'Only match identifiers with <prefix>') do |prefix|
      options.prefix = prefix
    end

    opts.on('-s', '--source-dir=<source>', 'Directory containing storyboards') do |source_dir|
      options.source_dir = source_dir
    end
    
    opts.on('-t', '--templates-dir=<templates>', 'Directory containing the templates to use for code formatting') do |templates_dir|
      options.templates_dir = templates_dir
    end

    opts.on('-q', '--queries=<queries>', 'YAML file containing queries') do |queries|
      options.query_file = queries
    end

    opts.on('-v', '--verbose', 'Verbose output') do |verbose|
      options.verbose = verbose
    end
    
    opts.on('-w', '--swift', 'Output to a Swift File') do |use_swift|
      options.use_swift = use_swift
    end
  end.parse!(argv)

  if argv.first.nil?
    options.dry_run = true
    options.output_path = 'no file given'
  else
    options.output_path = argv.first.chomp(File.extname(ARGV.first))
  end
  options
end

Instance Method Details

#queriesObject



67
68
69
70
# File 'lib/sbconstants/options.rb', line 67

def queries
  load_queries if @queries.nil?
  @queries
end