kelredd-useful 0.1.20 → 0.1.25

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -10,7 +10,7 @@ the pieces you are interested in.
10
10
 
11
11
  == Installation
12
12
 
13
- sudo gem install kelredd-useful --source http://gems.github.com
13
+ sudo gem install kelredd-useful --source http://gemcutter.org
14
14
 
15
15
  == Dependencies
16
16
 
data/Rakefile CHANGED
@@ -7,19 +7,20 @@ require 'lib/useful/version'
7
7
  task :default => :test
8
8
 
9
9
  spec = Gem::Specification.new do |s|
10
- s.name = 'useful'
10
+ s.name = 'kelredd-useful'
11
11
  s.version = Useful::Version.to_s
12
12
  s.has_rdoc = true
13
13
  s.extra_rdoc_files = %w(README.rdoc)
14
14
  s.rdoc_options = %w(--main README.rdoc)
15
15
  s.summary = "A collection of useful helpers for various ruby things."
16
- s.author = 'Kelredd'
17
- s.email = ''
18
- s.homepage = ''
19
- s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
16
+ s.author = 'Kelly Redding'
17
+ s.email = 'kelly@kelredd.com'
18
+ s.homepage = 'http://code.kelredd.com'
19
+ s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib}/**/*")
20
20
  # s.executables = ['useful']
21
21
 
22
22
  s.add_dependency('json')
23
+ s.add_dependency('tmail')
23
24
  end
24
25
 
25
26
  Rake::GemPackageTask.new(spec) do |pkg|
@@ -33,8 +34,15 @@ Rake::TestTask.new do |t|
33
34
  end
34
35
 
35
36
  desc 'Generate the gemspec to serve this Gem from Github'
36
- task :github do
37
+ task :gemspec do
37
38
  file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
38
39
  File.open(file, 'w') {|f| f << spec.to_ruby }
39
40
  puts "Created gemspec: #{file}"
40
- end
41
+ end
42
+
43
+ require 'cucumber'
44
+ require 'cucumber/rake/task'
45
+
46
+ Cucumber::Rake::Task.new(:features) do |t|
47
+ t.cucumber_opts = "test/features --format pretty"
48
+ end
@@ -45,13 +45,16 @@ module Useful
45
45
  self.class.except(self, keys)
46
46
  end
47
47
 
48
- # Determines if a value exists for the provided key(s). Allows searching in nested hashes
49
- def check_value?(*keys)
48
+ # Returns the value for the provided key(s). Allows searching in nested hashes
49
+ def get_value(*keys)
50
50
  val = self[keys.first] || self[keys.first.to_s]
51
51
  val = self[keys.first.to_s.intern] unless val || keys.first.to_s.empty? || keys.first.kind_of?(Symbol)
52
- return val.check_value?(*keys[1..-1]) if val.kind_of?(Hash) && keys.length > 1
53
- return true if val && !val.empty?
54
- false
52
+ val.kind_of?(Hash) && keys.length > 1 ? val.get_value?(keys[1..-1]) : val
53
+ end
54
+ # Determines if a value exists for the provided key(s). Allows searching in nested hashes
55
+ def check_value?(*keys)
56
+ val = self.get_value(keys)
57
+ val && !val.empty? ? true : false
55
58
  end
56
59
 
57
60
  # takes any empty values and makes them nil inline
@@ -65,13 +68,36 @@ module Useful
65
68
  # # => "?id=thomas_hardy"
66
69
  # {:id => 23423, :since => Time.now}.to_http_query_str
67
70
  # # => "?since=Thu,%2021%20Jun%202007%2012:10:05%20-0500&id=23423"
68
- def to_http_query_str(opts = {})
69
- require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
70
- opts[:prepend] ||= '?'
71
- opts[:append] ||= ''
72
- self.empty? ? '' : "#{opts[:prepend]}#{self.collect{|key, val| "#{key.to_s}=#{CGI.escape(val.to_s)}"}.join('&')}#{opts[:append]}"
71
+ # {:id => [1,2]}.to_http_query_str
72
+ # # => "?id[]=1&id[]=2"
73
+ # {:poo => {:foo => 1, :bar => 2}}.to_http_query_str
74
+ # # => "?poo[bar]=2&poo[foo]=1"
75
+ # {:poo => {:foo => 1, :bar => {:bar1 => 1, :bar2 => "nasty"}}}.to_http_query_str
76
+ # "?poo[bar][bar1]=1&poo[bar][bar2]=nasty&poo[foo]=1"
77
+ unless {}.respond_to?(:to_http_query_str)
78
+ def to_http_query_str(opts = {})
79
+ require 'cgi' unless defined?(::CGI) && defined?(::CGI::escape)
80
+ opts[:prepend] ||= '?'
81
+ opts[:append] ||= ''
82
+ opts[:key_ns] ||= nil
83
+ opt_strings = self.collect do |key, val|
84
+ key_s = opts[:key_ns] ? "#{opts[:key_ns]}[#{key.to_s}]" : key.to_s
85
+ if val.kind_of?(::Array)
86
+ val.collect{|i| "#{key_s}[]=#{::CGI.escape(i.to_s)}"}.join('&')
87
+ elsif val.kind_of?(::Hash)
88
+ val.to_http_query_str({
89
+ :prepend => '',
90
+ :key_ns => key_s,
91
+ :append => ''
92
+ })
93
+ else
94
+ "#{key_s}=#{::CGI.escape(val.to_s)}"
95
+ end
96
+ end
97
+ self.empty? ? '' : "#{opts[:prepend]}#{opt_strings.join('&')}#{opts[:append]}"
98
+ end
73
99
  end
74
-
100
+
75
101
  def to_html_attrs
76
102
  self.empty? ? '' : self.collect{|key, val| "#{key}=\"#{val}\""}.join(' ')
77
103
  end
@@ -37,7 +37,11 @@ module Useful
37
37
  "no match"
38
38
  end
39
39
  end
40
-
40
+
41
+ def to_boolean
42
+ self =~ /^(true|1)$/i ? true : false
43
+ end
44
+
41
45
  end
42
46
  end
43
47
  end
@@ -156,6 +156,14 @@ module Useful
156
156
  prefix = prefix.to_s
157
157
  self[0, prefix.length] == prefix
158
158
  end
159
+
160
+ def to_datetime
161
+ ::DateTime.civil(*::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec).map { |arg| arg || 0 }) rescue nil
162
+ end
163
+
164
+ def to_date
165
+ ::Date.civil(*::Date._parse(self, false).values_at(:year, :mon, :mday).map { |arg| arg || 0 }) rescue nil
166
+ end
159
167
 
160
168
  end
161
169
  end
@@ -19,8 +19,8 @@ module Sinatra
19
19
  link_to(content, href, options)
20
20
  end
21
21
 
22
- def mail_link_to(email)
23
- link_to email, "mailto: #{email}"
22
+ def mail_link_to(email, options={})
23
+ link_to options[:label] || email, "mailto: #{email}"
24
24
  end
25
25
 
26
26
  def link_to_function(content, function, opts={})
@@ -2,6 +2,8 @@
2
2
  # => I chose to copy the source in here instead of add yet another gem depencency
3
3
  # => I take no credit for this work, check out link for more info.
4
4
 
5
+ require 'net/smtp'
6
+
5
7
  Net::SMTP.class_eval do
6
8
  private
7
9
  def do_start(helodomain, user, secret, authtype)
@@ -3,7 +3,7 @@ module Useful
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- TINY = 20
6
+ TINY = 25
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kelredd-useful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.20
4
+ version: 0.1.25
5
5
  platform: ruby
6
6
  authors:
7
- - Kelredd
7
+ - Kelly Redding
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-17 00:00:00 -07:00
12
+ date: 2009-10-06 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,8 +22,18 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: tmail
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
25
35
  description:
26
- email: ""
36
+ email: kelly@kelredd.com
27
37
  executables: []
28
38
 
29
39
  extensions: []
@@ -33,19 +43,14 @@ extra_rdoc_files:
33
43
  files:
34
44
  - README.rdoc
35
45
  - Rakefile
36
- - lib/useful
37
- - lib/useful/active_record_helpers
38
46
  - lib/useful/active_record_helpers/mysql_migration_helpers.rb
39
47
  - lib/useful/active_record_helpers.rb
40
- - lib/useful/cap_tasks
41
48
  - lib/useful/cap_tasks/cache.rb
42
49
  - lib/useful/cap_tasks/gemsconfig.rb
43
50
  - lib/useful/cap_tasks/globals.rb
44
51
  - lib/useful/cap_tasks.rb
45
- - lib/useful/rails_extensions
46
52
  - lib/useful/rails_extensions/environment_tests.rb
47
53
  - lib/useful/rails_extensions.rb
48
- - lib/useful/ruby_extensions
49
54
  - lib/useful/ruby_extensions/array.rb
50
55
  - lib/useful/ruby_extensions/date.rb
51
56
  - lib/useful/ruby_extensions/false_class.rb
@@ -56,7 +61,6 @@ files:
56
61
  - lib/useful/ruby_extensions/string.rb
57
62
  - lib/useful/ruby_extensions/true_class.rb
58
63
  - lib/useful/ruby_extensions.rb
59
- - lib/useful/ruby_extensions_from_rails
60
64
  - lib/useful/ruby_extensions_from_rails/date.rb
61
65
  - lib/useful/ruby_extensions_from_rails/duration.rb
62
66
  - lib/useful/ruby_extensions_from_rails/fixnum.rb
@@ -66,9 +70,7 @@ files:
66
70
  - lib/useful/ruby_extensions_from_rails/string.rb
67
71
  - lib/useful/ruby_extensions_from_rails/time.rb
68
72
  - lib/useful/ruby_extensions_from_rails.rb
69
- - lib/useful/sinatra_helpers
70
73
  - lib/useful/sinatra_helpers/environment_tests.rb
71
- - lib/useful/sinatra_helpers/erb
72
74
  - lib/useful/sinatra_helpers/erb/error_pages.rb
73
75
  - lib/useful/sinatra_helpers/erb/forms.rb
74
76
  - lib/useful/sinatra_helpers/erb/helpers.rb
@@ -76,7 +78,6 @@ files:
76
78
  - lib/useful/sinatra_helpers/erb/partials.rb
77
79
  - lib/useful/sinatra_helpers/erb/tags.rb
78
80
  - lib/useful/sinatra_helpers/erb.rb
79
- - lib/useful/sinatra_helpers/mailer
80
81
  - lib/useful/sinatra_helpers/mailer/base.rb
81
82
  - lib/useful/sinatra_helpers/mailer/exceptions.rb
82
83
  - lib/useful/sinatra_helpers/mailer/tls.rb
@@ -84,11 +85,10 @@ files:
84
85
  - lib/useful/sinatra_helpers.rb
85
86
  - lib/useful/version.rb
86
87
  - lib/useful.rb
87
- - test/test_helper.rb
88
- - test/unit
89
- - test/unit/useful_test.rb
90
88
  has_rdoc: true
91
- homepage: ""
89
+ homepage: http://code.kelredd.com
90
+ licenses: []
91
+
92
92
  post_install_message:
93
93
  rdoc_options:
94
94
  - --main
@@ -110,9 +110,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  requirements: []
111
111
 
112
112
  rubyforge_project:
113
- rubygems_version: 1.2.0
113
+ rubygems_version: 1.3.5
114
114
  signing_key:
115
- specification_version: 2
115
+ specification_version: 3
116
116
  summary: A collection of useful helpers for various ruby things.
117
117
  test_files: []
118
118
 
data/test/test_helper.rb DELETED
@@ -1,10 +0,0 @@
1
- # http://sneaq.net/textmate-wtf
2
- $:.reject! { |e| e.include? 'TextMate' }
3
-
4
- require 'rubygems'
5
- require 'test/unit'
6
- require 'matchy'
7
- require 'context'
8
- require 'mocha'
9
-
10
- require File.dirname(__FILE__) + '/../lib/useful'
@@ -1,13 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
2
-
3
- class UsefulTest < Test::Unit::TestCase
4
-
5
- describe "An instance of the Useful class" do
6
-
7
- it "should flunk" do
8
- flunk "Please provide some tests"
9
- end
10
-
11
- end
12
-
13
- end