hirb 0.7.1 → 0.7.3

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3c82103d6a98efbf7551286da42328fe06933713
4
+ data.tar.gz: 007e3755d06c41814d5b3e80731f55c4b4cd47ff
5
+ SHA512:
6
+ metadata.gz: aad1ff6678f0a2b1a33aeeaf5ccf2cf647c96e9d0e4e077efec0e22c3c77ab3892534cba9810709b16b6f9729233658fe191ef206358f9c73e92db8b7677f938
7
+ data.tar.gz: 97a34adef83202ddfe42e989b8ef4ef639ce35b077258ca415af034f6cec0ba40be3786ffafd73030233ad4d82eabe23c8a31306a68627d7c6996d50cf0669cf
data/.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.add_development_dependency 'mocha', '~> 0.12.1'
16
16
  s.add_development_dependency 'mocha-on-bacon', '~> 0.2.1'
17
17
  s.add_development_dependency 'bacon-bits'
18
- s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} {.,test,spec}/deps.rip]) + %w{Rakefile .gemspec .travis.yml}
18
+ s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc,md} ext/**/*.{rb,c}]) + %w{Rakefile .gemspec .travis.yml}
19
19
  s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
20
20
  s.license = 'MIT'
21
21
  end
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.7.3
2
+ * Remove warnings
3
+
4
+ == 0.7.2
5
+ * Allow full paths on $PAGER
6
+ * Fix AR tables with no id column
7
+
1
8
  == 0.7.1
2
9
  * Add :style option
3
10
  * Fix mocha dep issue
data/CONTRIBUTING.md ADDED
@@ -0,0 +1 @@
1
+ Thanks for trying out this project! [See here for contribution guidelines.](http://tagaholic.me/contributing.html)
data/README.rdoc CHANGED
@@ -161,8 +161,11 @@ Although views by default are printed to STDOUT, they can be easily modified to
161
161
 
162
162
  == Pager
163
163
 
164
- Hirb has both pager and formatter functionality enabled by default.
165
- If you want to turn off the functionality of either you can pass that in at startup:
164
+ Hirb has both pager and formatter functionality enabled by default. Note - if you copy and paste
165
+ into your ruby console and think that one of your lines will kick off the pager, be aware that subsequent
166
+ characters will go to your pager and could cause side effects like saving a file.
167
+
168
+ If you want to turn off the functionality of either pager or formatter, pass that in at startup:
166
169
 
167
170
  Hirb.enable :pager=>false
168
171
  Hirb.enable :formatter=>false
@@ -187,7 +190,8 @@ Table code from http://gist.github.com/72234 and {my console app's needs}[http:/
187
190
  * Chrononaut for vertical table helper.
188
191
  * janlelis for unicode table helper.
189
192
  * technogeeky and FND for markdown table helper.
190
- * hsume2, crafterm, spastorino, xaviershay, bogdan, asanghi, vwall, maxmeyer, jimjh and joshua for patches.
193
+ * hsume2, crafterm, spastorino, xaviershay, bogdan, asanghi, vwall, maxmeyer, jimjh, ddoherty03,
194
+ rochefort and joshua for patches.
191
195
 
192
196
  == Bugs/Issues
193
197
  Please report them {on github}[http://github.com/cldwalker/hirb/issues].
@@ -29,7 +29,7 @@ module Hirb
29
29
  # [*:options*] Options to pass the helper method or class.
30
30
  # [*:ancestor*] Boolean which when true causes subclasses of the output class to inherit its config. This doesn't effect the current
31
31
  # output class. Defaults to false. This is used by ActiveRecord classes.
32
- #
32
+ #
33
33
  # Examples:
34
34
  # {'WWW::Delicious::Element'=>{:class=>'Hirb::Helpers::ObjectTable', :ancestor=>true, :options=>{:max_width=>180}}}
35
35
  # {'Date'=>{:class=>:auto_table, :ancestor=>true}}
@@ -101,10 +101,10 @@ module Hirb
101
101
  def build_klass_config(output_class)
102
102
  output_ancestors = output_class.ancestors.map {|e| e.to_s}.reverse
103
103
  output_ancestors.pop
104
- hash = output_ancestors.inject({}) {|h, klass|
105
- add_klass_config_if_true(h, klass) {|c,klass| c[klass] && c[klass][:ancestor] }
104
+ hash = output_ancestors.inject({}) {|h, ancestor_klass|
105
+ add_klass_config_if_true(h, ancestor_klass) {|c, klass| c[klass] && c[klass][:ancestor] }
106
106
  }
107
- add_klass_config_if_true(hash, output_class.to_s) {|c,klass| c[klass] }
107
+ add_klass_config_if_true(hash, output_class.to_s) {|c, klass| c[klass] }
108
108
  end
109
109
 
110
110
  def add_klass_config_if_true(hash, klass)
@@ -48,7 +48,7 @@ class Hirb::Helpers::Table
48
48
 
49
49
  # set all fields the same if relative doesn't work
50
50
  unless new_lengths.values.all? {|e| e > MIN_FIELD_LENGTH} && (sum(new_lengths.values) <= @width)
51
- new_lengths = @field_lengths.inject({}) {|t,(k,v)| t[k] = @width / @field_size; t }
51
+ new_lengths = @field_lengths.inject({}) {|t,(k,_v)| t[k] = @width / @field_size; t }
52
52
  end
53
53
  @field_lengths.each {|k,v| @field_lengths[k] = new_lengths[k] }
54
54
  end
@@ -302,6 +302,7 @@ class Helpers::Table
302
302
  max_fields.each {|k,max| @field_lengths[k] = max if @field_lengths[k].to_i > max }
303
303
  end
304
304
 
305
+ undef :max_fields
305
306
  def max_fields
306
307
  @max_fields ||= (@options[:max_fields] ||= {}).each {|k,v|
307
308
  @options[:max_fields][k] = (actual_width * v.to_f.abs).floor if v.to_f.abs < 1
@@ -312,6 +313,7 @@ class Helpers::Table
312
313
  @actual_width ||= self.width - (@fields.size * BORDER_LENGTH + 1)
313
314
  end
314
315
 
316
+ undef :width
315
317
  def width
316
318
  @width ||= @options[:max_width] || View.width
317
319
  end
data/lib/hirb/menu.rb CHANGED
@@ -89,7 +89,7 @@ module Hirb
89
89
  def choose_from_menu
90
90
  return unasked_choice if @output.size == 1 && !@options[:ask]
91
91
 
92
- if (helper_class = Util.any_const_get(@options[:helper_class]))
92
+ if (Util.any_const_get(@options[:helper_class]))
93
93
  View.render_output(@output, :class=>@options[:helper_class], :options=>@options.merge(:number=>true))
94
94
  else
95
95
  @output.each_with_index {|e,i| puts "#{i+1}: #{e}" }
data/lib/hirb/pager.rb CHANGED
@@ -8,9 +8,10 @@ module Hirb
8
8
  end
9
9
 
10
10
  def pager_command(*commands) #:nodoc:
11
- @pager_command = (!@pager_command.nil? && commands.empty?) ? @pager_command :
11
+ @pager_command = (!@pager_command.nil? && commands.empty?) ? @pager_command :
12
12
  begin
13
- commands = [ENV['PAGER'], 'less', 'more', 'pager'] if commands.empty?
13
+ env_pager = ENV['PAGER'] ? File.basename(ENV['PAGER']) : nil
14
+ commands = [env_pager, 'less', 'more', 'pager'] if commands.empty?
14
15
  commands.compact.uniq.find {|e| Util.command_exists?(e[/\w+/]) }
15
16
  end
16
17
  end
data/lib/hirb/util.rb CHANGED
@@ -13,7 +13,7 @@ module Hirb
13
13
  }
14
14
  klass
15
15
  rescue
16
- nil
16
+ nil
17
17
  end
18
18
  end
19
19
 
@@ -53,7 +53,7 @@ module Hirb
53
53
 
54
54
  # Determines if a shell command exists by searching for it in ENV['PATH'].
55
55
  def command_exists?(command)
56
- ENV['PATH'].split(File::PATH_SEPARATOR).any? {|d| File.exists? File.join(d, command) }
56
+ ENV['PATH'].split(File::PATH_SEPARATOR).any? {|d| File.exist? File.join(d, command) }
57
57
  end
58
58
 
59
59
  # Returns [width, height] of terminal when detected, nil if not detected.
data/lib/hirb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hirb
2
- VERSION = '0.7.1'
2
+ VERSION = '0.7.3'
3
3
  end
data/lib/hirb/view.rb CHANGED
@@ -22,7 +22,7 @@ module Hirb
22
22
  # >> {:a=>1, :b=>{:c=>3}}
23
23
  # ---
24
24
  # :a : 1
25
- # :b :
25
+ # :b :
26
26
  # :c : 3
27
27
  # => true
28
28
  #
@@ -75,7 +75,7 @@ module Hirb
75
75
  # Examples:
76
76
  # Hirb.enable
77
77
  # Hirb.enable :formatter=>false
78
- def enable(options={}, &block)
78
+ def enable(options={})
79
79
  Array(options.delete(:config_file)).each {|e|
80
80
  @new_config_file = true
81
81
  Hirb.config_files << e
@@ -115,9 +115,9 @@ module Hirb
115
115
  config[:width], config[:height] = determine_terminal_size(width, height)
116
116
  pager.resize(config[:width], config[:height])
117
117
  end
118
-
118
+
119
119
  # 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
120
- # successful renders it using render_method(). The options this method takes are helper config hashes as described in
120
+ # successful renders it using render_method(). The options this method takes are helper config hashes as described in
121
121
  # Hirb::Formatter.format_output(). Returns true if successful and false if no formatting is done or if not enabled.
122
122
  def view_output(output, options={})
123
123
  enabled? && config[:formatter] && render_output(output, options)
@@ -127,7 +127,7 @@ module Hirb
127
127
  false
128
128
  else
129
129
  index = (obj = e.backtrace.find {|f| f =~ /^\(eval\)/}) ? e.backtrace.index(obj) : e.backtrace.length
130
- $stderr.puts "Hirb Error: #{e.message}", e.backtrace.slice(0,index).map {|e| " " + e }
130
+ $stderr.puts "Hirb Error: #{e.message}", e.backtrace.slice(0,index).map {|_e| " " + _e }
131
131
  true
132
132
  end
133
133
  end
@@ -140,6 +140,7 @@ module Hirb
140
140
  # A lambda or proc which handles the final formatted object.
141
141
  # Although this pages/puts the object by default, it could be set to do other things
142
142
  # i.e. write the formatted object to a file.
143
+ undef :render_method
143
144
  def render_method
144
145
  @render_method ||= default_render_method
145
146
  end
@@ -148,7 +149,7 @@ module Hirb
148
149
  def reset_render_method
149
150
  @render_method = default_render_method
150
151
  end
151
-
152
+
152
153
  # Current console width
153
154
  def width
154
155
  config && config[:width] ? config[:width] : DEFAULT_WIDTH
@@ -253,10 +254,11 @@ module Hirb
253
254
 
254
255
  def config_loaded?; !!@config; end
255
256
 
257
+ undef :config
256
258
  def config
257
259
  @config
258
260
  end
259
-
261
+
260
262
  def default_render_method
261
263
  lambda {|output| page_output(output) || puts(output) }
262
264
  end
@@ -6,8 +6,8 @@ module Hirb::Views::Rails #:nodoc:
6
6
  def get_active_record_fields(obj)
7
7
  fields = obj.class.column_names.map {|e| e.to_sym }
8
8
  # if query used select
9
- if obj.attributes.keys.sort != obj.class.column_names.sort
10
- selected_columns = obj.attributes.keys
9
+ if obj.attributes.keys.compact.sort != obj.class.column_names.sort
10
+ selected_columns = obj.attributes.keys.compact
11
11
  sorted_columns = obj.class.column_names.dup.delete_if {|e| !selected_columns.include?(e) }
12
12
  sorted_columns += (selected_columns - sorted_columns)
13
13
  fields = sorted_columns.map {|e| e.to_sym}
@@ -16,4 +16,4 @@ module Hirb::Views::Rails #:nodoc:
16
16
  end
17
17
  end
18
18
 
19
- Hirb::DynamicView.add Hirb::Views::Rails, :helper=>:auto_table
19
+ Hirb::DynamicView.add Hirb::Views::Rails, :helper=>:auto_table
data/lib/hirb.rb CHANGED
@@ -34,8 +34,8 @@ module Hirb
34
34
  attr_accessor :config_files, :config
35
35
 
36
36
  # Enables view functionality. See Hirb::View.enable for details.
37
- def enable(options={}, &block)
38
- View.enable(options, &block)
37
+ def enable(options={})
38
+ View.enable(options)
39
39
  end
40
40
 
41
41
  # Disables view functionality. See Hirb::View.disable for details.
@@ -44,8 +44,8 @@ module Hirb
44
44
  end
45
45
 
46
46
  # Adds views. See Hirb::View.add for details.
47
- def add_view(view, options, &block)
48
- View.add(view, options, &block)
47
+ def add_view(view, options)
48
+ View.add(view, options)
49
49
  end
50
50
 
51
51
  # Adds views. See Hirb::DynamicView.add for details.
@@ -55,6 +55,7 @@ module Hirb
55
55
 
56
56
  # Array of config files which are merged sequentially to produce config.
57
57
  # Defaults to config/hirb.yml and ~/.hirb_yml
58
+ undef :config_files
58
59
  def config_files
59
60
  @config_files ||= default_config_files
60
61
  end
@@ -62,13 +63,14 @@ module Hirb
62
63
  #:stopdoc:
63
64
  def default_config_files
64
65
  [File.join(Util.find_home, ".hirb.yml")] +
65
- (File.exists?('config/hirb.yml') ? ['config/hirb.yml'] : [])
66
+ (File.exist?('config/hirb.yml') ? ['config/hirb.yml'] : [])
66
67
  end
67
68
 
68
69
  def read_config_file(file=config_file)
69
- File.exists?(file) ? YAML::load_file(file) : {}
70
+ File.exist?(file) ? YAML.load_file(file) : {}
70
71
  end
71
72
 
73
+ undef :config
72
74
  def config(reload=false)
73
75
  if (@config.nil? || reload)
74
76
  @config = config_files.inject({}) {|acc,e|
data/test/hirb_test.rb CHANGED
@@ -6,17 +6,17 @@ describe "Hirb" do
6
6
 
7
7
  it "config converts yaml when config file exists" do
8
8
  yaml_data = {:blah=>'blah'}
9
- File.stubs('exists?').returns(true)
9
+ File.stubs('exist?').returns(true)
10
10
  Hirb.config_files = ['ok']
11
- YAML::expects(:load_file).returns(yaml_data)
11
+ YAML.expects(:load_file).returns(yaml_data)
12
12
  Hirb.config.should == yaml_data
13
13
  end
14
-
14
+
15
15
  it "config defaults to hash when no config file" do
16
- File.stubs('exists?').returns(false)
16
+ File.stubs('exist?').returns(false)
17
17
  Hirb.config.should == {}
18
18
  end
19
-
19
+
20
20
  it "config reloads if given explicit reload" do
21
21
  Hirb.config
22
22
  Hirb.expects(:read_config_file).returns({})
@@ -36,4 +36,4 @@ describe "Hirb" do
36
36
  Hirb.config_files[0].class.should == String
37
37
  ENV["HOME"] = home
38
38
  end
39
- end
39
+ end
metadata CHANGED
@@ -1,78 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hirb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
5
- prerelease:
4
+ version: 0.7.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Gabriel Horner
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-25 00:00:00.000000000 Z
11
+ date: 2015-01-23 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bacon
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 1.1.0
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 1.1.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: mocha
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: 0.12.1
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: 0.12.1
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: mocha-on-bacon
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: 0.2.1
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: 0.2.1
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: bacon-bits
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  description: Hirb provides a mini view framework for console applications and uses
@@ -92,22 +83,30 @@ extra_rdoc_files:
92
83
  - README.rdoc
93
84
  - LICENSE.txt
94
85
  files:
86
+ - ".gemspec"
87
+ - ".travis.yml"
88
+ - CHANGELOG.rdoc
89
+ - CONTRIBUTING.md
90
+ - LICENSE.txt
91
+ - README.rdoc
92
+ - Rakefile
95
93
  - lib/bond/completions/hirb.rb
94
+ - lib/hirb.rb
96
95
  - lib/hirb/console.rb
97
96
  - lib/hirb/dynamic_view.rb
98
97
  - lib/hirb/formatter.rb
98
+ - lib/hirb/helpers.rb
99
99
  - lib/hirb/helpers/auto_table.rb
100
100
  - lib/hirb/helpers/markdown_table.rb
101
101
  - lib/hirb/helpers/object_table.rb
102
102
  - lib/hirb/helpers/parent_child_tree.rb
103
103
  - lib/hirb/helpers/tab_table.rb
104
+ - lib/hirb/helpers/table.rb
104
105
  - lib/hirb/helpers/table/filters.rb
105
106
  - lib/hirb/helpers/table/resizer.rb
106
- - lib/hirb/helpers/table.rb
107
107
  - lib/hirb/helpers/tree.rb
108
108
  - lib/hirb/helpers/unicode_table.rb
109
109
  - lib/hirb/helpers/vertical_table.rb
110
- - lib/hirb/helpers.rb
111
110
  - lib/hirb/import_object.rb
112
111
  - lib/hirb/menu.rb
113
112
  - lib/hirb/pager.rb
@@ -115,13 +114,12 @@ files:
115
114
  - lib/hirb/util.rb
116
115
  - lib/hirb/version.rb
117
116
  - lib/hirb/view.rb
117
+ - lib/hirb/views.rb
118
118
  - lib/hirb/views/couch_db.rb
119
119
  - lib/hirb/views/misc_db.rb
120
120
  - lib/hirb/views/mongo_db.rb
121
121
  - lib/hirb/views/orm.rb
122
122
  - lib/hirb/views/rails.rb
123
- - lib/hirb/views.rb
124
- - lib/hirb.rb
125
123
  - lib/ripl/hirb.rb
126
124
  - test/auto_table_test.rb
127
125
  - test/console_test.rb
@@ -139,37 +137,29 @@ files:
139
137
  - test/util_test.rb
140
138
  - test/view_test.rb
141
139
  - test/views_test.rb
142
- - LICENSE.txt
143
- - CHANGELOG.rdoc
144
- - README.rdoc
145
- - test/deps.rip
146
- - Rakefile
147
- - .gemspec
148
- - .travis.yml
149
140
  homepage: http://tagaholic.me/hirb/
150
141
  licenses:
151
142
  - MIT
143
+ metadata: {}
152
144
  post_install_message:
153
145
  rdoc_options: []
154
146
  require_paths:
155
147
  - lib
156
148
  required_ruby_version: !ruby/object:Gem::Requirement
157
- none: false
158
149
  requirements:
159
- - - ! '>='
150
+ - - ">="
160
151
  - !ruby/object:Gem::Version
161
152
  version: '0'
162
153
  required_rubygems_version: !ruby/object:Gem::Requirement
163
- none: false
164
154
  requirements:
165
- - - ! '>='
155
+ - - ">="
166
156
  - !ruby/object:Gem::Version
167
157
  version: 1.3.5
168
158
  requirements: []
169
159
  rubyforge_project:
170
- rubygems_version: 1.8.24
160
+ rubygems_version: 2.4.5
171
161
  signing_key:
172
- specification_version: 3
162
+ specification_version: 4
173
163
  summary: A mini view framework for console/irb that's easy to use, even while under
174
164
  its influence.
175
165
  test_files: []
data/test/deps.rip DELETED
@@ -1,4 +0,0 @@
1
- bacon >=1.1.0
2
- mocha ~>0.12.1
3
- mocha-on-bacon ~>0.2.1
4
- bacon-bits >=0