ronin 1.0.0 → 1.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. data/.yardopts +0 -1
  2. data/ChangeLog.md +67 -3
  3. data/Gemfile +20 -12
  4. data/README.md +3 -5
  5. data/gemspec.yml +5 -5
  6. data/lib/ronin/address.rb +8 -3
  7. data/lib/ronin/arch.rb +39 -14
  8. data/lib/ronin/author.rb +2 -0
  9. data/lib/ronin/auto_load.rb +67 -0
  10. data/lib/ronin/campaign.rb +15 -2
  11. data/lib/ronin/class_methods.rb +7 -1
  12. data/lib/ronin/config.rb +5 -0
  13. data/lib/ronin/credential.rb +14 -3
  14. data/lib/ronin/database/database.rb +38 -12
  15. data/lib/ronin/database/migrations.rb +3 -1
  16. data/lib/ronin/database/migrations/add_created_at_column_to_targets_table.rb +48 -0
  17. data/lib/ronin/database/migrations/add_updated_at_column_to_campaigns_table.rb +47 -0
  18. data/lib/ronin/database/migrations/create_licenses_table.rb +1 -1
  19. data/lib/ronin/database/migrations/create_passwords_table.rb +1 -1
  20. data/lib/ronin/database/migrations/{create_cached_files_table.rb → create_script_paths_table.rb} +4 -4
  21. data/lib/ronin/database/migrations/migration.rb +3 -6
  22. data/lib/ronin/database/migrations/migrations.rb +3 -3
  23. data/lib/ronin/email_address.rb +20 -3
  24. data/lib/ronin/environment.rb +0 -3
  25. data/lib/ronin/host_name.rb +20 -6
  26. data/lib/ronin/host_name_ip_address.rb +2 -3
  27. data/lib/ronin/installation.rb +92 -23
  28. data/lib/ronin/ip_address.rb +31 -8
  29. data/lib/ronin/ip_address_mac_address.rb +2 -3
  30. data/lib/ronin/license.rb +1 -1
  31. data/lib/ronin/mac_address.rb +6 -4
  32. data/lib/ronin/model/class_methods.rb +4 -0
  33. data/lib/ronin/model/has_authors/class_methods.rb +4 -0
  34. data/lib/ronin/model/has_authors/has_authors.rb +4 -0
  35. data/lib/ronin/model/has_description/class_methods.rb +2 -0
  36. data/lib/ronin/model/has_description/has_description.rb +2 -0
  37. data/lib/ronin/model/has_license/class_methods.rb +2 -0
  38. data/lib/ronin/model/has_license/has_license.rb +4 -0
  39. data/lib/ronin/model/has_name/class_methods.rb +2 -0
  40. data/lib/ronin/model/has_name/has_name.rb +4 -0
  41. data/lib/ronin/model/has_title/class_methods.rb +2 -0
  42. data/lib/ronin/model/has_title/has_title.rb +2 -0
  43. data/lib/ronin/model/has_unique_name/class_methods.rb +2 -0
  44. data/lib/ronin/model/has_unique_name/has_unique_name.rb +7 -1
  45. data/lib/ronin/model/has_version/class_methods.rb +4 -0
  46. data/lib/ronin/model/has_version/has_version.rb +2 -0
  47. data/lib/ronin/model/model.rb +2 -0
  48. data/lib/ronin/model/types.rb +1 -7
  49. data/lib/ronin/model/types/description.rb +2 -0
  50. data/lib/ronin/network/mixins/esmtp.rb +40 -25
  51. data/lib/ronin/network/mixins/http.rb +336 -73
  52. data/lib/ronin/network/mixins/imap.rb +38 -25
  53. data/lib/ronin/network/mixins/pop3.rb +34 -21
  54. data/lib/ronin/network/mixins/smtp.rb +40 -25
  55. data/lib/ronin/network/mixins/tcp.rb +66 -41
  56. data/lib/ronin/network/mixins/telnet.rb +43 -30
  57. data/lib/ronin/network/mixins/udp.rb +59 -40
  58. data/lib/ronin/open_port.rb +12 -5
  59. data/lib/ronin/organization.rb +1 -2
  60. data/lib/ronin/os.rb +10 -3
  61. data/lib/ronin/os_guess.rb +2 -3
  62. data/lib/ronin/password.rb +11 -3
  63. data/lib/ronin/port.rb +7 -2
  64. data/lib/ronin/{engine/exceptions/deploy_failed.rb → repositories.rb} +4 -6
  65. data/lib/ronin/repository.rb +110 -37
  66. data/lib/ronin/ronin.rb +4 -3
  67. data/lib/ronin/{engine.rb → script.rb} +2 -1
  68. data/lib/ronin/{engine → script}/buildable.rb +43 -29
  69. data/lib/ronin/script/class_methods.rb +84 -0
  70. data/lib/ronin/{engine → script}/deployable.rb +61 -40
  71. data/lib/ronin/{engine → script}/exceptions.rb +4 -3
  72. data/lib/ronin/script/exceptions/deploy_failed.rb +27 -0
  73. data/lib/ronin/{engine/exceptions/not_built.rb → script/exceptions/exception.rb} +2 -2
  74. data/lib/ronin/{engine/exceptions/verification_failed.rb → script/exceptions/not_built.rb} +4 -2
  75. data/lib/ronin/script/exceptions/test_failed.rb +27 -0
  76. data/lib/ronin/script/instance_methods.rb +217 -0
  77. data/lib/ronin/script/path.rb +277 -0
  78. data/lib/ronin/{engine/engine.rb → script/script.rb} +52 -15
  79. data/lib/ronin/{engine/verifiable.rb → script/testable.rb} +97 -68
  80. data/lib/ronin/service.rb +1 -2
  81. data/lib/ronin/service_credential.rb +1 -2
  82. data/lib/ronin/software.rb +3 -2
  83. data/lib/ronin/spec/database.rb +0 -4
  84. data/lib/ronin/target.rb +11 -3
  85. data/lib/ronin/tcp_port.rb +3 -2
  86. data/lib/ronin/udp_port.rb +2 -0
  87. data/lib/ronin/ui/cli/cli.rb +6 -0
  88. data/lib/ronin/ui/cli/command.rb +48 -12
  89. data/lib/ronin/ui/cli/commands/campaigns.rb +3 -3
  90. data/lib/ronin/ui/cli/commands/console.rb +2 -1
  91. data/lib/ronin/ui/cli/commands/creds.rb +3 -3
  92. data/lib/ronin/ui/cli/commands/database.rb +1 -17
  93. data/lib/ronin/ui/cli/commands/emails.rb +3 -3
  94. data/lib/ronin/ui/cli/commands/hosts.rb +3 -7
  95. data/lib/ronin/ui/cli/commands/ips.rb +3 -7
  96. data/lib/ronin/ui/cli/commands/repos.rb +5 -17
  97. data/lib/ronin/ui/cli/commands/urls.rb +3 -3
  98. data/lib/ronin/ui/cli/model_command.rb +82 -97
  99. data/lib/ronin/ui/cli/resources_command.rb +89 -0
  100. data/lib/ronin/ui/cli/script_command.rb +115 -0
  101. data/lib/ronin/ui/console.rb +17 -3
  102. data/lib/ronin/ui/output/helpers.rb +18 -0
  103. data/lib/ronin/ui/output/output.rb +20 -1
  104. data/lib/ronin/ui/output/terminal/color.rb +10 -0
  105. data/lib/ronin/ui/output/terminal/raw.rb +10 -0
  106. data/lib/ronin/ui/shell.rb +2 -0
  107. data/lib/ronin/url.rb +47 -12
  108. data/lib/ronin/url_query_param.rb +4 -0
  109. data/lib/ronin/url_scheme.rb +3 -3
  110. data/lib/ronin/user_name.rb +2 -0
  111. data/lib/ronin/version.rb +1 -1
  112. data/lib/ronin/web_credential.rb +6 -3
  113. data/spec/arch_spec.rb +3 -3
  114. data/spec/classes/my_script.rb +21 -0
  115. data/spec/helpers/repos/{test1 → installed}/ronin.yml +1 -1
  116. data/spec/helpers/repos/{hello/cache → installed/scripts}/.keep +0 -0
  117. data/spec/helpers/repos/local/lib/init.rb +1 -0
  118. data/spec/helpers/repos/{hello → local}/lib/stuff/another_test.rb +0 -0
  119. data/spec/helpers/repos/{hello → local}/lib/stuff/test.rb +0 -0
  120. data/spec/helpers/repos/{random → local}/ronin.yml +1 -1
  121. data/spec/helpers/repos/{random/cache → local/scripts}/.keep +0 -0
  122. data/spec/helpers/repos/{hello → remote}/ronin.yml +1 -1
  123. data/spec/helpers/repos/remote/scripts/.keep +0 -0
  124. data/spec/helpers/repos/{test2 → scripts}/ronin.yml +0 -0
  125. data/spec/helpers/repos/scripts/scripts/cached/cached.rb +10 -0
  126. data/spec/helpers/repos/scripts/scripts/cached/missing.rb +10 -0
  127. data/spec/helpers/repos/scripts/scripts/cached/modified.rb +10 -0
  128. data/spec/helpers/repos/scripts/scripts/cached/unmodified.rb +10 -0
  129. data/spec/helpers/repos/scripts/scripts/failures/exceptions.rb +11 -0
  130. data/spec/helpers/repos/{test2/cache/cacheable_model → scripts/scripts/failures}/load_errors.rb +3 -1
  131. data/spec/helpers/repos/{test2/cache/cacheable_model → scripts/scripts/failures}/name_errors.rb +1 -0
  132. data/spec/helpers/repos/scripts/scripts/failures/no_method_errors.rb +10 -0
  133. data/spec/helpers/repos/scripts/scripts/failures/syntax_errors.rb +11 -0
  134. data/spec/helpers/repos/scripts/scripts/failures/validation_errors.rb +11 -0
  135. data/spec/helpers/repos/scripts/scripts/my_scripts/test.rb +16 -0
  136. data/spec/model/spec_helper.rb +0 -2
  137. data/spec/repository_spec.rb +61 -81
  138. data/spec/ronin_spec.rb +2 -2
  139. data/spec/{engine → script}/buildable_spec.rb +9 -9
  140. data/spec/script/classes/buildable_class.rb +15 -0
  141. data/spec/script/classes/deployable_class.rb +13 -0
  142. data/spec/{engine/classes/engine_class.rb → script/classes/script_class.rb} +3 -3
  143. data/spec/{engine/classes/verifiable_class.rb → script/classes/testable_class.rb} +5 -5
  144. data/spec/{engine → script}/deployable_spec.rb +10 -10
  145. data/spec/{cached_file_spec.rb → script/path_spec.rb} +33 -72
  146. data/spec/script/script_spec.rb +130 -0
  147. data/spec/script/testable_spec.rb +117 -0
  148. data/spec/spec_helper.rb +15 -13
  149. metadata +114 -139
  150. data/lib/ronin/cached_file.rb +0 -247
  151. data/lib/ronin/engine/class_methods.rb +0 -135
  152. data/lib/ronin/engine/instance_methods.rb +0 -97
  153. data/lib/ronin/model/cacheable.rb +0 -21
  154. data/lib/ronin/model/cacheable/cacheable.rb +0 -273
  155. data/lib/ronin/model/cacheable/class_methods.rb +0 -60
  156. data/lib/ronin/ui/cli/engine_command.rb +0 -106
  157. data/spec/engine/classes/buildable_class.rb +0 -15
  158. data/spec/engine/classes/deployable_class.rb +0 -13
  159. data/spec/engine/engine_spec.rb +0 -55
  160. data/spec/engine/verifiable_spec.rb +0 -117
  161. data/spec/helpers/repos/hello/lib/init.rb +0 -1
  162. data/spec/helpers/repos/test1/cache/cacheable_model/one.rb +0 -15
  163. data/spec/helpers/repos/test2/cache/cacheable_model/exceptions.rb +0 -7
  164. data/spec/helpers/repos/test2/cache/cacheable_model/no_method_errors.rb +0 -9
  165. data/spec/helpers/repos/test2/cache/cacheable_model/syntax_errors.rb +0 -7
  166. data/spec/helpers/repos/test2/cache/cacheable_model/two.rb +0 -15
  167. data/spec/helpers/repos/test2/cache/cacheable_model/validation_errors.rb +0 -9
  168. data/spec/model/cacheable_spec.rb +0 -96
  169. data/spec/model/models/cacheable_model.rb +0 -13
@@ -17,7 +17,7 @@
17
17
  # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
18
18
  #
19
19
 
20
- require 'ronin/ui/cli/model_command'
20
+ require 'ronin/ui/cli/resources_command'
21
21
  require 'ronin/extensions/ip_addr'
22
22
  require 'ronin/ip_address'
23
23
 
@@ -28,9 +28,9 @@ module Ronin
28
28
  #
29
29
  # The `ronin-ips` command.
30
30
  #
31
- class IPs < ModelCommand
31
+ class IPs < ResourcesCommand
32
32
 
33
- self.model = IPAddress
33
+ model IPAddress
34
34
 
35
35
  query_option :v4, :type => :boolean, :aliases => '-4'
36
36
  query_option :v6, :type => :boolean, :aliases => '-6'
@@ -85,8 +85,6 @@ module Ronin
85
85
  # @since 1.0.0
86
86
  #
87
87
  def lookup(host)
88
- Database.setup
89
-
90
88
  print_info "Looking up #{host} ..."
91
89
 
92
90
  IPAddress.lookup(host).each do |ip|
@@ -105,8 +103,6 @@ module Ronin
105
103
  # @since 1.0.0
106
104
  #
107
105
  def import(path)
108
- Database.setup
109
-
110
106
  File.open(options[:import]) do |file|
111
107
  file.each_line do |line|
112
108
  IPAddr.extract(line) do |match|
@@ -17,9 +17,8 @@
17
17
  # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
18
18
  #
19
19
 
20
- require 'ronin/ui/cli/command'
20
+ require 'ronin/ui/cli/model_command'
21
21
  require 'ronin/repository'
22
- require 'ronin/database'
23
22
 
24
23
  module Ronin
25
24
  module UI
@@ -28,7 +27,7 @@ module Ronin
28
27
  #
29
28
  # The `ronin repos` command.
30
29
  #
31
- class Repos < Command
30
+ class Repos < ModelCommand
32
31
 
33
32
  desc 'Manages Ronin repositories'
34
33
  class_option :add, :type => :string,
@@ -57,8 +56,6 @@ module Ronin
57
56
  # Executes the command.
58
57
  #
59
58
  def execute
60
- Database.setup
61
-
62
59
  if options[:add]
63
60
  add options[:add]
64
61
  elsif options[:install]
@@ -143,19 +140,10 @@ module Ronin
143
140
  if repo.verbose?
144
141
  putc "\n"
145
142
 
146
- if repo.title
147
- puts "Title: #{repo.title}"
148
- end
149
-
143
+ puts "Title: #{repo.title}" if repo.title
150
144
  puts "URI: #{repo.uri}" if repo.uri
151
-
152
- if repo.source
153
- puts "Source URI: #{repo.source}"
154
- end
155
-
156
- if repo.website
157
- puts "Website: #{repo.website}"
158
- end
145
+ puts "Source URI: #{repo.source}" if repo.source
146
+ puts "Website: #{repo.website}" if repo.website
159
147
 
160
148
  executables = repo.executables
161
149
 
@@ -17,7 +17,7 @@
17
17
  # along with Ronin. If not, see <http://www.gnu.org/licenses/>.
18
18
  #
19
19
 
20
- require 'ronin/ui/cli/model_command'
20
+ require 'ronin/ui/cli/resources_command'
21
21
  require 'ronin/url'
22
22
 
23
23
  module Ronin
@@ -27,9 +27,9 @@ module Ronin
27
27
  #
28
28
  # The `ronin-urls` command.
29
29
  #
30
- class URLs < ModelCommand
30
+ class URLs < ResourcesCommand
31
31
 
32
- self.model = URL
32
+ model URL
33
33
 
34
34
  query_option :http, :type => :boolean
35
35
  query_option :https, :type => :boolean
@@ -20,20 +20,16 @@
20
20
  require 'ronin/ui/cli/command'
21
21
  require 'ronin/database'
22
22
 
23
- require 'set'
24
-
25
23
  module Ronin
26
24
  module UI
27
25
  module CLI
28
26
  #
29
- # A base-command for querying and exporting {Model}s.
27
+ # A base-command for querying {Model}s.
30
28
  #
31
29
  class ModelCommand < Command
32
30
 
33
- class_option :csv, :type => :boolean
34
- class_option :xml, :type => :boolean
35
- class_option :yaml, :type => :boolean
36
- class_option :json, :type => :boolean
31
+ class_option :database, :type => :string,
32
+ :aliases => '-D'
37
33
 
38
34
  #
39
35
  # The model to query.
@@ -41,33 +37,52 @@ module Ronin
41
37
  # @return [DataMapper::Resource]
42
38
  # The model that will be queried.
43
39
  #
44
- # @since 1.0.0
40
+ # @since 1.1.0
41
+ #
42
+ # @api semipublic
45
43
  #
46
- def self.model
47
- @model
44
+ def self.query_model
45
+ @query_model ||= if self.superclass < ModelCommand
46
+ self.superclass.query_model
47
+ end
48
48
  end
49
49
 
50
50
  #
51
51
  # The query options for the command.
52
52
  #
53
- # @return [Set]
53
+ # @return [Array<Symbol>]
54
54
  # The query options and their query method names.
55
55
  #
56
56
  # @since 1.0.0
57
57
  #
58
+ # @api semipublic
59
+ #
58
60
  def self.query_options
59
- @query_options ||= Set[]
61
+ @query_options ||= []
60
62
  end
61
63
 
62
64
  #
63
- # Default method performs the query and prints the found resources.
65
+ # Iterates over the query options for the command.
64
66
  #
65
- # @since 1.0.0
67
+ # @yield [name]
68
+ # The given block will be passed the names of the query options.
66
69
  #
67
- def execute
68
- Database.setup
70
+ # @yieldparam [Symbol] name
71
+ # The name of a query option.
72
+ #
73
+ # @return [Enumerator]
74
+ # If no block is given, an Enumerator object will be returned.
75
+ #
76
+ # @since 1.1.0
77
+ #
78
+ def self.each_query_option(&block)
79
+ return enum_for(:each_query_option) unless block
69
80
 
70
- print_resources(query)
81
+ self.class.ancestors.each do |ancestor|
82
+ if ancestor < ModelCommand
83
+ ancestor.query_options.each(&block)
84
+ end
85
+ end
71
86
  end
72
87
 
73
88
  protected
@@ -81,10 +96,12 @@ module Ronin
81
96
  # @return [DataMapper::Resource]
82
97
  # The model that will be queried.
83
98
  #
84
- # @since 1.0.0
99
+ # @since 1.1.0
100
+ #
101
+ # @api semipublic
85
102
  #
86
- def self.model=(model)
87
- @model = model
103
+ def self.model(model)
104
+ @query_model = model
88
105
  end
89
106
 
90
107
  #
@@ -98,108 +115,76 @@ module Ronin
98
115
  #
99
116
  # @since 1.0.0
100
117
  #
118
+ # @api semipublic
119
+ #
101
120
  def self.query_option(name,options={})
102
121
  query_options << name
103
122
  class_option(name,options)
104
123
  end
105
124
 
106
125
  #
107
- # Invokes a query method on a query.
108
- #
109
- # @param [DataMapper::Collection] query
110
- # The query.
111
- #
112
- # @param [Symbol] name
113
- # The method name to call.
114
- #
115
- # @param [Array] arguments
116
- # Additional arguments to pass to the query method.
126
+ # Sets up the {Database}.
117
127
  #
118
- # @return [DataMapper::Collection]
119
- # The modified query.
128
+ # @since 1.1.0
120
129
  #
121
- # @since 1.0.0
130
+ # @api semipublic
122
131
  #
123
- def query_method(query,name,arguments=[])
124
- query_method = begin
125
- query.model.method(name)
126
- rescue NameError
127
- raise("Undefined query method #{query.model}.#{name}")
128
- end
129
-
130
- case query_method.arity
131
- when 0
132
- query.send(name)
133
- when 1
134
- query.send(name,arguments)
135
- else
136
- query.send(name,*arguments)
132
+ def setup
133
+ super
134
+
135
+ if self.options[:database]
136
+ Database.repositories[:default] = options[:database]
137
137
  end
138
+
139
+ Database.setup
138
140
  end
139
141
 
140
142
  #
141
143
  # Builds a new query using the options of the command.
142
144
  #
143
- # @yield [query]
144
- # If a block is given, it will be passed the new query.
145
- #
146
- # @yieldparam [DataMapper::Collection] query
147
- # The new query.
148
- #
149
145
  # @return [DataMapper::Collection]
150
146
  # The new query.
151
147
  #
148
+ # @raise [RuntimeError]
149
+ # The query option does not map to a query-method or property
150
+ # defined in the Model.
151
+ #
152
152
  # @since 1.0.0
153
153
  #
154
+ # @api semipublic
155
+ #
154
156
  def query
155
- new_query = self.class.model.all
157
+ unless self.class.query_model
158
+ raise("query model not defined for #{self.class}")
159
+ end
156
160
 
157
- self.class.ancestors.each do |ancestor|
158
- if ancestor < ModelCommand
159
- ancestor.query_options.each do |name|
160
- unless options[name].nil?
161
- new_query = query_method(new_query,name,options[name])
162
- end
163
- end
161
+ query = self.class.query_model.all
162
+
163
+ self.class.each_query_option do |name|
164
+ value = options[name]
165
+
166
+ # skip unset options
167
+ next if value.nil?
168
+
169
+ if query_model.properties.named?(name)
170
+ query = query.all(name => value)
171
+ elsif query_model.respond_to?(name)
172
+ query_method = query_model.method(name)
173
+
174
+ query = case query_method.arity
175
+ when 0
176
+ query.send(name)
177
+ when 1
178
+ query.send(name,value)
179
+ else
180
+ query.send(name,*value)
181
+ end
182
+ else
183
+ raise("unknown query method or property #{name} for #{query_model}")
164
184
  end
165
185
  end
166
186
 
167
- new_query = yield(new_query) if block_given?
168
- return new_query
169
- end
170
-
171
- #
172
- # Default method which will print every queried resource.
173
- #
174
- # @param [DataMapper::Resource] resource
175
- # A queried resource from the Database.
176
- #
177
- # @since 1.0.0
178
- #
179
- def print_resource(resource)
180
- puts resource
181
- end
182
-
183
- #
184
- # Prints multiple resources.
185
- #
186
- # @param [DataMapper::Collection, Array<DataMapper::Resource>] resources
187
- # The query to print.
188
- #
189
- # @since 1.0.0
190
- #
191
- def print_resources(resources)
192
- if options.csv?
193
- print resources.to_csv
194
- elsif options.xml?
195
- print resources.to_xml
196
- elsif options.yaml?
197
- print resources.to_yaml
198
- elsif options.json?
199
- print resources.to_json
200
- else
201
- resources.each { |resource| print_resource(resource) }
202
- end
187
+ return query
203
188
  end
204
189
 
205
190
  end
@@ -0,0 +1,89 @@
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/cli/model_command'
21
+
22
+ module Ronin
23
+ module UI
24
+ module CLI
25
+ #
26
+ # A base-command class for listing Database Resources.
27
+ #
28
+ class ResourcesCommand < ModelCommand
29
+
30
+ class_option :csv, :type => :boolean
31
+ class_option :xml, :type => :boolean
32
+ class_option :yaml, :type => :boolean
33
+ class_option :json, :type => :boolean
34
+
35
+ #
36
+ # Default method performs the query and prints the found resources.
37
+ #
38
+ # @since 1.1.0
39
+ #
40
+ # @api semipublic
41
+ #
42
+ def execute
43
+ print_resources(query)
44
+ end
45
+
46
+ protected
47
+
48
+ #
49
+ # Default method which will print every queried resource.
50
+ #
51
+ # @param [DataMapper::Resource] resource
52
+ # A queried resource from the Database.
53
+ #
54
+ # @since 1.1.0
55
+ #
56
+ # @api semipublic
57
+ #
58
+ def print_resource(resource)
59
+ puts resource
60
+ end
61
+
62
+ #
63
+ # Prints multiple resources.
64
+ #
65
+ # @param [DataMapper::Collection] resources
66
+ # The query to print.
67
+ #
68
+ # @since 1.1.0
69
+ #
70
+ # @api semipublic
71
+ #
72
+ def print_resources(resources)
73
+ if options.csv?
74
+ print resources.to_csv
75
+ elsif options.xml?
76
+ print resources.to_xml
77
+ elsif options.yaml?
78
+ print resources.to_yaml
79
+ elsif options.json?
80
+ print resources.to_json
81
+ else
82
+ resources.each { |resource| print_resource(resource) }
83
+ end
84
+ end
85
+
86
+ end
87
+ end
88
+ end
89
+ end