ronin 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. data/ChangeLog.md +23 -0
  2. data/README.md +19 -13
  3. data/Rakefile +2 -1
  4. data/gemspec.yml +18 -17
  5. data/lib/bond/completions/ronin.rb +147 -0
  6. data/lib/ronin/auto_load.rb +30 -28
  7. data/lib/ronin/database/migrations/1.0.0.rb +1 -0
  8. data/lib/ronin/model/has_authors.rb +92 -2
  9. data/lib/ronin/model/has_description.rb +54 -2
  10. data/lib/ronin/model/has_license.rb +101 -2
  11. data/lib/ronin/model/has_name.rb +72 -2
  12. data/lib/ronin/model/has_title.rb +52 -2
  13. data/lib/ronin/model/has_unique_name.rb +93 -2
  14. data/lib/ronin/model/has_version.rb +58 -2
  15. data/lib/ronin/model/model.rb +91 -52
  16. data/lib/ronin/os.rb +30 -15
  17. data/lib/ronin/repository.rb +1 -1
  18. data/lib/ronin/ronin.rb +0 -15
  19. data/lib/ronin/script/script.rb +257 -2
  20. data/lib/ronin/ui/console.rb +2 -199
  21. data/lib/ronin/ui/console/commands.rb +164 -0
  22. data/lib/ronin/ui/console/console.rb +215 -0
  23. data/lib/ronin/ui/console/context.rb +95 -0
  24. data/lib/ronin/version.rb +1 -1
  25. data/spec/os_spec.rb +18 -13
  26. metadata +206 -239
  27. data/lib/ronin/class_methods.rb +0 -49
  28. data/lib/ronin/model/class_methods.rb +0 -58
  29. data/lib/ronin/model/has_authors/class_methods.rb +0 -60
  30. data/lib/ronin/model/has_authors/has_authors.rb +0 -70
  31. data/lib/ronin/model/has_description/class_methods.rb +0 -49
  32. data/lib/ronin/model/has_description/has_description.rb +0 -49
  33. data/lib/ronin/model/has_license/class_methods.rb +0 -68
  34. data/lib/ronin/model/has_license/has_license.rb +0 -71
  35. data/lib/ronin/model/has_name/class_methods.rb +0 -48
  36. data/lib/ronin/model/has_name/has_name.rb +0 -62
  37. data/lib/ronin/model/has_title/class_methods.rb +0 -48
  38. data/lib/ronin/model/has_title/has_title.rb +0 -48
  39. data/lib/ronin/model/has_unique_name/class_methods.rb +0 -51
  40. data/lib/ronin/model/has_unique_name/has_unique_name.rb +0 -78
  41. data/lib/ronin/model/has_version/class_methods.rb +0 -54
  42. data/lib/ronin/model/has_version/has_version.rb +0 -48
  43. data/lib/ronin/script/class_methods.rb +0 -84
  44. data/lib/ronin/script/instance_methods.rb +0 -217
@@ -17,202 +17,5 @@
17
17
  # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
18
18
  #
19
19
 
20
- require 'ronin/config'
21
- require 'ronin/repository'
22
-
23
- module Ronin
24
- module UI
25
- #
26
- # An interactive Ruby {Console} using
27
- # [Ripl](https://github.com/cldwalker/ripl).
28
- #
29
- class Console
30
-
31
- # The history file for the Console session
32
- HISTORY_FILE = File.join(Config::PATH,'console.log')
33
-
34
- @@color = !(STDOUT.tty?)
35
- @@short_errors = !(ENV.has_key?('VERBOSE'))
36
- @@auto_load = []
37
- @@setup_blocks = []
38
-
39
- #
40
- # Determines whether colorized output will be enabled.
41
- #
42
- # @return [Boolean]
43
- # Specifies whether colorized output will be enabled.
44
- #
45
- # @since 1.0.0
46
- #
47
- # @api semipublic
48
- #
49
- def Console.color?
50
- @@color
51
- end
52
-
53
- #
54
- # Enables or disables colorized output.
55
- #
56
- # @param [Boolean] mode
57
- # The new colorized output mode.
58
- #
59
- # @return [Boolean]
60
- # The colorized output mode.
61
- #
62
- # @since 1.0.0
63
- #
64
- # @api semipublic
65
- #
66
- def Console.color=(mode)
67
- @@color = mode
68
- end
69
-
70
- #
71
- # Determines whether one-line errors will be printed, instead of full
72
- # backtraces.
73
- #
74
- # @return [Boolean]
75
- # The Console short-errors setting.
76
- #
77
- # @since 1.0.0
78
- #
79
- # @api semipublic
80
- #
81
- def Console.short_errors?
82
- @@short_errors
83
- end
84
-
85
- #
86
- # Enables or disables the printing of one-lin errors.
87
- #
88
- # @param [Boolean] mode
89
- # The new Console short-errors setting.
90
- #
91
- # @return [Boolean]
92
- # The Console short-errors setting.
93
- #
94
- # @since 1.0.0
95
- #
96
- # @api semipublic
97
- #
98
- def Console.short_errors=(mode)
99
- @@short_errors = mode
100
- end
101
-
102
- #
103
- # The list of files to load before starting the Console.
104
- #
105
- # @return [Array]
106
- # The files to require when the Console starts.
107
- #
108
- # @api semipublic
109
- #
110
- def Console.auto_load
111
- @@auto_load
112
- end
113
-
114
- #
115
- # Adds a block to be ran from within the Console after it is
116
- # started.
117
- #
118
- # @yield []
119
- # The block to be ran from within the Console.
120
- #
121
- # @api semipublic
122
- #
123
- def Console.setup(&block)
124
- @@setup_blocks << block if block
125
- end
126
-
127
- #
128
- # Starts a Console.
129
- #
130
- # @param [Hash{Symbol => Object}] variables
131
- # Instance variable names and values to set within the console.
132
- #
133
- # @yield []
134
- # The block to be ran within the Console, after it has been setup.
135
- #
136
- # @return [Console]
137
- # The instance context the Console ran within.
138
- #
139
- # @example
140
- # Console.start
141
- # # >>
142
- #
143
- # @example
144
- # Console.start(:var => 'hello')
145
- # # >> @var
146
- # # # => "hello"
147
- #
148
- # @example
149
- # Console.start { @var = 'hello' }
150
- # # >> @var
151
- # # # => "hello"
152
- #
153
- # @api semipublic
154
- #
155
- def Console.start(variables={},&block)
156
- require 'ripl'
157
- require 'ripl/completion'
158
- require 'ripl/multi_line'
159
- require 'ripl/auto_indent'
160
- require 'ripl/color_result' if @@color
161
- require 'ripl/short_errors' if @@short_errors
162
-
163
- require 'ronin'
164
- require 'ronin/repositories'
165
- require 'pp'
166
-
167
- # append the current directory to $LOAD_PATH for Ruby 1.9.
168
- $LOAD_PATH << '.' unless $LOAD_PATH.include?('.')
169
-
170
- # require any of the auto-load paths
171
- @@auto_load.each { |path| require path }
172
-
173
- context = class << self.new; self; end
174
-
175
- # populate instance variables
176
- variables.each do |name,value|
177
- context.instance_variable_set("@#{name}".to_sym,value)
178
- end
179
-
180
- # run any setup-blocks
181
- @@setup_blocks.each do |setup_block|
182
- context.instance_eval(&setup_block)
183
- end
184
-
185
- # run the supplied configuration block is given
186
- context.instance_eval(&block) if block
187
-
188
- # Start the Ripl console
189
- Ripl.start(
190
- :argv => [],
191
- :name => 'ronin',
192
- :binding => context.instance_eval { binding },
193
- :history => HISTORY_FILE,
194
- :irbrc => false
195
- )
196
-
197
- return context
198
- end
199
-
200
- class << self
201
- #
202
- # Inspects the console.
203
- #
204
- # @return [String]
205
- # The inspected console.
206
- #
207
- # @since 1.0.0
208
- #
209
- # @api semipublic
210
- #
211
- def inspect
212
- "#<Ronin::UI::Console>"
213
- end
214
- end
215
-
216
- end
217
- end
218
- end
20
+ require 'ronin/ui/console/console'
21
+ require 'ronin/ui/console/commands'
@@ -0,0 +1,164 @@
1
+ #
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ #
4
+ # This file is part of Ronin.
5
+ #
6
+ # Ronin is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Ronin is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ require 'env'
21
+ require 'set'
22
+ require 'tempfile'
23
+
24
+ module Ronin
25
+ module UI
26
+ module Console
27
+ #
28
+ # Allows for executing shell commands prefixed by a `!`.
29
+ #
30
+ # @since 1.2.0
31
+ #
32
+ # @api private
33
+ #
34
+ module Commands
35
+ # Names and statuses of executables.
36
+ EXECUTABLES = Hash.new do |hash,key|
37
+ hash[key] = Env.paths.any? do |dir|
38
+ path = dir.join(key)
39
+
40
+ (path.file? && path.executable?)
41
+ end
42
+ end
43
+
44
+ # Blacklist of known commands that conflict with Ruby keywords.
45
+ BLACKLIST = Set[
46
+ '[', 'ap', 'begin', 'case', 'class', 'def', 'fail', 'false',
47
+ 'for', 'if', 'lambda', 'load', 'loop', 'module', 'p', 'pp',
48
+ 'print', 'proc', 'puts', 'raise', 'require', 'true', 'undef',
49
+ 'unless', 'until', 'warn', 'while'
50
+ ]
51
+
52
+ #
53
+ # Dynamically execute shell commands, instead of Ruby.
54
+ #
55
+ # @param [String] input
56
+ # The input from the console.
57
+ #
58
+ def loop_eval(input)
59
+ if input[0,1] == '!'
60
+ command = input[1..-1]
61
+ name, arguments = command.split(' ')
62
+
63
+ unless BLACKLIST.include?(name)
64
+ if Commands.singleton_class.method_defined?(name)
65
+ arguments ||= []
66
+
67
+ return Commands.send(name,*arguments)
68
+ elsif executable?(name)
69
+ return system(command)
70
+ end
71
+ end
72
+ end
73
+
74
+ super(input)
75
+ end
76
+
77
+ #
78
+ # Equivalent of the `cd` command, using `Dir.chdir`.
79
+ #
80
+ # @param [Array<String>] arguments
81
+ # The arguments of the command.
82
+ #
83
+ # @return [Boolean]
84
+ # Specifies whether the directory change was successful.
85
+ #
86
+ def Commands.cd(*arguments)
87
+ old_pwd = Dir.pwd
88
+
89
+ new_cwd = if arguments.empty?
90
+ Env.home
91
+ elsif arguments.first == '-'
92
+ unless ENV['OLDPWD']
93
+ print_warning 'cd: OLDPWD not set'
94
+ return false
95
+ end
96
+
97
+ ENV['OLDPWD']
98
+ else
99
+ arguments.first
100
+ end
101
+
102
+ Dir.chdir(new_cwd)
103
+ ENV['OLDPWD'] = old_pwd
104
+ return true
105
+ end
106
+
107
+ #
108
+ # Equivalent of the `export` or `set` commands.
109
+ #
110
+ # @param [Array<String>] arguments
111
+ # The arguments of the command.
112
+ #
113
+ # @return [true]
114
+ #
115
+ def Commands.export(*arguments)
116
+ arguments.each do |pair|
117
+ name, value = pair.split('=',2)
118
+
119
+ ENV[name] = value
120
+ end
121
+ end
122
+
123
+ #
124
+ # Edits a path and re-loads the code.
125
+ #
126
+ # @param [Array<String>] path
127
+ # The path of the file to re-load.
128
+ #
129
+ # @return [Boolean]
130
+ # Specifies whether the code was successfully re-loaded.
131
+ #
132
+ def Commands.edit(*arguments)
133
+ path = arguments.first
134
+
135
+ if Env.editor
136
+ path ||= Tempfile.new(['ronin-console', '.rb']).path
137
+
138
+ system(Env.editor,path) && load(path)
139
+ else
140
+ print_error "Please set the EDITOR env variable"
141
+ return false
142
+ end
143
+ end
144
+
145
+ protected
146
+
147
+ #
148
+ # Determines if an executable exists on the system.
149
+ #
150
+ # @param [String] name
151
+ # The program name or path.
152
+ #
153
+ # @return [Boolean]
154
+ # Specifies whether the executable exists.
155
+ #
156
+ def executable?(name)
157
+ (File.file?(name) && File.executable?(name)) || EXECUTABLES[name]
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
163
+
164
+ Ripl::Shell.send :include, Ronin::UI::Console::Commands
@@ -0,0 +1,215 @@
1
+ #
2
+ # Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
3
+ #
4
+ # This file is part of Ronin.
5
+ #
6
+ # Ronin is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Ronin is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ require 'ronin/ui/console/context'
21
+ require 'ronin/config'
22
+ require 'ronin/repository'
23
+
24
+ require 'ripl'
25
+ require 'ripl/multi_line'
26
+ require 'ripl/auto_indent'
27
+
28
+ module Ronin
29
+ module UI
30
+ #
31
+ # An interactive Ruby {Console} using
32
+ # [Ripl](https://github.com/cldwalker/ripl).
33
+ #
34
+ module Console
35
+
36
+ # The history file for the Console session
37
+ HISTORY_FILE = File.join(Config::PATH,'console.log')
38
+
39
+ @@color = !(STDOUT.tty?)
40
+ @@short_errors = !(ENV.has_key?('VERBOSE'))
41
+ @@auto_load = []
42
+ @@setup_blocks = []
43
+
44
+ #
45
+ # Determines whether colorized output will be enabled.
46
+ #
47
+ # @return [Boolean]
48
+ # Specifies whether colorized output will be enabled.
49
+ #
50
+ # @since 1.0.0
51
+ #
52
+ # @api semipublic
53
+ #
54
+ def Console.color?
55
+ @@color
56
+ end
57
+
58
+ #
59
+ # Enables or disables colorized output.
60
+ #
61
+ # @param [Boolean] mode
62
+ # The new colorized output mode.
63
+ #
64
+ # @return [Boolean]
65
+ # The colorized output mode.
66
+ #
67
+ # @since 1.0.0
68
+ #
69
+ # @api semipublic
70
+ #
71
+ def Console.color=(mode)
72
+ @@color = mode
73
+ end
74
+
75
+ #
76
+ # Determines whether one-line errors will be printed, instead of full
77
+ # backtraces.
78
+ #
79
+ # @return [Boolean]
80
+ # The Console short-errors setting.
81
+ #
82
+ # @since 1.0.0
83
+ #
84
+ # @api semipublic
85
+ #
86
+ def Console.short_errors?
87
+ @@short_errors
88
+ end
89
+
90
+ #
91
+ # Enables or disables the printing of one-lin errors.
92
+ #
93
+ # @param [Boolean] mode
94
+ # The new Console short-errors setting.
95
+ #
96
+ # @return [Boolean]
97
+ # The Console short-errors setting.
98
+ #
99
+ # @since 1.0.0
100
+ #
101
+ # @api semipublic
102
+ #
103
+ def Console.short_errors=(mode)
104
+ @@short_errors = mode
105
+ end
106
+
107
+ #
108
+ # The list of files to load before starting the Console.
109
+ #
110
+ # @return [Array]
111
+ # The files to require when the Console starts.
112
+ #
113
+ # @api semipublic
114
+ #
115
+ def Console.auto_load
116
+ @@auto_load
117
+ end
118
+
119
+ #
120
+ # Adds a block to be ran from within the Console after it is
121
+ # started.
122
+ #
123
+ # @yield []
124
+ # The block to be ran from within the Console.
125
+ #
126
+ # @api semipublic
127
+ #
128
+ def Console.setup(&block)
129
+ @@setup_blocks << block if block
130
+ end
131
+
132
+ #
133
+ # The list of completions files to require.
134
+ #
135
+ # @return [Array<String>]
136
+ # The sub-paths to require within `bond/completions/`.
137
+ #
138
+ # @since 1.2.0
139
+ #
140
+ # @api semipublic
141
+ #
142
+ def Console.completions
143
+ (Ripl.config[:completion][:gems] ||= [])
144
+ end
145
+
146
+ Console.completions << 'ronin'
147
+
148
+ #
149
+ # Starts a Console.
150
+ #
151
+ # @param [Hash{Symbol => Object}] variables
152
+ # Instance variable names and values to set within the console.
153
+ #
154
+ # @yield []
155
+ # The block to be ran within the Console, after it has been setup.
156
+ #
157
+ # @return [Console]
158
+ # The instance context the Console ran within.
159
+ #
160
+ # @example
161
+ # Console.start
162
+ # # >>
163
+ #
164
+ # @example
165
+ # Console.start(:var => 'hello')
166
+ # # >> @var
167
+ # # # => "hello"
168
+ #
169
+ # @example
170
+ # Console.start { @var = 'hello' }
171
+ # # >> @var
172
+ # # # => "hello"
173
+ #
174
+ # @api semipublic
175
+ #
176
+ def Console.start(variables={},&block)
177
+ require 'ripl/color_result' if @@color
178
+ require 'ripl/short_errors' if @@short_errors
179
+
180
+ require 'ronin'
181
+ require 'ronin/repositories'
182
+ require 'pp'
183
+
184
+ # append the current directory to $LOAD_PATH for Ruby 1.9.
185
+ $LOAD_PATH << '.' unless $LOAD_PATH.include?('.')
186
+
187
+ # require any of the auto-load paths
188
+ @@auto_load.each { |path| require path }
189
+
190
+ context = Context.new
191
+ context.instance_variables = variables
192
+
193
+ # run any setup-blocks
194
+ @@setup_blocks.each do |setup_block|
195
+ context.instance_eval(&setup_block)
196
+ end
197
+
198
+ # run the supplied configuration block is given
199
+ context.instance_eval(&block) if block
200
+
201
+ # Start the Ripl console
202
+ Ripl.start(
203
+ :argv => [],
204
+ :name => 'ronin',
205
+ :binding => context.instance_eval('binding'),
206
+ :history => HISTORY_FILE,
207
+ :irbrc => false
208
+ )
209
+
210
+ return context
211
+ end
212
+
213
+ end
214
+ end
215
+ end