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
@@ -0,0 +1,129 @@
1
+ # coding: utf-8
2
+
3
+ class HighLine
4
+ # Builtin Styles that are included at HighLine initialization.
5
+ # It has the basic styles like :bold and :underline.
6
+ module BuiltinStyles
7
+ # Included callback
8
+ # @param base [Class, Module] base class
9
+ def self.included(base)
10
+ base.extend ClassMethods
11
+ end
12
+
13
+ # Basic styles' ANSI escape codes like :bold => "\e[1m"
14
+ STYLE_LIST = {
15
+ erase_line: "\e[K",
16
+ erase_char: "\e[P",
17
+ clear: "\e[0m",
18
+ reset: "\e[0m",
19
+ bold: "\e[1m",
20
+ dark: "\e[2m",
21
+ underline: "\e[4m",
22
+ underscore: "\e[4m",
23
+ blink: "\e[5m",
24
+ reverse: "\e[7m",
25
+ concealed: "\e[8m"
26
+ }.freeze
27
+
28
+ STYLE_LIST.each do |style_name, code|
29
+ style = String(style_name).upcase
30
+
31
+ const_set style, code
32
+ const_set style + "_STYLE",
33
+ Style.new(name: style_name, code: code, builtin: true)
34
+ end
35
+
36
+ # Basic Style names like CLEAR, BOLD, UNDERLINE
37
+ STYLES = %w[CLEAR RESET BOLD DARK UNDERLINE
38
+ UNDERSCORE BLINK REVERSE CONCEALED].freeze
39
+
40
+ # A Hash with the basic colors an their ANSI escape codes.
41
+ COLOR_LIST = {
42
+ black: { code: "\e[30m", rgb: [0, 0, 0] },
43
+ red: { code: "\e[31m", rgb: [128, 0, 0] },
44
+ green: { code: "\e[32m", rgb: [0, 128, 0] },
45
+ blue: { code: "\e[34m", rgb: [0, 0, 128] },
46
+ yellow: { code: "\e[33m", rgb: [128, 128, 0] },
47
+ magenta: { code: "\e[35m", rgb: [128, 0, 128] },
48
+ cyan: { code: "\e[36m", rgb: [0, 128, 128] },
49
+ white: { code: "\e[37m", rgb: [192, 192, 192] },
50
+ gray: { code: "\e[37m", rgb: [192, 192, 192] },
51
+ grey: { code: "\e[37m", rgb: [192, 192, 192] },
52
+ none: { code: "\e[38m", rgb: [0, 0, 0] }
53
+ }.freeze
54
+
55
+ COLOR_LIST.each do |color_name, attributes|
56
+ color = String(color_name).upcase
57
+
58
+ style = Style.new(
59
+ name: color_name,
60
+ code: attributes[:code],
61
+ rgb: attributes[:rgb],
62
+ builtin: true
63
+ )
64
+
65
+ const_set color + "_STYLE", style
66
+ end
67
+
68
+ # The builtin styles basic colors like black, red, green.
69
+ BASIC_COLORS =
70
+ %w[BLACK RED GREEN YELLOW BLUE
71
+ MAGENTA CYAN WHITE GRAY GREY NONE].freeze
72
+
73
+ colors = BASIC_COLORS.dup
74
+ BASIC_COLORS.each do |color|
75
+ bright_color = "BRIGHT_#{color}"
76
+ colors << bright_color
77
+ const_set bright_color + "_STYLE", const_get(color + "_STYLE").bright
78
+
79
+ light_color = "LIGHT_#{color}"
80
+ colors << light_color
81
+ const_set light_color + "_STYLE", const_get(color + "_STYLE").light
82
+ end
83
+
84
+ # The builtin styles' colors like LIGHT_RED and BRIGHT_BLUE.
85
+ COLORS = colors
86
+
87
+ colors.each do |color|
88
+ const_set color, const_get("#{color}_STYLE").code
89
+ const_set "ON_#{color}_STYLE", const_get("#{color}_STYLE").on
90
+ const_set "ON_#{color}", const_get("ON_#{color}_STYLE").code
91
+ end
92
+
93
+ ON_NONE_STYLE.rgb = [255, 255, 255] # Override; white background
94
+
95
+ # BuiltinStyles class methods to be extended.
96
+ module ClassMethods
97
+ # Regexp to match against RGB style constant names.
98
+ RGB_COLOR_PATTERN = /^(ON_)?(RGB_)([A-F0-9]{6})(_STYLE)?$/
99
+
100
+ # const_missing callback for automatically respond to
101
+ # builtin constants (without explicitly defining them)
102
+ # @param name [Symbol] missing constant name
103
+ def const_missing(name)
104
+ raise NameError, "Bad color or uninitialized constant #{name}" unless
105
+ name.to_s =~ RGB_COLOR_PATTERN
106
+
107
+ on = Regexp.last_match(1)
108
+ suffix = Regexp.last_match(4)
109
+
110
+ code_name = if suffix
111
+ Regexp.last_match(1).to_s +
112
+ Regexp.last_match(2) +
113
+ Regexp.last_match(3)
114
+ else
115
+ name.to_s
116
+ end
117
+
118
+ style_name = code_name + "_STYLE"
119
+ style = Style.rgb(Regexp.last_match(3))
120
+ style = style.on if on
121
+
122
+ const_set(style_name, style)
123
+ const_set(code_name, style.code)
124
+
125
+ suffix ? style : style.code
126
+ end
127
+ end
128
+ end
129
+ end
@@ -1,3 +1,6 @@
1
+ # coding: utf-8
2
+
3
+ #--
1
4
  # color_scheme.rb
2
5
  #
3
6
  # Created by Jeremy Hinegardner on 2007-01-24
@@ -8,16 +11,15 @@
8
11
  class HighLine
9
12
  #
10
13
  # ColorScheme objects encapsulate a named set of colors to be used in the
11
- # HighLine.colors() method call. For example, by applying a ColorScheme that
14
+ # {HighLine.color} method call. For example, by applying a ColorScheme that
12
15
  # has a <tt>:warning</tt> color then the following could be used:
13
16
  #
14
- # colors("This is a warning", :warning)
17
+ # color("This is a warning", :warning)
15
18
  #
16
19
  # A ColorScheme contains named sets of HighLine color constants.
17
20
  #
18
- # Example: Instantiating a color scheme, applying it to HighLine,
19
- # and using it:
20
- #
21
+ # @example Instantiating a color scheme, applying it to HighLine,
22
+ # and using it:
21
23
  # ft = HighLine::ColorScheme.new do |cs|
22
24
  # cs[:headline] = [ :bold, :yellow, :on_black ]
23
25
  # cs[:horizontal_line] = [ :bold, :white ]
@@ -46,63 +48,78 @@ class HighLine
46
48
  # converted to <tt>:symbols</tt> and values are converted to HighLine
47
49
  # constants.
48
50
  #
49
- def initialize( h = nil )
50
- @scheme = Hash.new
51
- load_from_hash(h) unless h.nil?
51
+ # @param h [Hash]
52
+ def initialize(h = nil)
53
+ @scheme = {}
54
+ load_from_hash(h) if h
52
55
  yield self if block_given?
53
56
  end
54
57
 
55
58
  # Load multiple colors from key/value pairs.
56
- def load_from_hash( h )
59
+ # @param h [Hash]
60
+ def load_from_hash(h)
57
61
  h.each_pair do |color_tag, constants|
58
62
  self[color_tag] = constants
59
63
  end
60
64
  end
61
65
 
62
66
  # Does this color scheme include the given tag name?
63
- def include?( color_tag )
67
+ # @param color_tag [#to_sym]
68
+ # @return [Boolean]
69
+ def include?(color_tag)
64
70
  @scheme.keys.include?(to_symbol(color_tag))
65
71
  end
66
72
 
67
73
  # Allow the scheme to be accessed like a Hash.
68
- def []( color_tag )
74
+ # @param color_tag [#to_sym]
75
+ # @return [Style]
76
+ def [](color_tag)
69
77
  @scheme[to_symbol(color_tag)]
70
78
  end
71
79
 
72
80
  # Retrieve the original form of the scheme
73
- def definition( color_tag )
81
+ # @param color_tag [#to_sym]
82
+ def definition(color_tag)
74
83
  style = @scheme[to_symbol(color_tag)]
75
84
  style && style.list
76
85
  end
77
86
 
78
87
  # Retrieve the keys in the scheme
88
+ # @return [Array] of keys
79
89
  def keys
80
90
  @scheme.keys
81
91
  end
82
92
 
83
93
  # Allow the scheme to be set like a Hash.
84
- def []=( color_tag, constants )
85
- @scheme[to_symbol(color_tag)] = HighLine::Style.new(:name=>color_tag.to_s.downcase.to_sym,
86
- :list=>constants, :no_index=>true)
94
+ # @param color_tag [#to_sym]
95
+ # @param constants [Array<Symbol>] Array of Style symbols
96
+ def []=(color_tag, constants)
97
+ @scheme[to_symbol(color_tag)] =
98
+ HighLine::Style.new(name: color_tag.to_s.downcase.to_sym,
99
+ list: constants,
100
+ no_index: true)
87
101
  end
88
102
 
89
103
  # Retrieve the color scheme hash (in original definition format)
104
+ # @return [Hash] scheme as Hash. It may be reused in a new ColorScheme.
90
105
  def to_hash
91
- @scheme.inject({}) { |hsh, pair| key, value = pair; hsh[key] = value.list; hsh }
106
+ @scheme.each_with_object({}) do |pair, hsh|
107
+ key, value = pair
108
+ hsh[key] = value.list
109
+ end
92
110
  end
93
111
 
94
-
95
112
  private
96
113
 
97
114
  # Return a normalized representation of a color name.
98
- def to_symbol( t )
115
+ def to_symbol(t)
99
116
  t.to_s.downcase
100
117
  end
101
118
 
102
119
  # Return a normalized representation of a color setting.
103
- def to_constant( v )
120
+ def to_constant(v)
104
121
  v = v.to_s if v.is_a?(Symbol)
105
- if v.is_a?(::String) then
122
+ if v.is_a?(::String)
106
123
  HighLine.const_get(v.upcase)
107
124
  else
108
125
  v
@@ -112,23 +129,23 @@ class HighLine
112
129
 
113
130
  # A sample ColorScheme.
114
131
  class SampleColorScheme < ColorScheme
132
+ SAMPLE_SCHEME = {
133
+ critical: [:yellow, :on_red],
134
+ error: [:bold, :red],
135
+ warning: [:bold, :yellow],
136
+ notice: [:bold, :magenta],
137
+ info: [:bold, :cyan],
138
+ debug: [:bold, :green],
139
+ row_even: [:cyan],
140
+ row_odd: [:magenta]
141
+ }.freeze
115
142
  #
116
143
  # Builds the sample scheme with settings for <tt>:critical</tt>,
117
144
  # <tt>:error</tt>, <tt>:warning</tt>, <tt>:notice</tt>, <tt>:info</tt>,
118
145
  # <tt>:debug</tt>, <tt>:row_even</tt>, and <tt>:row_odd</tt> colors.
119
146
  #
120
- def initialize( h = nil )
121
- scheme = {
122
- :critical => [ :yellow, :on_red ],
123
- :error => [ :bold, :red ],
124
- :warning => [ :bold, :yellow ],
125
- :notice => [ :bold, :magenta ],
126
- :info => [ :bold, :cyan ],
127
- :debug => [ :bold, :green ],
128
- :row_even => [ :cyan ],
129
- :row_odd => [ :magenta ]
130
- }
131
- super(scheme)
147
+ def initialize(_h = nil)
148
+ super(SAMPLE_SCHEME)
132
149
  end
133
150
  end
134
151
  end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+
3
+ unless STDIN.respond_to? :getbyte
4
+ # HighLine adds #getbyte alias to #getc when #getbyte is not available.
5
+ class IO
6
+ # alias to #getc when #getbyte is not available
7
+ alias getbyte getc
8
+ end
9
+
10
+ # HighLine adds #getbyte alias to #getc when #getbyte is not available.
11
+ class StringIO
12
+ # alias to #getc when #getbyte is not available
13
+ alias getbyte getc
14
+ end
15
+ end
16
+
17
+ unless "".respond_to? :each_line
18
+ # HighLine adds #each_line alias to #each when each_line is not available.
19
+ class String
20
+ # alias to #each when each_line is not available.
21
+ alias each_line each
22
+ end
23
+ end
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+
3
+ class HighLine
4
+ # Internal HighLine errors.
5
+ module CustomErrors
6
+ # An error that responds to :explanation_key
7
+ class ExplainableError < StandardError
8
+ # Explanation key as Symbol or nil. Used to
9
+ # select the proper error message to be displayed.
10
+ # @return [nil, Symbol] explanation key to get the
11
+ # proper error message.
12
+ def explanation_key
13
+ nil
14
+ end
15
+ end
16
+
17
+ # Bare Question error
18
+ class QuestionError < ExplainableError
19
+ # (see ExplainableError#explanation_key)
20
+ def explanation_key
21
+ nil
22
+ end
23
+ end
24
+
25
+ # Invalid Question error
26
+ class NotValidQuestionError < ExplainableError
27
+ # (see ExplainableError#explanation_key)
28
+ def explanation_key
29
+ :not_valid
30
+ end
31
+ end
32
+
33
+ # Out of Range Question error
34
+ class NotInRangeQuestionError < ExplainableError
35
+ # (see ExplainableError#explanation_key)
36
+ def explanation_key
37
+ :not_in_range
38
+ end
39
+ end
40
+
41
+ # Unconfirmed Question error
42
+ class NoConfirmationQuestionError < ExplainableError
43
+ # (see ExplainableError#explanation_key)
44
+ def explanation_key
45
+ nil
46
+ end
47
+ end
48
+
49
+ # Unavailable auto complete error
50
+ class NoAutoCompleteMatch < ExplainableError
51
+ # (see ExplainableError#explanation_key)
52
+ def explanation_key
53
+ :no_completion
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,48 @@
1
+ # coding: utf-8
2
+
3
+ # import.rb
4
+ #
5
+ # Created by James Edward Gray II on 2005-04-26.
6
+ # Copyright 2005 Gray Productions. All rights reserved.
7
+ #
8
+ # This is Free Software. See LICENSE and COPYING for details.
9
+
10
+ require "highline"
11
+ require "forwardable"
12
+
13
+ #
14
+ # <tt>require "highline/import"</tt> adds shortcut methods to Kernel, making
15
+ # {HighLine#agree}, {HighLine#ask}, {HighLine#choose} and {HighLine#say}
16
+ # globally available. This is handy for
17
+ # quick and dirty input and output. These methods use HighLine.default_instance
18
+ # which is initialized to use <tt>$stdin</tt> and <tt>$stdout</tt> (you are free
19
+ # to change this).
20
+ # Otherwise, these methods are identical to their {HighLine} counterparts,
21
+ # see that class for detailed explanations.
22
+ #
23
+ module Kernel
24
+ extend Forwardable
25
+ def_instance_delegators :HighLine, :agree, :ask, :choose, :say
26
+ end
27
+
28
+ # When requiring 'highline/import' HighLine adds {#or_ask} to Object so
29
+ # it is globally available.
30
+ class Object
31
+ #
32
+ # Tries this object as a _first_answer_ for a HighLine::Question. See that
33
+ # attribute for details.
34
+ #
35
+ # *Warning*: This Object will be passed to String() before set.
36
+ #
37
+ # @param args [Array<#to_s>]
38
+ # @param details [lambda] block to be called with the question
39
+ # instance as argument.
40
+ # @return [String] answer
41
+ def or_ask(*args, &details)
42
+ ask(*args) do |question|
43
+ question.first_answer = String(self)
44
+
45
+ yield(question) if details
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+
3
+ require "stringio"
4
+ require "tempfile"
5
+
6
+ #
7
+ # On tests, we try to simulate input output with
8
+ # StringIO, Tempfile and File objects.
9
+ #
10
+ # For this to be accomplished, we have to do some
11
+ # tweaking so that they respond adequately to the
12
+ # called methods during tests.
13
+ #
14
+
15
+ module IOConsoleCompatible
16
+ def getch
17
+ getc
18
+ end
19
+
20
+ attr_accessor :echo
21
+
22
+ def winsize
23
+ [24, 80]
24
+ end
25
+ end
26
+
27
+ class Tempfile
28
+ include IOConsoleCompatible
29
+ end
30
+
31
+ class File
32
+ include IOConsoleCompatible
33
+ end
34
+
35
+ class StringIO
36
+ include IOConsoleCompatible
37
+ end