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,103 @@
1
+ # coding: utf-8
2
+
3
+ require "forwardable"
4
+
5
+ class HighLine
6
+ class Question
7
+ # It provides all answer conversion flow.
8
+ class AnswerConverter
9
+ extend Forwardable
10
+
11
+ def_delegators :@question,
12
+ :answer, :answer=, :check_range,
13
+ :directory, :answer_type, :choices_complete
14
+
15
+ # It should be initialized with a Question object.
16
+ # The class will get the answer from {Question#answer}
17
+ # and then convert it to the proper {Question#answer_type}.
18
+ # It is mainly used by {Question#convert}
19
+ #
20
+ # @param question [Question]
21
+ def initialize(question)
22
+ @question = question
23
+ end
24
+
25
+ # Based on the given Question object's settings,
26
+ # it makes the conversion and returns the answer.
27
+ # @return [Object] the converted answer.
28
+ def convert
29
+ return unless answer_type
30
+
31
+ self.answer = convert_by_answer_type
32
+ check_range
33
+ answer
34
+ end
35
+
36
+ # @return [HighLine::String] answer converted to a HighLine::String
37
+ def to_string
38
+ HighLine::String(answer)
39
+ end
40
+
41
+ # That's a weird name for a method!
42
+ # But it's working ;-)
43
+ define_method "to_highline::string" do
44
+ HighLine::String(answer)
45
+ end
46
+
47
+ # @return [Integer] answer converted to an Integer
48
+ def to_integer
49
+ Kernel.send(:Integer, answer)
50
+ end
51
+
52
+ # @return [Float] answer converted to a Float
53
+ def to_float
54
+ Kernel.send(:Float, answer)
55
+ end
56
+
57
+ # @return [Symbol] answer converted to an Symbol
58
+ def to_symbol
59
+ answer.to_sym
60
+ end
61
+
62
+ # @return [Regexp] answer converted to a Regexp
63
+ def to_regexp
64
+ Regexp.new(answer)
65
+ end
66
+
67
+ # @return [File] answer converted to a File
68
+ def to_file
69
+ self.answer = choices_complete(answer)
70
+ File.open(File.join(directory.to_s, answer.last))
71
+ end
72
+
73
+ # @return [Pathname] answer converted to an Pathname
74
+ def to_pathname
75
+ self.answer = choices_complete(answer)
76
+ Pathname.new(File.join(directory.to_s, answer.last))
77
+ end
78
+
79
+ # @return [Array] answer converted to an Array
80
+ def to_array
81
+ self.answer = choices_complete(answer)
82
+ answer.last
83
+ end
84
+
85
+ # @return [Proc] answer converted to an Proc
86
+ def to_proc
87
+ answer_type.call(answer)
88
+ end
89
+
90
+ private
91
+
92
+ def convert_by_answer_type
93
+ if answer_type.respond_to? :parse
94
+ answer_type.parse(answer)
95
+ elsif answer_type.is_a? Class
96
+ send("to_#{answer_type.name.downcase}")
97
+ else
98
+ send("to_#{answer_type.class.name.downcase}")
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,150 @@
1
+ # encoding: utf-8
2
+
3
+ class HighLine
4
+ # Deals with the task of "asking" a question
5
+ class QuestionAsker
6
+ # @return [Question] question to be asked
7
+ attr_reader :question
8
+
9
+ include CustomErrors
10
+
11
+ # To do its work QuestionAsker needs a Question
12
+ # to be asked and a HighLine context where to
13
+ # direct output.
14
+ #
15
+ # @param question [Question] question to be asked
16
+ # @param highline [HighLine] context
17
+ def initialize(question, highline)
18
+ @question = question
19
+ @highline = highline
20
+ end
21
+
22
+ #
23
+ # Gets just one answer, as opposed to #gather_answers
24
+ #
25
+ # @return [String] answer
26
+ def ask_once
27
+ question.show_question(@highline)
28
+
29
+ begin
30
+ question.get_response_or_default(@highline)
31
+ raise NotValidQuestionError unless question.valid_answer?
32
+
33
+ question.convert
34
+
35
+ if question.confirm
36
+ confirmation = @highline.send(:confirm, question)
37
+ raise NoConfirmationQuestionError unless confirmation
38
+ end
39
+ rescue ExplainableError => e
40
+ explain_error(e.explanation_key)
41
+ retry
42
+ rescue ArgumentError => error
43
+ case error.message
44
+ when /ambiguous/
45
+ # the assumption here is that OptionParser::Completion#complete
46
+ # (used for ambiguity resolution) throws exceptions containing
47
+ # the word 'ambiguous' whenever resolution fails
48
+ explain_error(:ambiguous_completion)
49
+ retry
50
+ when /invalid value for/
51
+ explain_error(:invalid_type)
52
+ retry
53
+ else
54
+ raise
55
+ end
56
+ end
57
+
58
+ question.answer
59
+ end
60
+
61
+ ## Multiple questions
62
+
63
+ #
64
+ # Collects an Array/Hash full of answers as described in
65
+ # HighLine::Question.gather().
66
+ #
67
+ # @return [Array, Hash] answers
68
+ def gather_answers
69
+ verify_match = question.verify_match
70
+ answers = []
71
+
72
+ # when verify_match is set this loop will repeat until unique_answers == 1
73
+ loop do
74
+ answers = gather_answers_based_on_type
75
+
76
+ break unless verify_match &&
77
+ (@highline.send(:unique_answers, answers).size > 1)
78
+
79
+ explain_error(:mismatch)
80
+ end
81
+
82
+ verify_match ? @highline.send(:last_answer, answers) : answers
83
+ end
84
+
85
+ # Gather multiple integer values based on {Question#gather} count
86
+ # @return [Array] answers
87
+ def gather_integer
88
+ gather_with_array do |answers|
89
+ (question.gather - 1).times { answers << ask_once }
90
+ end
91
+ end
92
+
93
+ # Gather multiple values until any of them matches the
94
+ # {Question#gather} Regexp.
95
+ # @return [Array] answers
96
+ def gather_regexp
97
+ gather_with_array do |answers|
98
+ answers << ask_once until answer_matches_regex(answers.last)
99
+ answers.pop
100
+ end
101
+ end
102
+
103
+ # Gather multiple values and store them on a Hash
104
+ # with keys provided by the Hash on {Question#gather}
105
+ # @return [Hash]
106
+ def gather_hash
107
+ sorted_keys = question.gather.keys.sort_by(&:to_s)
108
+ sorted_keys.each_with_object({}) do |key, answers|
109
+ @highline.key = key
110
+ answers[key] = ask_once
111
+ end
112
+ end
113
+
114
+ private
115
+
116
+ ## Delegate to Highline
117
+ def explain_error(explanation_key) # eg: :not_valid, :not_in_range
118
+ @highline.say(question.final_response(explanation_key))
119
+ @highline.say(question.ask_on_error_msg)
120
+ end
121
+
122
+ def gather_with_array
123
+ [].tap do |answers|
124
+ answers << ask_once
125
+ question.template = ""
126
+
127
+ yield answers
128
+ end
129
+ end
130
+
131
+ def answer_matches_regex(answer)
132
+ if question.gather.is_a?(::String) || question.gather.is_a?(Symbol)
133
+ answer.to_s == question.gather.to_s
134
+ elsif question.gather.is_a?(Regexp)
135
+ answer.to_s =~ question.gather
136
+ end
137
+ end
138
+
139
+ def gather_answers_based_on_type
140
+ case question.gather
141
+ when Integer
142
+ gather_integer
143
+ when ::String, Symbol, Regexp
144
+ gather_regexp
145
+ when Hash
146
+ gather_hash
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,59 @@
1
+ # coding: utf-8
2
+
3
+ #--
4
+ # simulate.rb
5
+ #
6
+ # Created by Andy Rossmeissl on 2012-04-29.
7
+ # Copyright 2005 Gray Productions. All rights reserved.
8
+ #
9
+ # This is Free Software. See LICENSE and COPYING for details.
10
+ #
11
+ # adapted from https://gist.github.com/194554
12
+
13
+ class HighLine
14
+ # Simulates Highline input for use in tests.
15
+ class Simulate
16
+ # Creates a simulator with an array of Strings as a script
17
+ # @param strings [Array<String>] preloaded string to be used
18
+ # as input buffer when simulating.
19
+ def initialize(strings)
20
+ @strings = strings
21
+ end
22
+
23
+ # Simulate StringIO#gets by shifting a string off of the script
24
+ def gets
25
+ @strings.shift
26
+ end
27
+
28
+ # Simulate StringIO#getbyte by shifting a single character off of
29
+ # the next line of the script
30
+ def getbyte
31
+ line = gets
32
+ return if line.empty?
33
+
34
+ char = line.slice! 0
35
+ @strings.unshift line
36
+ char
37
+ end
38
+
39
+ # The simulator handles its own EOF
40
+ def eof?
41
+ false
42
+ end
43
+
44
+ # A wrapper method that temporarily replaces the Highline
45
+ # instance in HighLine.default_instance with an instance of this object
46
+ # for the duration of the block
47
+ #
48
+ # @param strings [String] preloaded string buffer that
49
+ # will feed the input operations when simulating.
50
+
51
+ def self.with(*strings)
52
+ @input = HighLine.default_instance.instance_variable_get :@input
53
+ HighLine.default_instance.instance_variable_set :@input, new(strings)
54
+ yield
55
+ ensure
56
+ HighLine.default_instance.instance_variable_set :@input, @input
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,88 @@
1
+ # coding: utf-8
2
+
3
+ require "highline/wrapper"
4
+ require "highline/paginator"
5
+ require "highline/template_renderer"
6
+
7
+ class HighLine
8
+ # This class handles proper formatting based
9
+ # on a HighLine context, applying wrapping,
10
+ # pagination, indentation and color rendering
11
+ # when necessary. It's used by {HighLine#render_statement}
12
+ # @see HighLine#render_statement
13
+ class Statement
14
+ # The source object to be stringfied and formatted.
15
+ attr_reader :source
16
+
17
+ # The HighLine context
18
+ # @return [HighLine]
19
+ attr_reader :highline
20
+
21
+ # The stringfied source object
22
+ # @return [String]
23
+ attr_reader :template_string
24
+
25
+ # It needs the input String and the HighLine context
26
+ # @param source [#to_s]
27
+ # @param highline [HighLine] context
28
+ def initialize(source, highline)
29
+ @highline = highline
30
+ @source = source
31
+ @template_string = stringfy(source)
32
+ end
33
+
34
+ # Returns the formated statement.
35
+ # Applies wrapping, pagination, indentation and color rendering
36
+ # based on HighLine instance settings.
37
+ # @return [String] formated statement
38
+ def statement
39
+ @statement ||= format_statement
40
+ end
41
+
42
+ # (see #statement)
43
+ # Delegates to {#statement}
44
+ def to_s
45
+ statement
46
+ end
47
+
48
+ def self.const_missing(constant)
49
+ HighLine.const_get(constant)
50
+ end
51
+
52
+ private
53
+
54
+ def stringfy(template_string)
55
+ String(template_string || "").dup
56
+ end
57
+
58
+ def format_statement
59
+ return template_string if template_string.empty?
60
+
61
+ statement = render_template
62
+
63
+ statement = HighLine::Wrapper.wrap(statement, highline.wrap_at)
64
+ statement = HighLine::Paginator.new(highline).page_print(statement)
65
+
66
+ statement = statement.gsub(/\n(?!$)/, "\n#{highline.indentation}") if
67
+ highline.multi_indent
68
+
69
+ statement
70
+ end
71
+
72
+ def render_template
73
+ # Assigning to a local var so it may be
74
+ # used inside instance eval block
75
+
76
+ template_renderer = TemplateRenderer.new(template, source, highline)
77
+ template_renderer.render
78
+ end
79
+
80
+ def template
81
+ @template ||= if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
82
+ ERB.new(template_string, trim_mode: "%")
83
+ else
84
+ ERB.new(template_string, nil, "%")
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+
3
+ require "highline/string_extensions"
4
+
5
+ class HighLine
6
+ #
7
+ # HighLine::String is a subclass of String with convenience methods added
8
+ # for colorization.
9
+ #
10
+ # Available convenience methods include:
11
+ # * 'color' method e.g. highline_string.color(:bright_blue,
12
+ # :underline)
13
+ # * colors e.g. highline_string.magenta
14
+ # * RGB colors e.g. highline_string.rgb_ff6000
15
+ # or highline_string.rgb(255,96,0)
16
+ # * background colors e.g. highline_string.on_magenta
17
+ # * RGB background colors e.g. highline_string.on_rgb_ff6000
18
+ # or highline_string.on_rgb(255,96,0)
19
+ # * styles e.g. highline_string.underline
20
+ #
21
+ # Additionally, convenience methods can be chained, for instance the
22
+ # following are equivalent:
23
+ # highline_string.bright_blue.blink.underline
24
+ # highline_string.color(:bright_blue, :blink, :underline)
25
+ # HighLine.color(highline_string, :bright_blue, :blink, :underline)
26
+ #
27
+ # For those less squeamish about possible conflicts, the same convenience
28
+ # methods can be added to the built-in String class, as follows:
29
+ #
30
+ # require 'highline'
31
+ # Highline.colorize_strings
32
+ #
33
+ class String < ::String
34
+ include StringExtensions
35
+ end
36
+ end
@@ -0,0 +1,130 @@
1
+ # coding: utf-8
2
+
3
+ class HighLine #:nodoc:
4
+ # Returns a HighLine::String from any given String.
5
+ # @param s [String]
6
+ # @return [HighLine::String] from the given string.
7
+ def self.String(s) # rubocop:disable Naming/MethodName
8
+ HighLine::String.new(s)
9
+ end
10
+
11
+ # HighLine extensions for String class.
12
+ # Included by HighLine::String.
13
+ module StringExtensions
14
+ STYLE_METHOD_NAME_PATTERN = /^(on_)?rgb_([0-9a-fA-F]{6})$/
15
+
16
+ # Included hook. Actions to take when being included.
17
+ # @param base [Class, Module] base class
18
+ def self.included(base)
19
+ define_builtin_style_methods(base)
20
+ define_style_support_methods(base)
21
+ end
22
+
23
+ # At include time, it defines all basic style
24
+ # support method like #color, #on, #uncolor,
25
+ # #rgb, #on_rgb and the #method_missing callback
26
+ # @return [void]
27
+ # @param base [Class, Module] the base class/module
28
+ #
29
+ def self.define_style_support_methods(base)
30
+ base.class_eval do
31
+ undef :color if method_defined? :color
32
+ undef :foreground if method_defined? :foreground
33
+ def color(*args)
34
+ self.class.new(HighLine.color(self, *args))
35
+ end
36
+ alias_method :foreground, :color
37
+
38
+ undef :on if method_defined? :on
39
+ def on(arg)
40
+ color(("on_" + arg.to_s).to_sym)
41
+ end
42
+
43
+ undef :uncolor if method_defined? :uncolor
44
+ def uncolor
45
+ self.class.new(HighLine.uncolor(self))
46
+ end
47
+
48
+ undef :rgb if method_defined? :rgb
49
+ def rgb(*colors)
50
+ color_code = setup_color_code(*colors)
51
+ color("rgb_#{color_code}".to_sym)
52
+ end
53
+
54
+ undef :on_rgb if method_defined? :on_rgb
55
+ def on_rgb(*colors)
56
+ color_code = setup_color_code(*colors)
57
+ color("on_rgb_#{color_code}".to_sym)
58
+ end
59
+
60
+ # @todo Chain existing method_missing?
61
+ undef :method_missing if method_defined? :method_missing
62
+ def method_missing(method, *_args)
63
+ if method.to_s =~ STYLE_METHOD_NAME_PATTERN
64
+ color(method)
65
+ else
66
+ super
67
+ end
68
+ end
69
+
70
+ undef :respond_to_missing if method_defined? :respond_to_missing
71
+ def respond_to_missing?(method_name, include_private = false)
72
+ method_name.to_s =~ STYLE_METHOD_NAME_PATTERN || super
73
+ end
74
+
75
+ private
76
+
77
+ def setup_color_code(*colors)
78
+ color_code = colors.map do |color|
79
+ if color.is_a?(Numeric)
80
+ format("%02x", color)
81
+ else
82
+ color.to_s
83
+ end
84
+ end.join
85
+
86
+ raise "Bad RGB color #{colors.inspect}" unless
87
+ color_code =~ /^[a-fA-F0-9]{6}/
88
+
89
+ color_code
90
+ end
91
+ end
92
+ end
93
+
94
+ # At include time, it defines all basic builtin styles.
95
+ # @param base [Class, Module] base Class/Module
96
+ def self.define_builtin_style_methods(base)
97
+ HighLine::COLORS.each do |color|
98
+ color = color.downcase
99
+ base.class_eval <<-METHOD_DEFINITION
100
+ undef :#{color} if method_defined? :#{color}
101
+ def #{color}
102
+ color(:#{color})
103
+ end
104
+ METHOD_DEFINITION
105
+
106
+ base.class_eval <<-METHOD_DEFINITION
107
+ undef :on_#{color} if method_defined? :on_#{color}
108
+ def on_#{color}
109
+ on(:#{color})
110
+ end
111
+ METHOD_DEFINITION
112
+
113
+ HighLine::STYLES.each do |style|
114
+ style = style.downcase
115
+ base.class_eval <<-METHOD_DEFINITION
116
+ undef :#{style} if method_defined? :#{style}
117
+ def #{style}
118
+ color(:#{style})
119
+ end
120
+ METHOD_DEFINITION
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ # Adds color support to the base String class
127
+ def self.colorize_strings
128
+ ::String.send(:include, StringExtensions)
129
+ end
130
+ end