beaver 1.2.0 → 1.3.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.
@@ -2,18 +2,18 @@ require 'yaml'
2
2
  require 'time'
3
3
 
4
4
  module Beaver
5
- # Sundry utility methods and classes for use by Beaver
5
+ # Sundry utility methods for use by Beaver
6
6
  module Utils
7
- LBRACE, RBRACE = '{', '}'
8
- LBRACKET, RBRACKET = '[', ']'
9
- QUOTE = '"'
10
- ESCAPE = '\\'
11
- EQUAL = '='
12
- COLIN = ':'
13
- TO_SPACE = ['>']
14
- SPACE = ' '
15
- COMMA = ','
16
- LETTER_REGEX = /^[a-z]$/i
7
+ LBRACE, RBRACE = '{', '}' # :nodoc:
8
+ LBRACKET, RBRACKET = '[', ']' # :nodoc:
9
+ QUOTE = '"' # :nodoc:
10
+ ESCAPE = '\\' # :nodoc:
11
+ EQUAL = '=' # :nodoc:
12
+ COLIN = ':' # :nodoc:
13
+ TO_SPACE = ['>'] # :nodoc:
14
+ SPACE = ' ' # :nodoc:
15
+ COMMA = ',' # :nodoc:
16
+ LETTER_REGEX = /^[a-z]$/i # :nodoc:
17
17
 
18
18
  # Converts a string representation of a Hash into YAML, then into a Hash.
19
19
  # This is targeted towards the Parameters value in Rails logs. It is assumed that every key is a represented as a String in the logs.
@@ -92,6 +92,54 @@ module Beaver
92
92
  YAML.load s
93
93
  end
94
94
 
95
+ # Returns an array of arrays of strings with all the columns padded the same length.
96
+ def self.tablize(rows)
97
+ max_sizes = rows.inject([0]*rows.first.size) do |sizes, vals|
98
+ vals.map! &:to_s
99
+ vals.each_with_index { |val, i| sizes[i] = val.size if val.size > sizes[i] }; sizes
100
+ end
101
+ rows.map { |vals| vals.each_with_index.map { |val, i| val.ljust(max_sizes[i]) } }
102
+ end
103
+
104
+ # Matches tags recursively
105
+ def self.deep_matching_tags(matchers, tags)
106
+ all_tags_matched = nil
107
+ any_arrays_matched = false
108
+ for m in matchers
109
+ if m.is_a? Array
110
+ matched = deep_matching_tags m, tags
111
+ any_arrays_matched = true if matched
112
+ else
113
+ matched = tags.include? m
114
+ all_tags_matched = (matched && all_tags_matched != false) ? true : false
115
+ end
116
+ end
117
+ return (all_tags_matched or any_arrays_matched)
118
+ end
119
+
120
+ # Recursively compares to Hashes. If all of Hash A is in Hash B, they match.
121
+ def self.matching_hashes?(a,b)
122
+ intersecting_keys = a.keys & b.keys
123
+ if intersecting_keys.any?
124
+ a_values = a.values_at(*intersecting_keys)
125
+ b_values = b.values_at(*intersecting_keys)
126
+ indicies = (0..b_values.size-1)
127
+ indicies.all? do |i|
128
+ if a_values[i].is_a? String
129
+ a_values[i] == b_values[i]
130
+ elsif a_values[i].is_a?(Regexp) and b_values[i].is_a?(String)
131
+ a_values[i] =~ b_values[i]
132
+ elsif a_values[i].is_a?(Hash) and b_values[i].is_a?(Hash)
133
+ matching_hashes? a_values[i], b_values[i]
134
+ else
135
+ false
136
+ end
137
+ end
138
+ else
139
+ false
140
+ end
141
+ end
142
+
95
143
  # Parse a string (from a command-line arg) into a Date object
96
144
  def self.parse_date(date)
97
145
  case date
@@ -100,17 +148,5 @@ module Beaver
100
148
  else nil
101
149
  end
102
150
  end
103
-
104
- # Normalizes Time.new across Ruby 1.8 and 1.9.
105
- # Accepts the same arguments as Time.
106
- class NormalizedTime < ::Time
107
- if RUBY_VERSION < '1.9'
108
- # Returns a new NormalizedTime object.
109
- def self.new(*args)
110
- args.pop if args.last.is_a? String
111
- local(*args)
112
- end
113
- end
114
- end
115
151
  end
116
152
  end
@@ -0,0 +1,4 @@
1
+ module Beaver
2
+ MAJOR_VERSION, MINOR_VERSION, TINY_VERSION, PRE_VERSION = 1, 3, 0, nil # :nodoc:
3
+ VERSION = [MAJOR_VERSION, MINOR_VERSION, TINY_VERSION, PRE_VERSION].compact.join '.' # :nodoc:
4
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 1.2.0
9
+ version: 1.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jordan Hollinger
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-12-08 00:00:00 -05:00
17
+ date: 2012-06-24 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -32,7 +32,9 @@ files:
32
32
  - lib/beaver/beaver.rb
33
33
  - lib/beaver/request.rb
34
34
  - lib/beaver/parsers/rails.rb
35
+ - lib/beaver/parsers/http.rb
35
36
  - lib/beaver/utils.rb
37
+ - lib/beaver/version.rb
36
38
  - README.rdoc
37
39
  - LICENSE
38
40
  - bin/beaver