brakeman 4.5.0 → 4.5.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of brakeman might be problematic. Click here for more details.

Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +15 -0
  3. data/README.md +6 -6
  4. data/bundle/load.rb +3 -3
  5. data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/AUTHORS +0 -0
  6. data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/COPYING +0 -0
  7. data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/Changelog.md +211 -15
  8. data/bundle/ruby/2.5.0/gems/highline-2.0.2/Gemfile +22 -0
  9. data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/LICENSE +0 -0
  10. data/bundle/ruby/2.5.0/gems/highline-2.0.2/README.md +202 -0
  11. data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/TODO +0 -0
  12. data/bundle/ruby/2.5.0/gems/highline-2.0.2/appveyor.yml +37 -0
  13. data/bundle/ruby/2.5.0/gems/highline-2.0.2/highline.gemspec +35 -0
  14. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline.rb +650 -0
  15. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/builtin_styles.rb +129 -0
  16. data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/lib/highline/color_scheme.rb +49 -32
  17. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/compatibility.rb +23 -0
  18. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/custom_errors.rb +57 -0
  19. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/import.rb +48 -0
  20. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/io_console_compatible.rb +37 -0
  21. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/list.rb +177 -0
  22. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/list_renderer.rb +261 -0
  23. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/menu.rb +576 -0
  24. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/menu/item.rb +32 -0
  25. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/paginator.rb +52 -0
  26. data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/lib/highline/question.rb +281 -131
  27. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/question/answer_converter.rb +103 -0
  28. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/question_asker.rb +150 -0
  29. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/simulate.rb +59 -0
  30. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/statement.rb +88 -0
  31. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/string.rb +36 -0
  32. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/string_extensions.rb +130 -0
  33. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/style.rb +325 -0
  34. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/template_renderer.rb +62 -0
  35. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/terminal.rb +190 -0
  36. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/terminal/io_console.rb +36 -0
  37. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/terminal/ncurses.rb +38 -0
  38. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/terminal/unix_stty.rb +51 -0
  39. data/bundle/ruby/2.5.0/gems/{highline-1.7.10 → highline-2.0.2}/lib/highline/version.rb +3 -1
  40. data/bundle/ruby/2.5.0/gems/highline-2.0.2/lib/highline/wrapper.rb +53 -0
  41. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/History.rdoc +32 -0
  42. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/Manifest.txt +0 -0
  43. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/README.rdoc +0 -0
  44. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/compare/normalize.rb +0 -0
  45. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/debugging.md +0 -0
  46. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/rp_extensions.rb +1 -1
  47. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/rp_stringscanner.rb +0 -0
  48. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby20_parser.rb +2427 -2432
  49. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby20_parser.y +32 -29
  50. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby21_parser.rb +2101 -2109
  51. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby21_parser.y +32 -29
  52. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby22_parser.rb +2080 -2095
  53. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby22_parser.y +32 -29
  54. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0/lib/ruby25_parser.rb → ruby_parser-3.13.1/lib/ruby23_parser.rb} +2339 -2333
  55. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby23_parser.y +32 -29
  56. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby24_parser.rb +2347 -2335
  57. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby24_parser.y +32 -23
  58. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0/lib/ruby23_parser.rb → ruby_parser-3.13.1/lib/ruby25_parser.rb} +2349 -2337
  59. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby25_parser.y +32 -23
  60. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby26_parser.rb +2351 -2338
  61. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby26_parser.y +32 -23
  62. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby_lexer.rb +253 -161
  63. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby_lexer.rex +25 -25
  64. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby_lexer.rex.rb +68 -26
  65. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby_parser.rb +3 -1
  66. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby_parser.yy +34 -23
  67. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/lib/ruby_parser_extras.rb +64 -43
  68. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/tools/munge.rb +2 -1
  69. data/bundle/ruby/2.5.0/gems/{ruby_parser-3.13.0 → ruby_parser-3.13.1}/tools/ripper.rb +6 -1
  70. data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/CHANGELOG.md +4 -0
  71. data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/MIT-LICENSE.txt +0 -0
  72. data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/README.md +1 -1
  73. data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/data/display_width.marshal.gz +0 -0
  74. data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/lib/unicode/display_width.rb +0 -0
  75. data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/lib/unicode/display_width/constants.rb +2 -2
  76. data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/lib/unicode/display_width/index.rb +0 -0
  77. data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/lib/unicode/display_width/no_string_ext.rb +0 -0
  78. data/bundle/ruby/2.5.0/gems/{unicode-display_width-1.5.0 → unicode-display_width-1.6.0}/lib/unicode/display_width/string_ext.rb +0 -0
  79. data/lib/brakeman.rb +7 -0
  80. data/lib/brakeman/app_tree.rb +34 -22
  81. data/lib/brakeman/checks.rb +7 -7
  82. data/lib/brakeman/checks/base_check.rb +9 -9
  83. data/lib/brakeman/checks/check_cross_site_scripting.rb +5 -0
  84. data/lib/brakeman/checks/check_default_routes.rb +5 -0
  85. data/lib/brakeman/checks/check_deserialize.rb +52 -0
  86. data/lib/brakeman/checks/check_dynamic_finders.rb +1 -1
  87. data/lib/brakeman/checks/check_force_ssl.rb +27 -0
  88. data/lib/brakeman/checks/check_json_parsing.rb +5 -0
  89. data/lib/brakeman/checks/check_link_to_href.rb +6 -1
  90. data/lib/brakeman/checks/check_mail_to.rb +1 -1
  91. data/lib/brakeman/checks/check_model_attr_accessible.rb +1 -1
  92. data/lib/brakeman/checks/check_model_attributes.rb +12 -50
  93. data/lib/brakeman/checks/check_model_serialize.rb +1 -1
  94. data/lib/brakeman/checks/check_nested_attributes_bypass.rb +3 -3
  95. data/lib/brakeman/checks/check_secrets.rb +1 -1
  96. data/lib/brakeman/checks/check_session_settings.rb +10 -10
  97. data/lib/brakeman/checks/check_simple_format.rb +5 -0
  98. data/lib/brakeman/checks/check_skip_before_filter.rb +1 -1
  99. data/lib/brakeman/checks/check_sql.rb +15 -17
  100. data/lib/brakeman/checks/check_validation_regex.rb +1 -1
  101. data/lib/brakeman/file_parser.rb +6 -8
  102. data/lib/brakeman/file_path.rb +71 -0
  103. data/lib/brakeman/options.rb +7 -0
  104. data/lib/brakeman/parsers/template_parser.rb +3 -3
  105. data/lib/brakeman/processor.rb +3 -4
  106. data/lib/brakeman/processors/alias_processor.rb +12 -6
  107. data/lib/brakeman/processors/base_processor.rb +8 -7
  108. data/lib/brakeman/processors/controller_alias_processor.rb +10 -7
  109. data/lib/brakeman/processors/controller_processor.rb +5 -9
  110. data/lib/brakeman/processors/haml_template_processor.rb +5 -0
  111. data/lib/brakeman/processors/lib/module_helper.rb +8 -8
  112. data/lib/brakeman/processors/lib/processor_helper.rb +3 -3
  113. data/lib/brakeman/processors/lib/rails2_config_processor.rb +3 -3
  114. data/lib/brakeman/processors/lib/rails2_route_processor.rb +2 -2
  115. data/lib/brakeman/processors/lib/rails3_config_processor.rb +3 -3
  116. data/lib/brakeman/processors/lib/rails3_route_processor.rb +2 -2
  117. data/lib/brakeman/processors/lib/render_helper.rb +2 -2
  118. data/lib/brakeman/processors/lib/render_path.rb +18 -1
  119. data/lib/brakeman/processors/library_processor.rb +5 -5
  120. data/lib/brakeman/processors/model_processor.rb +4 -5
  121. data/lib/brakeman/processors/output_processor.rb +5 -0
  122. data/lib/brakeman/processors/template_alias_processor.rb +4 -5
  123. data/lib/brakeman/processors/template_processor.rb +4 -4
  124. data/lib/brakeman/report.rb +3 -3
  125. data/lib/brakeman/report/ignore/config.rb +2 -3
  126. data/lib/brakeman/report/ignore/interactive.rb +2 -2
  127. data/lib/brakeman/report/pager.rb +1 -0
  128. data/lib/brakeman/report/report_base.rb +51 -6
  129. data/lib/brakeman/report/report_codeclimate.rb +3 -3
  130. data/lib/brakeman/report/report_hash.rb +1 -1
  131. data/lib/brakeman/report/report_html.rb +2 -2
  132. data/lib/brakeman/report/report_json.rb +1 -24
  133. data/lib/brakeman/report/report_table.rb +20 -4
  134. data/lib/brakeman/report/report_tabs.rb +1 -1
  135. data/lib/brakeman/report/report_text.rb +2 -2
  136. data/lib/brakeman/rescanner.rb +9 -12
  137. data/lib/brakeman/scanner.rb +19 -14
  138. data/lib/brakeman/tracker.rb +4 -4
  139. data/lib/brakeman/tracker/collection.rb +4 -3
  140. data/lib/brakeman/tracker/config.rb +6 -0
  141. data/lib/brakeman/util.rb +1 -147
  142. data/lib/brakeman/version.rb +1 -1
  143. data/lib/brakeman/warning.rb +23 -13
  144. data/lib/brakeman/warning_codes.rb +1 -0
  145. data/lib/ruby_parser/bm_sexp_processor.rb +1 -0
  146. metadata +78 -61
  147. data/bundle/ruby/2.5.0/gems/highline-1.7.10/Gemfile +0 -11
  148. data/bundle/ruby/2.5.0/gems/highline-1.7.10/INSTALL +0 -59
  149. data/bundle/ruby/2.5.0/gems/highline-1.7.10/README.rdoc +0 -74
  150. data/bundle/ruby/2.5.0/gems/highline-1.7.10/highline.gemspec +0 -37
  151. data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline.rb +0 -1048
  152. data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/compatibility.rb +0 -16
  153. data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/import.rb +0 -41
  154. data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/menu.rb +0 -381
  155. data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/simulate.rb +0 -48
  156. data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/string_extensions.rb +0 -111
  157. data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/style.rb +0 -192
  158. data/bundle/ruby/2.5.0/gems/highline-1.7.10/lib/highline/system_extensions.rb +0 -254
  159. data/bundle/ruby/2.5.0/gems/highline-1.7.10/setup.rb +0 -1360
@@ -1,16 +0,0 @@
1
- unless STDIN.respond_to? :getbyte
2
- class IO
3
- alias_method :getbyte, :getc
4
- end
5
-
6
- class StringIO
7
- alias_method :getbyte, :getc
8
- end
9
- end
10
-
11
- unless "".respond_to? :each_line
12
- # Not a perfect translation, but sufficient for our needs.
13
- class String
14
- alias_method :each_line, :each
15
- end
16
- end
@@ -1,41 +0,0 @@
1
- # import.rb
2
- #
3
- # Created by James Edward Gray II on 2005-04-26.
4
- # Copyright 2005 Gray Productions. All rights reserved.
5
- #
6
- # This is Free Software. See LICENSE and COPYING for details.
7
-
8
- require "highline"
9
- require "forwardable"
10
-
11
- $terminal = HighLine.new
12
-
13
- #
14
- # <tt>require "highline/import"</tt> adds shortcut methods to Kernel, making
15
- # agree(), ask(), choose() and say() globally available. This is handy for
16
- # quick and dirty input and output. These methods use the HighLine object in
17
- # the global variable <tt>$terminal</tt>, which is initialized to used
18
- # <tt>$stdin</tt> and <tt>$stdout</tt> (you are free to change this).
19
- # Otherwise, these methods are identical to their HighLine counterparts, see that
20
- # class for detailed explanations.
21
- #
22
- module Kernel
23
- extend Forwardable
24
- def_delegators :$terminal, :agree, :ask, :choose, :say
25
- end
26
-
27
- class Object
28
- #
29
- # Tries this object as a _first_answer_ for a HighLine::Question. See that
30
- # attribute for details.
31
- #
32
- # *Warning*: This Object will be passed to String() before set.
33
- #
34
- def or_ask( *args, &details )
35
- ask(*args) do |question|
36
- question.first_answer = String(self) unless nil?
37
-
38
- details.call(question) unless details.nil?
39
- end
40
- end
41
- end
@@ -1,381 +0,0 @@
1
- # menu.rb
2
- #
3
- # Created by Gregory Thomas Brown on 2005-05-10.
4
- # Copyright 2005. All rights reserved.
5
- #
6
- # This is Free Software. See LICENSE and COPYING for details.
7
-
8
- require "highline/question"
9
-
10
- class HighLine
11
- #
12
- # Menu objects encapsulate all the details of a call to HighLine.choose().
13
- # Using the accessors and Menu.choice() and Menu.choices(), the block passed
14
- # to HighLine.choose() can detail all aspects of menu display and control.
15
- #
16
- class Menu < Question
17
- #
18
- # Create an instance of HighLine::Menu. All customization is done
19
- # through the passed block, which should call accessors and choice() and
20
- # choices() as needed to define the Menu. Note that Menus are also
21
- # Questions, so all that functionality is available to the block as
22
- # well.
23
- #
24
- def initialize( )
25
- #
26
- # Initialize Question objects with ignored values, we'll
27
- # adjust ours as needed.
28
- #
29
- super("Ignored", [ ], &nil) # avoiding passing the block along
30
-
31
- @items = [ ]
32
- @hidden_items = [ ]
33
- @help = Hash.new("There's no help for that topic.")
34
-
35
- @index = :number
36
- @index_suffix = ". "
37
- @select_by = :index_or_name
38
- @flow = :rows
39
- @list_option = nil
40
- @header = nil
41
- @prompt = "? "
42
- @layout = :list
43
- @shell = false
44
- @nil_on_handled = false
45
-
46
- # Override Questions responses, we'll set our own.
47
- @responses = { }
48
- # Context for action code.
49
- @highline = nil
50
-
51
- yield self if block_given?
52
-
53
- init_help if @shell and not @help.empty?
54
- end
55
-
56
- #
57
- # An _index_ to append to each menu item in display. See
58
- # Menu.index=() for details.
59
- #
60
- attr_reader :index
61
- #
62
- # The String placed between an _index_ and a menu item. Defaults to
63
- # ". ". Switches to " ", when _index_ is set to a String (like "-").
64
- #
65
- attr_accessor :index_suffix
66
- #
67
- # The _select_by_ attribute controls how the user is allowed to pick a
68
- # menu item. The available choices are:
69
- #
70
- # <tt>:index</tt>:: The user is allowed to type the numerical
71
- # or alphabetical index for their selection.
72
- # <tt>:index_or_name</tt>:: Allows both methods from the
73
- # <tt>:index</tt> option and the
74
- # <tt>:name</tt> option.
75
- # <tt>:name</tt>:: Menu items are selected by typing a portion
76
- # of the item name that will be
77
- # auto-completed.
78
- #
79
- attr_accessor :select_by
80
- #
81
- # This attribute is passed directly on as the mode to HighLine.list() by
82
- # all the preset layouts. See that method for appropriate settings.
83
- #
84
- attr_accessor :flow
85
- #
86
- # This setting is passed on as the third parameter to HighLine.list()
87
- # by all the preset layouts. See that method for details of its
88
- # effects. Defaults to +nil+.
89
- #
90
- attr_accessor :list_option
91
- #
92
- # Used by all the preset layouts to display title and/or introductory
93
- # information, when set. Defaults to +nil+.
94
- #
95
- attr_accessor :header
96
- #
97
- # Used by all the preset layouts to ask the actual question to fetch a
98
- # menu selection from the user. Defaults to "? ".
99
- #
100
- attr_accessor :prompt
101
- #
102
- # An ERb _layout_ to use when displaying this Menu object. See
103
- # Menu.layout=() for details.
104
- #
105
- attr_reader :layout
106
- #
107
- # When set to +true+, responses are allowed to be an entire line of
108
- # input, including details beyond the command itself. Only the first
109
- # "word" of input will be matched against the menu choices, but both the
110
- # command selected and the rest of the line will be passed to provided
111
- # action blocks. Defaults to +false+.
112
- #
113
- attr_accessor :shell
114
- #
115
- # When +true+, any selected item handled by provided action code will
116
- # return +nil+, instead of the results to the action code. This may
117
- # prove handy when dealing with mixed menus where only the names of
118
- # items without any code (and +nil+, of course) will be returned.
119
- # Defaults to +false+.
120
- #
121
- attr_accessor :nil_on_handled
122
-
123
- #
124
- # Adds _name_ to the list of available menu items. Menu items will be
125
- # displayed in the order they are added.
126
- #
127
- # An optional _action_ can be associated with this name and if provided,
128
- # it will be called if the item is selected. The result of the method
129
- # will be returned, unless _nil_on_handled_ is set (when you would get
130
- # +nil+ instead). In _shell_ mode, a provided block will be passed the
131
- # command chosen and any details that followed the command. Otherwise,
132
- # just the command is passed. The <tt>@highline</tt> variable is set to
133
- # the current HighLine context before the action code is called and can
134
- # thus be used for adding output and the like.
135
- #
136
- def choice( name, help = nil, &action )
137
- @items << [name, action]
138
-
139
- @help[name.to_s.downcase] = help unless help.nil?
140
- update_responses # rebuild responses based on our settings
141
- end
142
-
143
- #
144
- # A shortcut for multiple calls to the sister method choice(). <b>Be
145
- # warned:</b> An _action_ set here will apply to *all* provided
146
- # _names_. This is considered to be a feature, so you can easily
147
- # hand-off interface processing to a different chunk of code.
148
- #
149
- def choices( *names, &action )
150
- names.each { |n| choice(n, &action) }
151
- end
152
-
153
- # Identical to choice(), but the item will not be listed for the user.
154
- def hidden( name, help = nil, &action )
155
- @hidden_items << [name, action]
156
-
157
- @help[name.to_s.downcase] = help unless help.nil?
158
- end
159
-
160
- #
161
- # Sets the indexing style for this Menu object. Indexes are appended to
162
- # menu items, when displayed in list form. The available settings are:
163
- #
164
- # <tt>:number</tt>:: Menu items will be indexed numerically, starting
165
- # with 1. This is the default method of indexing.
166
- # <tt>:letter</tt>:: Items will be indexed alphabetically, starting
167
- # with a.
168
- # <tt>:none</tt>:: No index will be appended to menu items.
169
- # <i>any String</i>:: Will be used as the literal _index_.
170
- #
171
- # Setting the _index_ to <tt>:none</tt> or a literal String also adjusts
172
- # _index_suffix_ to a single space and _select_by_ to <tt>:name</tt>.
173
- # Because of this, you should make a habit of setting the _index_ first.
174
- #
175
- def index=( style )
176
- @index = style
177
-
178
- # Default settings.
179
- if @index == :none or @index.is_a?(::String)
180
- @index_suffix = " "
181
- @select_by = :name
182
- end
183
- end
184
-
185
- #
186
- # Initializes the help system by adding a <tt>:help</tt> choice, some
187
- # action code, and the default help listing.
188
- #
189
- def init_help( )
190
- return if @items.include?(:help)
191
-
192
- topics = @help.keys.sort
193
- help_help = @help.include?("help") ? @help["help"] :
194
- "This command will display helpful messages about " +
195
- "functionality, like this one. To see the help for " +
196
- "a specific topic enter:\n\thelp [TOPIC]\nTry asking " +
197
- "for help on any of the following:\n\n" +
198
- "<%= list(#{topics.inspect}, :columns_across) %>"
199
- choice(:help, help_help) do |command, topic|
200
- topic.strip!
201
- topic.downcase!
202
- if topic.empty?
203
- @highline.say(@help["help"])
204
- else
205
- @highline.say("= #{topic}\n\n#{@help[topic]}")
206
- end
207
- end
208
- end
209
-
210
- #
211
- # Used to set help for arbitrary topics. Use the topic <tt>"help"</tt>
212
- # to override the default message.
213
- #
214
- def help( topic, help )
215
- @help[topic] = help
216
- end
217
-
218
- #
219
- # Setting a _layout_ with this method also adjusts some other attributes
220
- # of the Menu object, to ideal defaults for the chosen _layout_. To
221
- # account for that, you probably want to set a _layout_ first in your
222
- # configuration block, if needed.
223
- #
224
- # Accepted settings for _layout_ are:
225
- #
226
- # <tt>:list</tt>:: The default _layout_. The _header_ if set
227
- # will appear at the top on its own line with
228
- # a trailing colon. Then the list of menu
229
- # items will follow. Finally, the _prompt_
230
- # will be used as the ask()-like question.
231
- # <tt>:one_line</tt>:: A shorter _layout_ that fits on one line.
232
- # The _header_ comes first followed by a
233
- # colon and spaces, then the _prompt_ with menu
234
- # items between trailing parenthesis.
235
- # <tt>:menu_only</tt>:: Just the menu items, followed up by a likely
236
- # short _prompt_.
237
- # <i>any ERb String</i>:: Will be taken as the literal _layout_. This
238
- # String can access <tt>@header</tt>,
239
- # <tt>@menu</tt> and <tt>@prompt</tt>, but is
240
- # otherwise evaluated in the typical HighLine
241
- # context, to provide access to utilities like
242
- # HighLine.list() primarily.
243
- #
244
- # If set to either <tt>:one_line</tt>, or <tt>:menu_only</tt>, _index_
245
- # will default to <tt>:none</tt> and _flow_ will default to
246
- # <tt>:inline</tt>.
247
- #
248
- def layout=( new_layout )
249
- @layout = new_layout
250
-
251
- # Default settings.
252
- case @layout
253
- when :one_line, :menu_only
254
- self.index = :none
255
- @flow = :inline
256
- end
257
- end
258
-
259
- #
260
- # This method returns all possible options for auto-completion, based
261
- # on the settings of _index_ and _select_by_.
262
- #
263
- def options( )
264
- # add in any hidden menu commands
265
- @items.concat(@hidden_items)
266
-
267
- by_index = if @index == :letter
268
- l_index = "`"
269
- @items.map { "#{l_index.succ!}" }
270
- else
271
- (1 .. @items.size).collect { |s| String(s) }
272
- end
273
- by_name = @items.collect { |c| c.first }
274
-
275
- case @select_by
276
- when :index then
277
- by_index
278
- when :name
279
- by_name
280
- else
281
- by_index + by_name
282
- end
283
- ensure
284
- # make sure the hidden items are removed, before we return
285
- @items.slice!(@items.size - @hidden_items.size, @hidden_items.size)
286
- end
287
-
288
- #
289
- # This method processes the auto-completed user selection, based on the
290
- # rules for this Menu object. If an action was provided for the
291
- # selection, it will be executed as described in Menu.choice().
292
- #
293
- def select( highline_context, selection, details = nil )
294
- # add in any hidden menu commands
295
- @items.concat(@hidden_items)
296
-
297
- # Find the selected action.
298
- name, action = if selection =~ /^\d+$/
299
- @items[selection.to_i - 1]
300
- else
301
- l_index = "`"
302
- index = @items.map { "#{l_index.succ!}" }.index(selection)
303
- @items.find { |c| c.first == selection } or @items[index]
304
- end
305
-
306
- # Run or return it.
307
- if not action.nil?
308
- @highline = highline_context
309
- if @shell
310
- result = action.call(name, details)
311
- else
312
- result = action.call(name)
313
- end
314
- @nil_on_handled ? nil : result
315
- elsif action.nil?
316
- name
317
- else
318
- nil
319
- end
320
- ensure
321
- # make sure the hidden items are removed, before we return
322
- @items.slice!(@items.size - @hidden_items.size, @hidden_items.size)
323
- end
324
-
325
- #
326
- # Allows Menu objects to pass as Arrays, for use with HighLine.list().
327
- # This method returns all menu items to be displayed, complete with
328
- # indexes.
329
- #
330
- def to_ary( )
331
- case @index
332
- when :number
333
- @items.map { |c| "#{@items.index(c) + 1}#{@index_suffix}#{c.first}" }
334
- when :letter
335
- l_index = "`"
336
- @items.map { |c| "#{l_index.succ!}#{@index_suffix}#{c.first}" }
337
- when :none
338
- @items.map { |c| "#{c.first}" }
339
- else
340
- @items.map { |c| "#{index}#{@index_suffix}#{c.first}" }
341
- end
342
- end
343
-
344
- #
345
- # Allows Menu to behave as a String, just like Question. Returns the
346
- # _layout_ to be rendered, which is used by HighLine.say().
347
- #
348
- def to_s( )
349
- case @layout
350
- when :list
351
- '<%= if @header.nil? then '' else "#{@header}:\n" end %>' +
352
- "<%= list( @menu, #{@flow.inspect},
353
- #{@list_option.inspect} ) %>" +
354
- "<%= @prompt %>"
355
- when :one_line
356
- '<%= if @header.nil? then '' else "#{@header}: " end %>' +
357
- "<%= @prompt %>" +
358
- "(<%= list( @menu, #{@flow.inspect},
359
- #{@list_option.inspect} ) %>)" +
360
- "<%= @prompt[/\s*$/] %>"
361
- when :menu_only
362
- "<%= list( @menu, #{@flow.inspect},
363
- #{@list_option.inspect} ) %><%= @prompt %>"
364
- else
365
- @layout
366
- end
367
- end
368
-
369
- #
370
- # This method will update the intelligent responses to account for
371
- # Menu specific differences. Calls the superclass' (Question's)
372
- # build_responses method, overriding its default arguments to specify
373
- # 'options' will be used to populate choice lists, and that
374
- # the newly built hash will predominate over the preexisting hash
375
- # for any keys that are the same.
376
- #
377
- def update_responses( )
378
- build_responses(options, true)
379
- end
380
- end
381
- end
@@ -1,48 +0,0 @@
1
- # simulate.rb
2
- #
3
- # Created by Andy Rossmeissl on 2012-04-29.
4
- # Copyright 2005 Gray Productions. All rights reserved.
5
- #
6
- # This is Free Software. See LICENSE and COPYING for details.
7
- #
8
- # adapted from https://gist.github.com/194554
9
- class HighLine
10
-
11
- # Simulates Highline input for use in tests.
12
- class Simulate
13
-
14
- # Creates a simulator with an array of Strings as a script
15
- def initialize(strings)
16
- @strings = strings
17
- end
18
-
19
- # Simulate StringIO#gets by shifting a string off of the script
20
- def gets
21
- @strings.shift
22
- end
23
-
24
- # Simulate StringIO#getbyte by shifting a single character off of the next line of the script
25
- def getbyte
26
- line = gets.dup
27
- if line.length > 0
28
- char = line.slice! 0
29
- @strings.unshift line
30
- char
31
- end
32
- end
33
-
34
- # The simulator handles its own EOF
35
- def eof?
36
- false
37
- end
38
-
39
- # A wrapper method that temporarily replaces the Highline instance in $terminal with an instance of this object for the duration of the block
40
- def self.with(*strings)
41
- @input = $terminal.instance_variable_get :@input
42
- $terminal.instance_variable_set :@input, new(strings)
43
- yield
44
- ensure
45
- $terminal.instance_variable_set :@input, @input
46
- end
47
- end
48
- end