Class: Xumlidot::Options

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

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.optionsObject

Returns the value of attribute options.



31
32
33
# File 'lib/xumlidot/options.rb', line 31

def options
  @options
end

Class Method Details

.method_missing(method_name, *_args, &_block) ⇒ Object

Raises:



33
34
35
36
37
# File 'lib/xumlidot/options.rb', line 33

def method_missing(method_name, *_args, &_block)
  return options.public_send(method_name) if options.respond_to?(method_name)

  raise OptionsError.new, "Unknown Option #{method_name}"
end

.parse(args) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/xumlidot/options.rb', line 44

def self.parse(args) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  @options = new

  @options.title = 'Class Diagram'
  @options.model_name = 'My Model'
  @options.diagram_type = :dot
  @options.rails = false
  @options.debug = false
  @options.inheritance = true
  @options.composition = true
  @options.usage = true
  @options.split = 1
  @options.sequence = ''
  @options.exclude = ''
  @options.use_debug_ids = false

  ENV.delete('XUMLIDOT_DEBUG')

  opt_parser = OptionParser.new do |opts|
    opts.banner = 'Usage: xumlidot.rb [options]'

    opts.separator ''
    opts.separator 'Specific options:'

    opts.on('-t', '--title [TEXT]', 'Title for the diagram') do |v|
      @options.title = v
    end

    opts.on('-m', '--model [TEXT]', 'Model Name for the diagram') do |v|
      @options.model_name = v
    end

    opts.on('-d', '--dot', 'Output diagram using dot (default)') do
      @options.diagram_type = :dot
    end

    opts.on('-x', '--xmi', 'Output diagram using xmi') do
      @options.diagram_type = :xmi
    end

    opts.on('-d', '--debug', 'Output debug information') do
      @options.debug = true
      ENV['XUMLIDOT_DEBUG'] = '1'
    end

    opts.on('-i', '--no-inheritance', 'Output inheritance links on the diagram') do
      @options.inheritance = false
    end

    opts.on('-c', '--no-composition', 'Output composition links on the diagram') do
      @options.composition = false
    end

    opts.on('-r', '--rails', 'Expect a Rails application') do |v|
      @options.rails = v
    end

    opts.on('-e', '--exclude [TEXT]', 'Exclude directories or files by pattern') do |v|
      @options.exclude = v
    end

    opts.on('-u', '--[no-]usage', 'Output usage links on the diagram') do |v|
      @options.usage = v
    end

    opts.on('-b', '--debug-ids', 'Output from a static list of ids') do |v|
      @options.use_debug_ids = v
    end

    opts.separator ''
    opts.separator 'Common options:'

    # No argument, shows at tail.  This will print an options summary.
    # Try it and see!
    opts.on_tail('-h', '--help', 'Show this message') do
      puts opts
      exit
    end

    # Another typical switch to print the version.
    opts.on_tail('--version', 'Show version') do
      puts ::Version.join('.')
      exit
    end
  end

  opt_parser.parse!(args)

  # Rather than pass the options around everywhere, lets set it as a class instance var
  # TODO: Remove code passing it around everywhere
  ::Xumlidot::Options.options = @options

  @options
end

.respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/xumlidot/options.rb', line 39

def respond_to_missing?(method_name, include_private = false)
  options.respond_to?(method_name) || super
end