kelredd-useful 0.4.0 → 0.4.1

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.
@@ -5,7 +5,7 @@
5
5
  require 'useful/erb_helpers/common'
6
6
  require 'useful/erb_helpers/tags'
7
7
  require 'useful/ruby_extensions/string' unless ::String.new.respond_to?('ends_with?')
8
- unless ::Object.new.respond_to?('blank?') && ::Object.new.respond_to?('is_true?') && ::Object.new.respond_to?('returning')
8
+ unless ::Object.new.respond_to?('blank?') && ::Object.new.respond_to?('is_true?')
9
9
  require 'useful/ruby_extensions/object'
10
10
  end
11
11
 
@@ -13,14 +13,14 @@ module Useful; end
13
13
  module Useful::ErbHelpers; end
14
14
 
15
15
  module Useful::ErbHelpers::Proper
16
-
16
+
17
17
  include Useful::ErbHelpers::Common
18
-
18
+
19
19
  # This one's a little different than the corresponding actionpack version:
20
20
  # => ie. you don't pass an options string as the 2nd argument
21
21
  # => you, instead, pass a block that should return the desired options string
22
22
  # => ie, proper_select_tag('user') { '<option>test</option>' }
23
- def proper_select_tag(name, options={}, &block)
23
+ def proper_select_tag(name, options={}, &block)
24
24
  html_name = (options[:multiple].is_true? && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name
25
25
  options[:multiple] = OPTIONS[:multiple] if options[:multiple] == true
26
26
  options[:tag] = 'select'
@@ -37,13 +37,13 @@ module Useful::ErbHelpers::Proper
37
37
  unchecked_value = options.delete(:unchecked_value)
38
38
  unchecked_value = '0' if unchecked_value.nil?
39
39
  disable_unchecked_value = options.delete(:disable_unchecked_value)
40
- returning html = '' do
40
+ ''.tap do |html|
41
41
  html << input_tag(:hidden, name, unchecked_value, :id => "#{options[:id]}_hidden") unless disable_unchecked_value.is_true?
42
42
  html << input_tag(:checkbox, name, value, options)
43
43
  html << tag(:label, :for => options[:id]) { label_text } unless label_text.blank?
44
44
  end
45
45
  end
46
-
46
+
47
47
  # TODO: write tests
48
48
  def proper_radio_button_tag(*args)
49
49
  name, value, checked, options = proper_check_radio_options(nil, args)
@@ -52,7 +52,7 @@ module Useful::ErbHelpers::Proper
52
52
  label_text = options.delete(:label) || value.to_s.humanize
53
53
  label_container_tag = options.delete(:tag) || :span
54
54
  radio_button_str = input_tag(:radio, name, value, options)
55
- returning html = '' do
55
+ ''.tap do |html|
56
56
  html << if label_text.blank?
57
57
  radio_button_str
58
58
  else
@@ -66,9 +66,9 @@ module Useful::ErbHelpers::Proper
66
66
  def self.included(receiver)
67
67
  receiver.send :include, Useful::ErbHelpers::Tags
68
68
  end
69
-
69
+
70
70
  private
71
-
71
+
72
72
  def proper_check_radio_options(default_value, args)
73
73
  # args should be passed to proper checkbox and radiobutton tags like this:
74
74
  # => name, value, checked, options={}
@@ -101,7 +101,7 @@ module Useful::ErbHelpers::Proper
101
101
  raise ArgumentError, "please specify 1 to 4 arguments for name, value, checked, and options"
102
102
  end
103
103
  end
104
-
104
+
105
105
  def case_arg_options_for_length(length, args)
106
106
  args.length == length || (args.length == (length-1) && !(args[(length-2)].kind_of?(::Hash) || args[(length-2)].nil?))
107
107
  end
@@ -56,58 +56,14 @@ module Useful::RubyExtensions::Object
56
56
  self.nil? || self.false? || (self.respond_to?(:empty?) ? self.empty? : false)
57
57
  end unless ::Object.new.respond_to?('blank?')
58
58
 
59
- # Returns +value+ after yielding +value+ to the block. This simplifies the
60
- # process of constructing an object, performing work on the object, and then
61
- # returning the object from a method. It is a Ruby-ized realization of the K
62
- # combinator, courtesy of Mikael Brockman.
63
- #
64
- # ==== Examples
65
- #
66
- # # Without returning
67
- # def foo
68
- # values = []
69
- # values << "bar"
70
- # values << "baz"
71
- # return values
72
- # end
73
- #
74
- # foo # => ['bar', 'baz']
75
- #
76
- # # returning with a local variable
77
- # def foo
78
- # returning values = [] do
79
- # values << 'bar'
80
- # values << 'baz'
81
- # end
82
- # end
83
- #
84
- # foo # => ['bar', 'baz']
85
- #
86
- # # returning with a block argument
87
- # def foo
88
- # returning [] do |values|
89
- # values << 'bar'
90
- # values << 'baz'
91
- # end
92
- # end
93
- #
94
- # foo # => ['bar', 'baz']
95
59
  def returning(value)
96
- yield(value)
60
+ warn "[DEPRECATION] `returning` is deprecated. Please use `tap` instead."
61
+ yield(value)
97
62
  value
98
63
  end unless ::Object.new.respond_to?('returning')
99
64
 
100
- # Yields <code>x</code> to the block, and then returns <code>x</code>.
101
- # The primary purpose of this method is to "tap into" a method chain,
102
- # in order to perform operations on intermediate results within the chain.
103
- #
104
- # (1..10).tap { |x| puts "original: #{x.inspect}" }.to_a.
105
- # tap { |x| puts "array: #{x.inspect}" }.
106
- # select { |x| x%2 == 0 }.
107
- # tap { |x| puts "evens: #{x.inspect}" }.
108
- # map { |x| x*x }.
109
- # tap { |x| puts "squares: #{x.inspect}" }
110
65
  def tap
66
+ warn "[DEPRECATION] `tap` will be deprecated because it is part of the object kernel in 1.8.7 up."
111
67
  yield self
112
68
  self
113
69
  end unless ::Object.new.respond_to?('tap')
@@ -26,7 +26,7 @@ module Useful::RubyHelpers::Logger
26
26
  if name.empty? && msg.empty?
27
27
  nil
28
28
  else
29
- returning formatted_log_msg(name, msg, opts) do |log_msg|
29
+ formatted_log_msg(name, msg, opts).tap do |log_msg|
30
30
  logger.send(opts[:level].to_s, log_msg)
31
31
  end
32
32
  end
@@ -50,18 +50,11 @@ module Useful::RubyHelpers::Logger
50
50
  end
51
51
 
52
52
  def formatted_log_msg(name, msg, opts)
53
+ name = name.strip
54
+ msg = msg.strip
53
55
  opts[:newlines] ||= 0
54
56
  opts[:color] = true if opts[:color].nil?
55
- opts[:prefix] ||= case opts[:level].to_s
56
- when 'info'
57
- "*" # green
58
- when 'warn'
59
- "~" # cyan
60
- when 'error'
61
- "!" # red
62
- else # debug
63
- "-"
64
- end
57
+
65
58
  color_level = opts[:color] ? opts[:level].to_s : 'none'
66
59
  color = case color_level
67
60
  when 'debug'
@@ -78,7 +71,8 @@ module Useful::RubyHelpers::Logger
78
71
  end
79
72
  color_reg = "0;#{color}"
80
73
  color_underlined = "4;#{color}"
81
- "\e[0m#{"\n"*opts[:newlines].to_i.abs} \e[#{color_reg}m#{opts[:prefix]}\e[0m#{opts[:prefix].empty? ? '' : ' '}\e[#{color_underlined}m#{name}\e[0m#{name.empty? ? '' : ' '}#{msg}"
74
+
75
+ "\e[0m#{"\n"*opts[:newlines].to_i.abs} \e[#{color_underlined}m#{name}\e[0m#{name.empty? ? '' : "\t"}#{msg}"
82
76
  end
83
77
 
84
78
  def handle_log_args(args)
@@ -3,7 +3,7 @@ module Useful
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 4
6
- TINY = 0
6
+ TINY = 1
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kelredd-useful
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-30 00:00:00 -05:00
18
+ date: 2010-09-11 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency