bbcloud 0.6.2 → 0.7
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.
- data/bbcloud.gemspec +1 -3
- data/lib/bbcloud/commands/servers-show.rb +1 -1
- data/lib/bbcloud/version.rb +1 -1
- metadata +26 -61
- data/lib/bbcloud/commands/servers-restart.rb +0 -30
- data/lib/bbcloud/vendor/hirb/.gemspec +0 -22
- data/lib/bbcloud/vendor/hirb/CHANGELOG.rdoc +0 -106
- data/lib/bbcloud/vendor/hirb/LICENSE.txt +0 -22
- data/lib/bbcloud/vendor/hirb/README.rdoc +0 -182
- data/lib/bbcloud/vendor/hirb/Rakefile +0 -35
- data/lib/bbcloud/vendor/hirb/lib/bond/completions/hirb.rb +0 -15
- data/lib/bbcloud/vendor/hirb/lib/hirb/console.rb +0 -43
- data/lib/bbcloud/vendor/hirb/lib/hirb/dynamic_view.rb +0 -113
- data/lib/bbcloud/vendor/hirb/lib/hirb/formatter.rb +0 -116
- data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/auto_table.rb +0 -24
- data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/object_table.rb +0 -14
- data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/parent_child_tree.rb +0 -24
- data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/table/filters.rb +0 -10
- data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/table/resizer.rb +0 -82
- data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/table.rb +0 -323
- data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/tree.rb +0 -181
- data/lib/bbcloud/vendor/hirb/lib/hirb/helpers/vertical_table.rb +0 -37
- data/lib/bbcloud/vendor/hirb/lib/hirb/helpers.rb +0 -17
- data/lib/bbcloud/vendor/hirb/lib/hirb/import_object.rb +0 -10
- data/lib/bbcloud/vendor/hirb/lib/hirb/menu.rb +0 -221
- data/lib/bbcloud/vendor/hirb/lib/hirb/pager.rb +0 -95
- data/lib/bbcloud/vendor/hirb/lib/hirb/string.rb +0 -44
- data/lib/bbcloud/vendor/hirb/lib/hirb/util.rb +0 -96
- data/lib/bbcloud/vendor/hirb/lib/hirb/version.rb +0 -3
- data/lib/bbcloud/vendor/hirb/lib/hirb/view.rb +0 -284
- data/lib/bbcloud/vendor/hirb/lib/hirb/views/couch_db.rb +0 -11
- data/lib/bbcloud/vendor/hirb/lib/hirb/views/misc_db.rb +0 -15
- data/lib/bbcloud/vendor/hirb/lib/hirb/views/mongo_db.rb +0 -14
- data/lib/bbcloud/vendor/hirb/lib/hirb/views/orm.rb +0 -11
- data/lib/bbcloud/vendor/hirb/lib/hirb/views/rails.rb +0 -19
- data/lib/bbcloud/vendor/hirb/lib/hirb/views.rb +0 -8
- data/lib/bbcloud/vendor/hirb/lib/hirb.rb +0 -81
- data/lib/bbcloud/vendor/hirb/test/auto_table_test.rb +0 -30
- data/lib/bbcloud/vendor/hirb/test/console_test.rb +0 -27
- data/lib/bbcloud/vendor/hirb/test/deps.rip +0 -4
- data/lib/bbcloud/vendor/hirb/test/dynamic_view_test.rb +0 -94
- data/lib/bbcloud/vendor/hirb/test/formatter_test.rb +0 -171
- data/lib/bbcloud/vendor/hirb/test/hirb_test.rb +0 -39
- data/lib/bbcloud/vendor/hirb/test/import_test.rb +0 -9
- data/lib/bbcloud/vendor/hirb/test/menu_test.rb +0 -239
- data/lib/bbcloud/vendor/hirb/test/object_table_test.rb +0 -79
- data/lib/bbcloud/vendor/hirb/test/pager_test.rb +0 -162
- data/lib/bbcloud/vendor/hirb/test/resizer_test.rb +0 -62
- data/lib/bbcloud/vendor/hirb/test/table_test.rb +0 -550
- data/lib/bbcloud/vendor/hirb/test/test_helper.rb +0 -61
- data/lib/bbcloud/vendor/hirb/test/tree_test.rb +0 -184
- data/lib/bbcloud/vendor/hirb/test/util_test.rb +0 -59
- data/lib/bbcloud/vendor/hirb/test/view_test.rb +0 -172
- data/lib/bbcloud/vendor/hirb/test/views_test.rb +0 -13
@@ -1,284 +0,0 @@
|
|
1
|
-
module Hirb
|
2
|
-
# This class is responsible for managing all view-related functionality.
|
3
|
-
#
|
4
|
-
# == Create a View
|
5
|
-
# Let's create a simple view for Hash objects:
|
6
|
-
# $ irb -rubygems
|
7
|
-
# >> require 'hirb'
|
8
|
-
# =>true
|
9
|
-
# >> Hirb.enable
|
10
|
-
# =>nil
|
11
|
-
# >> require 'yaml'
|
12
|
-
# =>true
|
13
|
-
#
|
14
|
-
# # A view method is the smallest view
|
15
|
-
# >> def yaml(output); output.to_yaml; end
|
16
|
-
# => nil
|
17
|
-
# # Add the view
|
18
|
-
# >> Hirb.add_view Hash, :method=>:yaml
|
19
|
-
# => true
|
20
|
-
#
|
21
|
-
# # Hashes now appear as yaml
|
22
|
-
# >> {:a=>1, :b=>{:c=>3}}
|
23
|
-
# ---
|
24
|
-
# :a : 1
|
25
|
-
# :b :
|
26
|
-
# :c : 3
|
27
|
-
# => true
|
28
|
-
#
|
29
|
-
# Another way of creating a view is a Helper class:
|
30
|
-
#
|
31
|
-
# # Create yaml view class
|
32
|
-
# >> class Hirb::Helpers::Yaml; def self.render(output, options={}); output.to_yaml; end ;end
|
33
|
-
# =>nil
|
34
|
-
# # Add the view
|
35
|
-
# >> Hirb.add_view Hash, :class=>Hirb::Helpers::Yaml
|
36
|
-
# =>true
|
37
|
-
#
|
38
|
-
# # Hashes appear as yaml like above ...
|
39
|
-
#
|
40
|
-
# == Configure a View
|
41
|
-
# To configure the above Helper class as a view, either pass Hirb.enable a hash:
|
42
|
-
# # In .irbrc
|
43
|
-
# require 'hirb'
|
44
|
-
# # View class needs to come before enable()
|
45
|
-
# class Hirb::Helpers::Yaml; def self.render(output, options={}); output.to_yaml; end ;end
|
46
|
-
# Hirb.enable :output=>{"Hash"=>{:class=>"Hirb::Helpers::Yaml"}}
|
47
|
-
#
|
48
|
-
# Or create a config file at config/hirb.yml or ~/.hirb.yml:
|
49
|
-
# # The config file for the yaml example would look like:
|
50
|
-
# # ---
|
51
|
-
# # :output :
|
52
|
-
# # Hash :
|
53
|
-
# # :class : Hirb::Helpers::Yaml
|
54
|
-
#
|
55
|
-
# # In .irbrc
|
56
|
-
# require 'hirb'
|
57
|
-
# # View class needs to come before enable()
|
58
|
-
# class Hirb::Helpers::Yaml; def self.render(output, options={}); output.to_yaml; end ;end
|
59
|
-
# Hirb.enable
|
60
|
-
#
|
61
|
-
# For more about configuring Hirb, see the Config Files section in Hirb.
|
62
|
-
module View
|
63
|
-
DEFAULT_WIDTH = 120
|
64
|
-
DEFAULT_HEIGHT = 40
|
65
|
-
class<<self
|
66
|
-
attr_accessor :render_method
|
67
|
-
attr_reader :config
|
68
|
-
|
69
|
-
# This activates view functionality i.e. the formatter, pager and size detection. If irb exists, it overrides irb's output
|
70
|
-
# method with Hirb::View.view_output. When called multiple times, new configs are merged into the existing config.
|
71
|
-
# If using Wirble, you should call this after it. The view configuration can be specified in a hash via a config file,
|
72
|
-
# or as options to this method. In addition to the config keys mentioned in Hirb, options also take the following keys:
|
73
|
-
# ==== Options:
|
74
|
-
# * config_file: Name of config file(s) that are merged into existing config
|
75
|
-
# * output_method: Specify an object's class and instance method (separated by a period) to be realiased with
|
76
|
-
# hirb's view system. The instance method should take a string to be output. Default is IRB::Irb.output_value
|
77
|
-
# if using irb.
|
78
|
-
# Examples:
|
79
|
-
# Hirb.enable
|
80
|
-
# Hirb.enable :formatter=>false, :output_method=>"Mini.output"
|
81
|
-
def enable(options={}, &block)
|
82
|
-
Array(options.delete(:config_file)).each {|e|
|
83
|
-
@new_config_file = true
|
84
|
-
Hirb.config_files << e
|
85
|
-
}
|
86
|
-
enable_output_method(options.delete(:output_method))
|
87
|
-
merge_or_load_config options
|
88
|
-
resize(config[:width], config[:height])
|
89
|
-
@enabled = true
|
90
|
-
end
|
91
|
-
|
92
|
-
# Indicates if Hirb::View is enabled.
|
93
|
-
def enabled?
|
94
|
-
@enabled || false
|
95
|
-
end
|
96
|
-
|
97
|
-
# Disable's Hirb's output and revert's irb's output method if irb exists.
|
98
|
-
def disable
|
99
|
-
@enabled = false
|
100
|
-
unalias_output_method(@output_method) if @output_method
|
101
|
-
false
|
102
|
-
end
|
103
|
-
|
104
|
-
# Toggles pager on or off. The pager only works while Hirb::View is enabled.
|
105
|
-
def toggle_pager
|
106
|
-
config[:pager] = !config[:pager]
|
107
|
-
end
|
108
|
-
|
109
|
-
# Toggles formatter on or off.
|
110
|
-
def toggle_formatter
|
111
|
-
config[:formatter] = !config[:formatter]
|
112
|
-
end
|
113
|
-
|
114
|
-
# Resizes the console width and height for use with the table and pager i.e. after having resized the console window. *nix users
|
115
|
-
# should only have to call this method. Non-*nix users should call this method with explicit width and height. If you don't know
|
116
|
-
# your width and height, in irb play with "a"* width to find width and puts "a\n" * height to find height.
|
117
|
-
def resize(width=nil, height=nil)
|
118
|
-
config[:width], config[:height] = determine_terminal_size(width, height)
|
119
|
-
pager.resize(config[:width], config[:height])
|
120
|
-
end
|
121
|
-
|
122
|
-
# This is the main method of this class. When view is enabled, this method searches for a formatter it can use for the output and if
|
123
|
-
# successful renders it using render_method(). The options this method takes are helper config hashes as described in
|
124
|
-
# Hirb::Formatter.format_output(). Returns true if successful and false if no formatting is done or if not enabled.
|
125
|
-
def view_output(output, options={})
|
126
|
-
enabled? && config[:formatter] && render_output(output, options)
|
127
|
-
rescue Exception=>e
|
128
|
-
if config[:ignore_errors]
|
129
|
-
$stderr.puts "Hirb Error: #{e.message}"
|
130
|
-
false
|
131
|
-
else
|
132
|
-
index = (obj = e.backtrace.find {|f| f =~ /^\(eval\)/}) ? e.backtrace.index(obj) : e.backtrace.length
|
133
|
-
$stderr.puts "Hirb Error: #{e.message}", e.backtrace.slice(0,index).map {|e| " " + e }
|
134
|
-
true
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
# Captures STDOUT and renders it using render_method(). The main use case is to conditionally page captured stdout.
|
139
|
-
def capture_and_render(&block)
|
140
|
-
render_method.call Util.capture_stdout(&block)
|
141
|
-
end
|
142
|
-
|
143
|
-
# A lambda or proc which handles the final formatted object.
|
144
|
-
# Although this pages/puts the object by default, it could be set to do other things
|
145
|
-
# i.e. write the formatted object to a file.
|
146
|
-
def render_method
|
147
|
-
@render_method ||= default_render_method
|
148
|
-
end
|
149
|
-
|
150
|
-
# Resets render_method back to its default.
|
151
|
-
def reset_render_method
|
152
|
-
@render_method = default_render_method
|
153
|
-
end
|
154
|
-
|
155
|
-
# Current console width
|
156
|
-
def width
|
157
|
-
config && config[:width] ? config[:width] : DEFAULT_WIDTH
|
158
|
-
end
|
159
|
-
|
160
|
-
# Current console height
|
161
|
-
def height
|
162
|
-
config && config[:height] ? config[:height] : DEFAULT_HEIGHT
|
163
|
-
end
|
164
|
-
|
165
|
-
# Current formatter config, storing a hash of all static views
|
166
|
-
def formatter_config
|
167
|
-
formatter.config
|
168
|
-
end
|
169
|
-
|
170
|
-
# Adds a view when View is enabled. See Formatter.add_view for more details.
|
171
|
-
def add(klass, view_config)
|
172
|
-
if enabled?
|
173
|
-
formatter.add_view(klass, view_config)
|
174
|
-
else
|
175
|
-
puts "View must be enabled to add a view"
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
#:stopdoc:
|
180
|
-
def enable_output_method(meth)
|
181
|
-
if (meth ||= Object.const_defined?(:IRB) ? "IRB::Irb.output_value" : false) && !@output_method
|
182
|
-
@output_method = meth
|
183
|
-
alias_output_method(@output_method)
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
def unalias_output_method(output_method)
|
188
|
-
klass, klass_method = output_method.split(".")
|
189
|
-
eval %[
|
190
|
-
::#{klass}.class_eval do
|
191
|
-
alias_method :#{klass_method}, :non_hirb_view_output
|
192
|
-
end
|
193
|
-
]
|
194
|
-
@output_method = nil
|
195
|
-
end
|
196
|
-
|
197
|
-
def alias_output_method(output_method)
|
198
|
-
klass, klass_method = output_method.split(".")
|
199
|
-
eval %[
|
200
|
-
::#{klass}.class_eval do
|
201
|
-
alias_method :non_hirb_view_output, :#{klass_method}
|
202
|
-
if '#{klass}' == "IRB::Irb"
|
203
|
-
def #{klass_method} #:nodoc:
|
204
|
-
Hirb::View.view_output(@context.last_value) || Hirb::View.page_output(@context.last_value.inspect, true) ||
|
205
|
-
non_hirb_view_output
|
206
|
-
end
|
207
|
-
else
|
208
|
-
def #{klass_method}(output_string) #:nodoc:
|
209
|
-
Hirb::View.view_output(output_string) || Hirb::View.page_output(output_string.inspect, true) ||
|
210
|
-
non_hirb_view_output(output_string)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
]
|
215
|
-
end
|
216
|
-
|
217
|
-
def render_output(output, options={})
|
218
|
-
if (formatted_output = formatter.format_output(output, options))
|
219
|
-
render_method.call(formatted_output)
|
220
|
-
true
|
221
|
-
else
|
222
|
-
false
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
def determine_terminal_size(width, height)
|
227
|
-
detected = (width.nil? || height.nil?) ? Util.detect_terminal_size || [] : []
|
228
|
-
[width || detected[0] || DEFAULT_WIDTH , height || detected[1] || DEFAULT_HEIGHT]
|
229
|
-
end
|
230
|
-
|
231
|
-
def page_output(output, inspect_mode=false)
|
232
|
-
if enabled? && config[:pager] && pager.activated_by?(output, inspect_mode)
|
233
|
-
pager.page(output, inspect_mode)
|
234
|
-
true
|
235
|
-
else
|
236
|
-
false
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
def pager
|
241
|
-
@pager ||= Pager.new(config[:width], config[:height], :pager_command=>config[:pager_command])
|
242
|
-
end
|
243
|
-
|
244
|
-
def pager=(value); @pager = value; end
|
245
|
-
|
246
|
-
def formatter(reload=false)
|
247
|
-
@formatter = reload || @formatter.nil? ? Formatter.new(config[:output]) : @formatter
|
248
|
-
end
|
249
|
-
|
250
|
-
def formatter=(value); @formatter = value; end
|
251
|
-
|
252
|
-
def merge_or_load_config(additional_config={})
|
253
|
-
if @config && (@new_config_file || !additional_config.empty?)
|
254
|
-
Hirb.config = nil
|
255
|
-
load_config Util.recursive_hash_merge(@config, additional_config)
|
256
|
-
@new_config_file = false
|
257
|
-
elsif !@enabled
|
258
|
-
load_config(additional_config)
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
def load_config(additional_config={})
|
263
|
-
@config = Util.recursive_hash_merge default_config, additional_config
|
264
|
-
formatter(true)
|
265
|
-
true
|
266
|
-
end
|
267
|
-
|
268
|
-
def config_loaded?; !!@config; end
|
269
|
-
|
270
|
-
def config
|
271
|
-
@config
|
272
|
-
end
|
273
|
-
|
274
|
-
def default_render_method
|
275
|
-
lambda {|output| page_output(output) || puts(output) }
|
276
|
-
end
|
277
|
-
|
278
|
-
def default_config
|
279
|
-
Util.recursive_hash_merge({:pager=>true, :formatter=>true}, Hirb.config || {})
|
280
|
-
end
|
281
|
-
#:startdoc:
|
282
|
-
end
|
283
|
-
end
|
284
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module Hirb::Views::CouchDb #:nodoc:
|
2
|
-
def default_couch(obj)
|
3
|
-
{:fields=>([:_id] + obj.class.properties.map {|e| e.name }) }
|
4
|
-
end
|
5
|
-
|
6
|
-
alias_method :couch_rest__extended_document_view, :default_couch
|
7
|
-
alias_method :couch_foo__base_view, :default_couch
|
8
|
-
alias_method :couch_potato__persistence_view, :default_couch
|
9
|
-
end
|
10
|
-
|
11
|
-
Hirb::DynamicView.add Hirb::Views::CouchDb, :helper=>:auto_table
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Hirb::Views::MiscDb #:nodoc:
|
2
|
-
def friendly__document_view(obj)
|
3
|
-
{:fields=>obj.class.attributes.keys - [:id]}
|
4
|
-
end
|
5
|
-
|
6
|
-
def ripple__document_view(obj)
|
7
|
-
{:fields=>obj.class.properties.keys}
|
8
|
-
end
|
9
|
-
|
10
|
-
def d_b_i__row_view(obj)
|
11
|
-
{:fields=>obj.column_names, :table_class=>Hirb::Helpers::Table}
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
Hirb::DynamicView.add Hirb::Views::MiscDb, :helper=>:auto_table
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Hirb::Views::MongoDb #:nodoc:
|
2
|
-
def mongoid__document_view(obj)
|
3
|
-
{:fields=>['_id'] + obj.class.fields.keys}
|
4
|
-
end
|
5
|
-
|
6
|
-
def mongo_mapper__document_view(obj)
|
7
|
-
fields = obj.class.column_names
|
8
|
-
fields.delete('_id') && fields.unshift('_id')
|
9
|
-
{:fields=>fields}
|
10
|
-
end
|
11
|
-
alias_method :mongo_mapper__embedded_document_view, :mongo_mapper__document_view
|
12
|
-
end
|
13
|
-
|
14
|
-
Hirb::DynamicView.add Hirb::Views::MongoDb, :helper=>:auto_table
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module Hirb::Views::ORM #:nodoc:
|
2
|
-
def data_mapper__resource_view(obj)
|
3
|
-
{:fields=>obj.class.properties.map {|e| e.name }}
|
4
|
-
end
|
5
|
-
|
6
|
-
def sequel__model_view(obj)
|
7
|
-
{:fields=>obj.class.columns}
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
Hirb::DynamicView.add Hirb::Views::ORM, :helper=>:auto_table
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Hirb::Views::Rails #:nodoc:
|
2
|
-
def active_record__base_view(obj)
|
3
|
-
{:fields=>get_active_record_fields(obj)}
|
4
|
-
end
|
5
|
-
|
6
|
-
def get_active_record_fields(obj)
|
7
|
-
fields = obj.class.column_names.map {|e| e.to_sym }
|
8
|
-
# if query used select
|
9
|
-
if obj.attributes.keys.sort != obj.class.column_names.sort
|
10
|
-
selected_columns = obj.attributes.keys
|
11
|
-
sorted_columns = obj.class.column_names.dup.delete_if {|e| !selected_columns.include?(e) }
|
12
|
-
sorted_columns += (selected_columns - sorted_columns)
|
13
|
-
fields = sorted_columns.map {|e| e.to_sym}
|
14
|
-
end
|
15
|
-
fields
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
Hirb::DynamicView.add Hirb::Views::Rails, :helper=>:auto_table
|
@@ -1,81 +0,0 @@
|
|
1
|
-
# Needed by Hirb::String to handle multibyte characters
|
2
|
-
$KCODE = 'u' if RUBY_VERSION < '1.9'
|
3
|
-
|
4
|
-
require 'hirb/util'
|
5
|
-
require 'hirb/string'
|
6
|
-
require 'hirb/formatter' # must come before helpers/auto_table
|
7
|
-
require 'hirb/dynamic_view'
|
8
|
-
require 'hirb/helpers'
|
9
|
-
require 'hirb/views'
|
10
|
-
require 'hirb/view'
|
11
|
-
require 'hirb/console'
|
12
|
-
require 'hirb/pager'
|
13
|
-
require 'hirb/menu'
|
14
|
-
require 'hirb/version'
|
15
|
-
|
16
|
-
# Most of Hirb's functionality is in Hirb::View.
|
17
|
-
# For a tutorial on configuring and creating views see Hirb::View. For a tutorial on dynamic views see Hirb::DynamicView.
|
18
|
-
#
|
19
|
-
# == Config Files
|
20
|
-
# Hirb can have multiple config files defined by config_files(). These config files
|
21
|
-
# have the following top level keys:
|
22
|
-
# [*:output*] This hash is used by the formatter object. See Hirb::Formatter.config for its format.
|
23
|
-
# [*:width*] Width of the terminal/console. Defaults to Hirb::View::DEFAULT_WIDTH or possibly autodetected when Hirb is enabled.
|
24
|
-
# [*:height*] Height of the terminal/console. Defaults to Hirb::View::DEFAULT_HEIGHT or possibly autodetected when Hirb is enabled.
|
25
|
-
# [*:formatter*] Boolean which determines if the formatter is enabled. Defaults to true.
|
26
|
-
# [*:pager*] Boolean which determines if the pager is enabled. Defaults to true.
|
27
|
-
# [*:pager_command*] Command to be used for paging. Command can have options after it i.e. 'less -r'.
|
28
|
-
# Defaults to common pagers i.e. less and more if detected.
|
29
|
-
# [*:ignore_errors*] Boolean which ignores internal view errors and continues with original view
|
30
|
-
# (i.e. #inspect for irb). Defaults to false.
|
31
|
-
module Hirb
|
32
|
-
class <<self
|
33
|
-
attr_accessor :config_files, :config
|
34
|
-
|
35
|
-
# Enables view functionality. See Hirb::View.enable for details.
|
36
|
-
def enable(options={}, &block)
|
37
|
-
View.enable(options, &block)
|
38
|
-
end
|
39
|
-
|
40
|
-
# Disables view functionality. See Hirb::View.disable for details.
|
41
|
-
def disable
|
42
|
-
View.disable
|
43
|
-
end
|
44
|
-
|
45
|
-
# Adds views. See Hirb::View.add for details.
|
46
|
-
def add_view(view, options, &block)
|
47
|
-
View.add(view, options, &block)
|
48
|
-
end
|
49
|
-
|
50
|
-
# Adds views. See Hirb::DynamicView.add for details.
|
51
|
-
def add_dynamic_view(view, options, &block)
|
52
|
-
DynamicView.add(view, options, &block)
|
53
|
-
end
|
54
|
-
|
55
|
-
# Array of config files which are merged sequentially to produce config.
|
56
|
-
# Defaults to config/hirb.yml and ~/.hirb_yml
|
57
|
-
def config_files
|
58
|
-
@config_files ||= default_config_files
|
59
|
-
end
|
60
|
-
|
61
|
-
#:stopdoc:
|
62
|
-
def default_config_files
|
63
|
-
[File.join(Util.find_home, ".hirb.yml")] +
|
64
|
-
(File.exists?('config/hirb.yml') ? ['config/hirb.yml'] : [])
|
65
|
-
end
|
66
|
-
|
67
|
-
def read_config_file(file=config_file)
|
68
|
-
File.exists?(file) ? YAML::load_file(file) : {}
|
69
|
-
end
|
70
|
-
|
71
|
-
def config(reload=false)
|
72
|
-
if (@config.nil? || reload)
|
73
|
-
@config = config_files.inject({}) {|acc,e|
|
74
|
-
Util.recursive_hash_merge(acc,read_config_file(e))
|
75
|
-
}
|
76
|
-
end
|
77
|
-
@config
|
78
|
-
end
|
79
|
-
#:startdoc:
|
80
|
-
end
|
81
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
describe "auto table" do
|
4
|
-
it "converts nonarrays to arrays and renders" do
|
5
|
-
require 'set'
|
6
|
-
expected_table = <<-TABLE.unindent
|
7
|
-
+-------+
|
8
|
-
| value |
|
9
|
-
+-------+
|
10
|
-
| 1 |
|
11
|
-
| 2 |
|
12
|
-
| 3 |
|
13
|
-
+-------+
|
14
|
-
3 rows in set
|
15
|
-
TABLE
|
16
|
-
Helpers::AutoTable.render(::Set.new([1,2,3])).should == expected_table
|
17
|
-
end
|
18
|
-
|
19
|
-
it "renders hash" do
|
20
|
-
expected_table = <<-TABLE.unindent
|
21
|
-
+---+-------+
|
22
|
-
| 0 | 1 |
|
23
|
-
+---+-------+
|
24
|
-
| a | 12345 |
|
25
|
-
+---+-------+
|
26
|
-
1 row in set
|
27
|
-
TABLE
|
28
|
-
Helpers::AutoTable.render({:a=>12345}).should == expected_table
|
29
|
-
end
|
30
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
describe "Console" do
|
4
|
-
it "#table is called without Hirb enabled" do
|
5
|
-
extend Hirb::Console
|
6
|
-
reset_config
|
7
|
-
expected_table = <<-TABLE.unindent
|
8
|
-
+-------+
|
9
|
-
| value |
|
10
|
-
+-------+
|
11
|
-
| 5 |
|
12
|
-
| 3 |
|
13
|
-
+-------+
|
14
|
-
2 rows in set
|
15
|
-
TABLE
|
16
|
-
capture_stdout {
|
17
|
-
table([5,3], :fields=>[:to_s])
|
18
|
-
}.should == expected_table +"\n"
|
19
|
-
end
|
20
|
-
|
21
|
-
it ".render_output sets config if it wasn't before" do
|
22
|
-
reset_config
|
23
|
-
View.expects(:render_output)
|
24
|
-
Console.render_output('blah')
|
25
|
-
View.config.is_a?(Hash).should == true
|
26
|
-
end
|
27
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
describe "DynamicView" do
|
4
|
-
def output_expects(output, expects)
|
5
|
-
Helpers::ObjectTable.expects(:render).with(output, expects)
|
6
|
-
Helpers::AutoTable.render(output)
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "add" do
|
10
|
-
before_all { View.load_config }
|
11
|
-
|
12
|
-
it "raises error if no :helper option" do
|
13
|
-
lambda { Hirb.add_dynamic_view 'Blah', {} }.should.raise(ArgumentError).
|
14
|
-
message.should =~ /:helper.*required/
|
15
|
-
end
|
16
|
-
|
17
|
-
it "raises error if :helper option not a dynamic_view module" do
|
18
|
-
lambda { Hirb.add_dynamic_view('Blah', :helper=>:table) {|obj| } }.
|
19
|
-
should.raise(ArgumentError).message.should =~ /:helper.*must/
|
20
|
-
end
|
21
|
-
|
22
|
-
it "raises error if views module not a module" do
|
23
|
-
lambda { Hirb.add_dynamic_view 'Blah', :helper=>:auto_table }.should.raise(ArgumentError).
|
24
|
-
message.should =~ /must be a module/
|
25
|
-
end
|
26
|
-
|
27
|
-
it "adds a view with block" do
|
28
|
-
Hirb.add_dynamic_view('Date', :helper=>:auto_table) do |obj|
|
29
|
-
{:fields=>obj.class::DAYNAMES}
|
30
|
-
end
|
31
|
-
output_expects [Date.new], :fields=>Date::DAYNAMES
|
32
|
-
end
|
33
|
-
|
34
|
-
it "when adding views with a block, second view for same class overrides first one" do
|
35
|
-
Hirb.add_dynamic_view('Date', :helper=>:auto_table) do |obj|
|
36
|
-
{:fields=>obj.class::DAYNAMES}
|
37
|
-
end
|
38
|
-
Hirb.add_dynamic_view('Date', :helper=>:auto_table) do |obj|
|
39
|
-
{:fields=>[:blah]}
|
40
|
-
end
|
41
|
-
output_expects [Date.new], :fields=>[:blah]
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
it "class_to_method and method_to_class convert to each other" do
|
46
|
-
["DBI::Row", "Hirb::View"].each do |e|
|
47
|
-
Helpers::AutoTable.method_to_class(DynamicView.class_to_method(e).downcase).should == e
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
it "class_to_method converts correctly" do
|
52
|
-
DynamicView.class_to_method("DBI::Row").should == 'd_b_i__row_view'
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "dynamic_view" do
|
56
|
-
def define_view(mod_name= :Blah, &block)
|
57
|
-
mod = Views.const_set(mod_name, Module.new)
|
58
|
-
mod_block = block_given? ? block : lambda {|obj| {:fields=>obj.class::DAYNAMES}}
|
59
|
-
mod.send(:define_method, :date_view, mod_block)
|
60
|
-
Hirb.add_dynamic_view mod, :helper=>:auto_table
|
61
|
-
end
|
62
|
-
|
63
|
-
before_all { View.load_config }
|
64
|
-
before { Formatter.dynamic_config = {} }
|
65
|
-
after { Views.send(:remove_const, :Blah) }
|
66
|
-
|
67
|
-
it "sets a view's options" do
|
68
|
-
define_view
|
69
|
-
output_expects [Date.new], :fields=>Date::DAYNAMES
|
70
|
-
end
|
71
|
-
|
72
|
-
it "does override existing formatter dynamic_config" do
|
73
|
-
Formatter.dynamic_config["Date"] = {:class=>Helpers::Table}
|
74
|
-
define_view
|
75
|
-
Formatter.dynamic_config["Date"].should == {:class=>Hirb::Helpers::AutoTable, :ancestor=>true}
|
76
|
-
end
|
77
|
-
|
78
|
-
it "raises a readable error when error occurs in a view" do
|
79
|
-
define_view {|obj| raise 'blah' }
|
80
|
-
lambda { Helpers::AutoTable.render([Date.new]) }.should.raise(RuntimeError).
|
81
|
-
message.should =~ /'Date'.*date_view.*\nblah/
|
82
|
-
end
|
83
|
-
|
84
|
-
it "another view can reuse an old view's options" do
|
85
|
-
define_view
|
86
|
-
define_view(:Blah2) do |obj|
|
87
|
-
{:fields=>obj.class::DAYNAMES + ['blah']}
|
88
|
-
end
|
89
|
-
output_expects [Date.new], :fields=>(Date::DAYNAMES + ['blah'])
|
90
|
-
end
|
91
|
-
after_all { reset_config }
|
92
|
-
end
|
93
|
-
after_all { Formatter.dynamic_config = {} }
|
94
|
-
end
|