vidibus-core_extensions 0.3.12 → 0.3.14

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,5 +1,7 @@
1
- source "http://gemcutter.org"
1
+ source :rubygems
2
2
 
3
- gem "rspec", "~> 2.0.0.beta.20"
4
- gem "rr"
5
- gem "relevance-rcov"
3
+ group :development do
4
+ gem "rspec", "~> 2.0.0.beta.20"
5
+ gem "rr"
6
+ gem "relevance-rcov"
7
+ end
data/Gemfile.lock CHANGED
@@ -1,17 +1,19 @@
1
1
  GEM
2
- remote: http://gemcutter.org/
2
+ remote: http://rubygems.org/
3
3
  specs:
4
4
  diff-lcs (1.1.2)
5
5
  relevance-rcov (0.9.2.1)
6
- rr (1.0.0)
7
- rspec (2.0.0.beta.20)
8
- rspec-core (= 2.0.0.beta.20)
9
- rspec-expectations (= 2.0.0.beta.20)
10
- rspec-mocks (= 2.0.0.beta.20)
11
- rspec-core (2.0.0.beta.20)
12
- rspec-expectations (2.0.0.beta.20)
6
+ rr (1.0.2)
7
+ rspec (2.0.1)
8
+ rspec-core (~> 2.0.1)
9
+ rspec-expectations (~> 2.0.1)
10
+ rspec-mocks (~> 2.0.1)
11
+ rspec-core (2.0.1)
12
+ rspec-expectations (2.0.1)
13
13
  diff-lcs (>= 1.1.2)
14
- rspec-mocks (2.0.0.beta.20)
14
+ rspec-mocks (2.0.1)
15
+ rspec-core (~> 2.0.1)
16
+ rspec-expectations (~> 2.0.1)
15
17
 
16
18
  PLATFORMS
17
19
  ruby
data/README.rdoc CHANGED
@@ -50,7 +50,7 @@ Examples:
50
50
  Returns URL-encoded string of uri params. Examples:
51
51
 
52
52
  {:some => :value, :another => "speciál"}.to_uri # => "some=value&another=speci%C3%A1l"
53
- {:some => {:nested => :thing}}.to_uri # => "some=[nested=thing]"
53
+ {:some => {:nested => :thing}}.to_uri # => "some[nested]=thing"
54
54
 
55
55
 
56
56
  === Hash#only
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.12
1
+ 0.3.14
@@ -23,21 +23,16 @@ class Hash
23
23
  # Examples:
24
24
  #
25
25
  # {:some => :value, :another => "speciál"}.to_uri # => "some=value&another=speci%C3%A1l"
26
- # {:some => {:nested => :thing}}.to_uri # => "some=[nested=thing]"
26
+ # {:some => {:nested => :thing}}.to_uri # => "some[nested]=thing"
27
27
  #
28
- def to_uri
29
- hash = dup
30
- list = hash.to_a.map do |arg|
31
- value = arg[1]
32
- if value.is_a?(Hash)
33
- value = "[#{value.to_uri}]"
34
- else
35
- value = URI.escape(value.to_s)
36
- end
37
- "#{URI.escape(arg[0].to_s)}=#{value}"
38
- end
39
- list.join("&")
28
+ # Stolen from active_record/core_ext. Thanks
29
+ #
30
+ def to_query(namespace = nil)
31
+ out = collect do |key, value|
32
+ value.to_query(namespace ? "#{namespace}[#{key}]" : key)
33
+ end.sort * "&"
40
34
  end
35
+ alias_method :to_uri, :to_query
41
36
 
42
37
  # Returns a copy of self including only the given keys.
43
38
  #
@@ -13,4 +13,11 @@ class Object
13
13
  raise e
14
14
  end
15
15
  end
16
+
17
+ # Turns object into a key-value pair.
18
+ # Stolen from active_support/core_ext
19
+ def to_query(key)
20
+ require "cgi" unless defined?(CGI) && defined?(CGI::escape)
21
+ "#{CGI.escape(key.to_s)}=#{CGI.escape(to_s)}"
22
+ end
16
23
  end
@@ -123,4 +123,16 @@ class String
123
123
  def strip_tags!
124
124
  self.replace strip_tags
125
125
  end
126
+
127
+ # Appends hash of query params to current string.
128
+ #
129
+ # Example:
130
+ #
131
+ # "http://vidibus.org".with_params(:awesome => "yes")
132
+ # # => "http://vidibus.org?awesome=yes"
133
+ #
134
+ def with_params(params = {})
135
+ return self unless params and params.any?
136
+ self + (self.match(/\?/) ? "&" : "?") + params.to_query
137
+ end
126
138
  end
@@ -1,21 +1,26 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "Hash" do
4
- describe "#to_uri" do
4
+ describe "#to_query" do
5
5
  it "should join params with '&'" do
6
6
  hash = {:some => "value", :another => "thing"}
7
- parts = hash.to_uri.split("&")
7
+ parts = hash.to_query.split("&")
8
8
  parts.sort.should eql(['another=thing', 'some=value'])
9
9
  end
10
10
 
11
11
  it "should return items as urlencoded string" do
12
12
  hash = {:another => "speciál"}
13
- hash.to_uri.should eql("another=speci%C3%A1l")
13
+ hash.to_query.should eql("another=speci%C3%A1l")
14
14
  end
15
15
 
16
16
  it "should support multi-level hashes" do
17
17
  hash = {:some => {:nested => :thing}}
18
- hash.to_uri.should eql("some=[nested=thing]")
18
+ hash.to_query.should eql("some%5Bnested%5D=thing")
19
+ end
20
+
21
+ it "should support a namespace" do
22
+ hash = {:nested => :thing}
23
+ hash.to_query(:some).should eql("some%5Bnested%5D=thing")
19
24
  end
20
25
  end
21
26
 
@@ -63,7 +68,7 @@ describe "Hash" do
63
68
  hash = {:some => {:nested => {:is => ["really", "groovy"]}}}
64
69
  hash.to_a_rec.should eql([[:some, [[:nested, [[:is, ["really", "groovy"]]]]]]])
65
70
  end
66
-
71
+
67
72
  it "should return an array from hashes within arrays" do
68
73
  hash = {:some => [:nested, {:is => ["really", "groovy"]}]}
69
74
  hash.to_a_rec.should eql([[:some, [:nested, [[:is, ["really", "groovy"]]]]]])
@@ -76,7 +76,7 @@ describe "String" do
76
76
  end
77
77
  end
78
78
 
79
- describe "snip" do
79
+ describe "#snip" do
80
80
  it "should truncate string to given length while preserving words" do
81
81
  "O Brother, Where Art Thou?".snip(13).should eql("O Brother, Where…")
82
82
  end
@@ -96,7 +96,7 @@ describe "String" do
96
96
  it "should strip trailing white space" do
97
97
  "O Brother, Where Art Thou? ".snip(26).should eql("O Brother, Where Art Thou?")
98
98
  end
99
-
99
+
100
100
  it "should strip leading white space" do
101
101
  " O Brother, Where Art Thou?".snip(26).should eql("O Brother, Where Art Thou?")
102
102
  end
@@ -106,7 +106,7 @@ describe "String" do
106
106
  end
107
107
  end
108
108
 
109
- describe "strip_tags" do
109
+ describe "#strip_tags" do
110
110
  it "should remove all tags from string" do
111
111
  "<p>Think<br />different</p>".strip_tags.should eql("Thinkdifferent")
112
112
  end
@@ -116,11 +116,29 @@ describe "String" do
116
116
  end
117
117
  end
118
118
 
119
- describe "strip_tags!" do
119
+ describe "#strip_tags!" do
120
120
  it "should strip tags on self" do
121
121
  string = "<p>Think<br />different</p>"
122
122
  string.strip_tags!
123
123
  string.should eql("Thinkdifferent")
124
124
  end
125
125
  end
126
+
127
+ describe "#with_params" do
128
+ it "should return the current string unless params are given" do
129
+ "http://vidibus.org".with_params.should eql("http://vidibus.org")
130
+ end
131
+
132
+ it "should return the current string if an empty hash is given" do
133
+ "http://vidibus.org".with_params({}).should eql("http://vidibus.org")
134
+ end
135
+
136
+ it "should return the current string with params as query" do
137
+ "http://vidibus.org".with_params(:awesome => "yes").should eql("http://vidibus.org?awesome=yes")
138
+ end
139
+
140
+ it "should append params to existing query" do
141
+ "http://vidibus.org?opensource=true".with_params(:awesome => "yes").should eql("http://vidibus.org?opensource=true&awesome=yes")
142
+ end
143
+ end
126
144
  end
@@ -1,59 +1,57 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{vidibus-core_extensions}
8
- s.version = "0.3.12"
8
+ s.version = "0.3.14"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andre Pankratz"]
12
- s.date = %q{2010-11-16}
12
+ s.date = %q{2011-01-14}
13
13
  s.description = %q{Provides some extensions to the ruby core.}
14
14
  s.email = %q{andre@vidibus.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".bundle/config",
21
- ".document",
22
- ".gitignore",
23
- ".rspec",
24
- "Gemfile",
25
- "Gemfile.lock",
26
- "LICENSE",
27
- "README.rdoc",
28
- "Rakefile",
29
- "VERSION",
30
- "lib/vidibus-core_extensions.rb",
31
- "lib/vidibus/core_extensions.rb",
32
- "lib/vidibus/core_extensions/array.rb",
33
- "lib/vidibus/core_extensions/file_utils.rb",
34
- "lib/vidibus/core_extensions/hash.rb",
35
- "lib/vidibus/core_extensions/object.rb",
36
- "lib/vidibus/core_extensions/string.rb",
37
- "spec/spec_helper.rb",
38
- "spec/vidibus/core_extensions/array_spec.rb",
39
- "spec/vidibus/core_extensions/file_utils_spec.rb",
40
- "spec/vidibus/core_extensions/hash_spec.rb",
41
- "spec/vidibus/core_extensions/object_spec.rb",
42
- "spec/vidibus/core_extensions/string_spec.rb",
43
- "vidibus-core_extensions.gemspec"
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/vidibus-core_extensions.rb",
30
+ "lib/vidibus/core_extensions.rb",
31
+ "lib/vidibus/core_extensions/array.rb",
32
+ "lib/vidibus/core_extensions/file_utils.rb",
33
+ "lib/vidibus/core_extensions/hash.rb",
34
+ "lib/vidibus/core_extensions/object.rb",
35
+ "lib/vidibus/core_extensions/string.rb",
36
+ "spec/spec_helper.rb",
37
+ "spec/vidibus/core_extensions/array_spec.rb",
38
+ "spec/vidibus/core_extensions/file_utils_spec.rb",
39
+ "spec/vidibus/core_extensions/hash_spec.rb",
40
+ "spec/vidibus/core_extensions/object_spec.rb",
41
+ "spec/vidibus/core_extensions/string_spec.rb",
42
+ "vidibus-core_extensions.gemspec"
44
43
  ]
45
44
  s.homepage = %q{http://github.com/vidibus/vidibus-core_extensions}
46
- s.rdoc_options = ["--charset=UTF-8"]
47
45
  s.require_paths = ["lib"]
48
46
  s.rubygems_version = %q{1.3.7}
49
47
  s.summary = %q{Extends the ruby core.}
50
48
  s.test_files = [
51
49
  "spec/spec_helper.rb",
52
- "spec/vidibus/core_extensions/array_spec.rb",
53
- "spec/vidibus/core_extensions/file_utils_spec.rb",
54
- "spec/vidibus/core_extensions/hash_spec.rb",
55
- "spec/vidibus/core_extensions/object_spec.rb",
56
- "spec/vidibus/core_extensions/string_spec.rb"
50
+ "spec/vidibus/core_extensions/array_spec.rb",
51
+ "spec/vidibus/core_extensions/file_utils_spec.rb",
52
+ "spec/vidibus/core_extensions/hash_spec.rb",
53
+ "spec/vidibus/core_extensions/object_spec.rb",
54
+ "spec/vidibus/core_extensions/string_spec.rb"
57
55
  ]
58
56
 
59
57
  if s.respond_to? :specification_version then
@@ -61,9 +59,18 @@ Gem::Specification.new do |s|
61
59
  s.specification_version = 3
62
60
 
63
61
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
62
+ s.add_development_dependency(%q<rspec>, ["~> 2.0.0.beta.20"])
63
+ s.add_development_dependency(%q<rr>, [">= 0"])
64
+ s.add_development_dependency(%q<relevance-rcov>, [">= 0"])
64
65
  else
66
+ s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.20"])
67
+ s.add_dependency(%q<rr>, [">= 0"])
68
+ s.add_dependency(%q<relevance-rcov>, [">= 0"])
65
69
  end
66
70
  else
71
+ s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.20"])
72
+ s.add_dependency(%q<rr>, [">= 0"])
73
+ s.add_dependency(%q<relevance-rcov>, [">= 0"])
67
74
  end
68
75
  end
69
76
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vidibus-core_extensions
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 12
10
- version: 0.3.12
9
+ - 14
10
+ version: 0.3.14
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andre Pankratz
@@ -15,10 +15,55 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-16 00:00:00 +01:00
18
+ date: 2011-01-14 00:00:00 +01:00
19
19
  default_executable:
20
- dependencies: []
21
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :development
23
+ prerelease: false
24
+ name: rspec
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 62196427
31
+ segments:
32
+ - 2
33
+ - 0
34
+ - 0
35
+ - beta
36
+ - 20
37
+ version: 2.0.0.beta.20
38
+ requirement: *id001
39
+ - !ruby/object:Gem::Dependency
40
+ type: :development
41
+ prerelease: false
42
+ name: rr
43
+ version_requirements: &id002 !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ hash: 3
49
+ segments:
50
+ - 0
51
+ version: "0"
52
+ requirement: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ type: :development
55
+ prerelease: false
56
+ name: relevance-rcov
57
+ version_requirements: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirement: *id003
22
67
  description: Provides some extensions to the ruby core.
23
68
  email: andre@vidibus.com
24
69
  executables: []
@@ -31,7 +76,6 @@ extra_rdoc_files:
31
76
  files:
32
77
  - .bundle/config
33
78
  - .document
34
- - .gitignore
35
79
  - .rspec
36
80
  - Gemfile
37
81
  - Gemfile.lock
@@ -58,8 +102,8 @@ homepage: http://github.com/vidibus/vidibus-core_extensions
58
102
  licenses: []
59
103
 
60
104
  post_install_message:
61
- rdoc_options:
62
- - --charset=UTF-8
105
+ rdoc_options: []
106
+
63
107
  require_paths:
64
108
  - lib
65
109
  required_ruby_version: !ruby/object:Gem::Requirement
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC