Class: RightScraper::Processes::Shell
- Inherits:
-
Object
- Object
- RightScraper::Processes::Shell
- Includes:
- RightGit::Shell::Interface
- Defined in:
- lib/right_scraper/processes/shell.rb
Overview
provides a shell with configurable properties that satisfies the interface for a shell for right_git but can be used for other scraper actions.
Defined Under Namespace
Classes: LimitError, SizeLimitError, TimeLimitError
Constant Summary collapse
- MAX_SAFE_BUFFER_LINE_COUNT =
10- MAX_SAFE_BUFFER_LINE_LENGTH =
128
Instance Attribute Summary collapse
-
#initial_directory ⇒ Object
Returns the value of attribute initial_directory.
-
#max_bytes ⇒ Object
Returns the value of attribute max_bytes.
-
#max_seconds ⇒ Object
Returns the value of attribute max_seconds.
-
#stop_timestamp ⇒ Object
Returns the value of attribute stop_timestamp.
-
#watch_directory ⇒ Object
Returns the value of attribute watch_directory.
Instance Method Summary collapse
-
#execute(cmd, options = {}) ⇒ Integer
Implements execute interface.
-
#exit_handler(status) ⇒ TrueClass
Handles exit status.
-
#initialize(options = {}) ⇒ Shell
constructor
A new instance of Shell.
-
#output_for(cmd, options = {}) ⇒ String
Implements output_for interface.
-
#safe_output_handler(data) ⇒ TrueClass
Buffers output safely.
-
#size_limit_handler ⇒ Object
Raises size limit error.
-
#timeout_handler ⇒ Object
Raises timeout error.
-
#unsafe_output_handler(data) ⇒ TrueClass
Buffers output unsafely but completely.
Constructor Details
#initialize(options = {}) ⇒ Shell
Returns a new instance of Shell.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/right_scraper/processes/shell.rb', line 57 def initialize( = {}) = { :initial_directory => nil, :max_bytes => nil, :max_seconds => nil, :watch_directory => nil, }.merge() @initial_directory = [:initial_directory] @max_bytes = [:max_bytes] @max_seconds = [:max_seconds] @watch_directory = [:watch_directory] # set stop time once for the lifetime of this shell object. @stop_timestamp = (::Time.now + @max_seconds).to_i if @max_seconds end |
Instance Attribute Details
#initial_directory ⇒ Object
Returns the value of attribute initial_directory.
48 49 50 |
# File 'lib/right_scraper/processes/shell.rb', line 48 def initial_directory @initial_directory end |
#max_bytes ⇒ Object
Returns the value of attribute max_bytes.
48 49 50 |
# File 'lib/right_scraper/processes/shell.rb', line 48 def max_bytes @max_bytes end |
#max_seconds ⇒ Object
Returns the value of attribute max_seconds.
48 49 50 |
# File 'lib/right_scraper/processes/shell.rb', line 48 def max_seconds @max_seconds end |
#stop_timestamp ⇒ Object
Returns the value of attribute stop_timestamp.
49 50 51 |
# File 'lib/right_scraper/processes/shell.rb', line 49 def @stop_timestamp end |
#watch_directory ⇒ Object
Returns the value of attribute watch_directory.
49 50 51 |
# File 'lib/right_scraper/processes/shell.rb', line 49 def watch_directory @watch_directory end |
Instance Method Details
#execute(cmd, options = {}) ⇒ Integer
Implements execute interface.
82 83 84 85 86 |
# File 'lib/right_scraper/processes/shell.rb', line 82 def execute(cmd, = {}) inner_execute(cmd, :safe_output_handler, ) ensure @output = nil end |
#exit_handler(status) ⇒ TrueClass
Handles exit status.
148 149 150 151 152 153 154 155 |
# File 'lib/right_scraper/processes/shell.rb', line 148 def exit_handler(status) @exit_code = status.exitstatus if @raise_on_failure && !status.success? @output.buffer << "Exit code = #{@exit_code}" raise ::RightScraper::Error, "Execution failed: #{@output.display_text}" end true end |
#output_for(cmd, options = {}) ⇒ String
Implements output_for interface.
96 97 98 99 100 101 |
# File 'lib/right_scraper/processes/shell.rb', line 96 def output_for(cmd, = {}) inner_execute(cmd, :unsafe_output_handler, ) @output.display_text ensure @output = nil end |
#safe_output_handler(data) ⇒ TrueClass
Buffers output safely.
108 109 110 111 |
# File 'lib/right_scraper/processes/shell.rb', line 108 def safe_output_handler(data) @output.safe_buffer_data(data) true end |
#size_limit_handler ⇒ Object
Raises size limit error.
126 127 128 129 130 131 132 |
# File 'lib/right_scraper/processes/shell.rb', line 126 def size_limit_handler = "Exceeded size limit of #{@max_bytes / (1024 * 1024)} MB on " + "repository directory. Hidden file and directory sizes are not " + "included in the total." raise SizeLimitError, end |
#timeout_handler ⇒ Object
Raises timeout error.
137 138 139 |
# File 'lib/right_scraper/processes/shell.rb', line 137 def timeout_handler raise TimeLimitError, "Timed-out after #{@max_seconds} seconds" end |
#unsafe_output_handler(data) ⇒ TrueClass
Buffers output unsafely but completely.
118 119 120 121 |
# File 'lib/right_scraper/processes/shell.rb', line 118 def unsafe_output_handler(data) @output.buffer << data.chomp true end |