has_gravatar 0.0.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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +54 -0
- data/LICENSE +20 -0
- data/README.md +45 -0
- data/Rakefile +7 -0
- data/has_gravatar.gemspec +30 -0
- data/lib/has_gravatar.rb +5 -0
- data/lib/has_gravatar/extensions.rb +31 -0
- data/lib/has_gravatar/version.rb +3 -0
- data/spec/db/.gitkeep +0 -0
- data/spec/lib/model_caching_spec.rb +28 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/data.rb +1 -0
- data/spec/support/models.rb +3 -0
- data/spec/support/schema.rb +9 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 666144ab54a43142f8153d309b33d9da7deed3d7
|
4
|
+
data.tar.gz: ae9978110b6b3902657e6b3145aecd3c8e04885c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 921c58028560835667bc5642711cf3cf922f00a13f1ace2ec74c4d78e6646378803f0416ea35058ebc9523e5273e17779b561333c4aba18d345726553dfaf19e
|
7
|
+
data.tar.gz: 3042cada6b5f23a0d07a1d9581b39a7a9d6772a61cbd2e6e17fa4368d66a22629711d9fa58f625c2e2c6a67e5d45574a9dcbdfc1e2187cb23a984b548e89a065
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
has_gravatar (0.0.1)
|
5
|
+
activerecord (~> 4.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (4.0.2)
|
11
|
+
activesupport (= 4.0.2)
|
12
|
+
builder (~> 3.1.0)
|
13
|
+
activerecord (4.0.2)
|
14
|
+
activemodel (= 4.0.2)
|
15
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
16
|
+
activesupport (= 4.0.2)
|
17
|
+
arel (~> 4.0.0)
|
18
|
+
activerecord-deprecated_finders (1.0.3)
|
19
|
+
activesupport (4.0.2)
|
20
|
+
i18n (~> 0.6, >= 0.6.4)
|
21
|
+
minitest (~> 4.2)
|
22
|
+
multi_json (~> 1.3)
|
23
|
+
thread_safe (~> 0.1)
|
24
|
+
tzinfo (~> 0.3.37)
|
25
|
+
arel (4.0.1)
|
26
|
+
atomic (1.1.14)
|
27
|
+
builder (3.1.4)
|
28
|
+
diff-lcs (1.2.5)
|
29
|
+
i18n (0.6.9)
|
30
|
+
minitest (4.7.5)
|
31
|
+
multi_json (1.8.4)
|
32
|
+
rake (10.1.1)
|
33
|
+
rspec (2.14.1)
|
34
|
+
rspec-core (~> 2.14.0)
|
35
|
+
rspec-expectations (~> 2.14.0)
|
36
|
+
rspec-mocks (~> 2.14.0)
|
37
|
+
rspec-core (2.14.7)
|
38
|
+
rspec-expectations (2.14.4)
|
39
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
40
|
+
rspec-mocks (2.14.4)
|
41
|
+
sqlite3 (1.3.8)
|
42
|
+
thread_safe (0.1.3)
|
43
|
+
atomic
|
44
|
+
tzinfo (0.3.38)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
ruby
|
48
|
+
|
49
|
+
DEPENDENCIES
|
50
|
+
bundler (~> 1.5)
|
51
|
+
has_gravatar!
|
52
|
+
rake (~> 10.1)
|
53
|
+
rspec (~> 2.14)
|
54
|
+
sqlite3 (~> 1.3)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Victor Gama
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
has_gravatar
|
2
|
+
============
|
3
|
+
|
4
|
+
[](https://travis-ci.org/victorgama/has_gravatar) [](https://gemnasium.com/victorgama/has_gravatar)
|
5
|
+
|
6
|
+
has_gravatar is intended to add easy access to gravatar URLs from Active Record models.
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
|
11
|
+
has_gravatar is distributed as a gem, which is how it should be used in your app.
|
12
|
+
|
13
|
+
First, include the gem in your Gemfile:
|
14
|
+
`gem "has_gravatar"`
|
15
|
+
And install it:
|
16
|
+
`bundle`
|
17
|
+
|
18
|
+
After these two simple steps, has_gravatar is ready to be used on any Active Record model.
|
19
|
+
In order to use it, call `has_gravatar`, passing one or more fields as argument. Example:
|
20
|
+
```ruby
|
21
|
+
class User < ActiveRecord::Base
|
22
|
+
has_gravatar :primary_email, :secondary_email, :email
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
Now, to get the Gravatar URL of a model, use:
|
27
|
+
```ruby
|
28
|
+
user = User.first
|
29
|
+
|
30
|
+
# Returns http://gravatar.com/avatar/<hash>
|
31
|
+
user.email_gravatar
|
32
|
+
|
33
|
+
# Supports default images
|
34
|
+
user.email_gravatar default_avatar: 'http://my.domain.com/public/default_gravatar.png'
|
35
|
+
|
36
|
+
# And sizing
|
37
|
+
user.email_gravatar default_avatar: 'http://my.domain.com/public/default_gravatar.png', size: 128
|
38
|
+
|
39
|
+
# And HTTPS
|
40
|
+
user.email_gravatar default_avatar: 'http://my.domain.com/public/default_gravatar.png', size: 128, secure: true
|
41
|
+
|
42
|
+
```
|
43
|
+
|
44
|
+
------------------
|
45
|
+
Pull requests are welcome!
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'has_gravatar/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
|
9
|
+
spec.name = 'has_gravatar'
|
10
|
+
spec.version = HasGravatar::VERSION
|
11
|
+
spec.authors = ['Victor Gama']
|
12
|
+
spec.email = ['hey@vito.io']
|
13
|
+
spec.description = %q{Dead simple Gravatar URL generator}
|
14
|
+
spec.summary = %q{Dead simple Gravatar URL generator}
|
15
|
+
spec.homepage = 'http://github.com/victorgama/has_gravatar'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.1'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 2.14'
|
26
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3'
|
27
|
+
|
28
|
+
spec.add_dependency 'activerecord', '~> 4.0'
|
29
|
+
|
30
|
+
end
|
data/lib/has_gravatar.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
|
3
|
+
module HasGravatar
|
4
|
+
module Extensions
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
module ClassMethods
|
7
|
+
def has_gravatar *fields
|
8
|
+
fields.each do |field|
|
9
|
+
method_name = "#{field}_gravatar".to_sym
|
10
|
+
self.send :define_method, method_name do |*args|
|
11
|
+
protocol = '://'
|
12
|
+
default_url = nil
|
13
|
+
size = nil
|
14
|
+
if args.is_a?(Array) && args.size == 1 && args[0].is_a?(Hash) then
|
15
|
+
args = args[0]
|
16
|
+
protocol = 's://secure.' if args.has_key?(:secure) && args[:secure] == true
|
17
|
+
# From: ERB library (http://rdoc.info/stdlib/erb/1.8.7/ERB/Util%3aurl_encode)
|
18
|
+
default_url = 'd=' << args[:default_avatar].to_s.gsub(/[^a-zA-Z0-9_\-.]/n){ sprintf("%%%02X", $&.unpack("C")[0]) } if args.has_key? :default_avatar
|
19
|
+
size = 's=' << args[:size].to_s if args.has_key? :size
|
20
|
+
end
|
21
|
+
hash = Digest::MD5.hexdigest(self.send field.to_sym)
|
22
|
+
suffix = [default_url, size].reject! {|item| item == nil || item.empty? }.join('&')
|
23
|
+
suffix = '?' << suffix unless suffix.empty?
|
24
|
+
|
25
|
+
"http#{protocol}gravatar.com/avatar/#{hash}#{suffix}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/db/.gitkeep
ADDED
File without changes
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Model' do
|
4
|
+
it 'should contain VERSION' do
|
5
|
+
HasGravatar::VERSION.should_not be_nil
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should respond to email_gravatar method' do
|
9
|
+
User.first.should respond_to :email_gravatar
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should return a valid gravatar url for the given email address' do
|
13
|
+
# Hash calculated by md5.cz
|
14
|
+
User.first.email_gravatar.should eq 'http://gravatar.com/avatar/23463b99b62a72f26ed677cc556c44e8'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should support https gravatars' do
|
18
|
+
User.first.email_gravatar(secure: true).should start_with 'https://secure.gravatar'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should support default images' do
|
22
|
+
User.first.email_gravatar(default_avatar: 'http://example.com/public/default_gravatar.png').should include 'example.com'
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should support gravatar size' do
|
26
|
+
User.first.email_gravatar(size: 128).should include '?s=128'
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'has_gravatar'
|
2
|
+
|
3
|
+
ActiveRecord::Base.establish_connection(adapter: "sqlite3",
|
4
|
+
database: File.dirname(__FILE__) + "/db/has_gravatar.sqlite3")
|
5
|
+
|
6
|
+
load File.dirname(__FILE__) + '/support/schema.rb'
|
7
|
+
load File.dirname(__FILE__) + '/support/models.rb'
|
8
|
+
load File.dirname(__FILE__) + '/support/data.rb'
|
@@ -0,0 +1 @@
|
|
1
|
+
User.create!(email: 'example@example.com')
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: has_gravatar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Victor Gama
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activerecord
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.0'
|
83
|
+
description: Dead simple Gravatar URL generator
|
84
|
+
email:
|
85
|
+
- hey@vito.io
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- Gemfile.lock
|
95
|
+
- LICENSE
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- has_gravatar.gemspec
|
99
|
+
- lib/has_gravatar.rb
|
100
|
+
- lib/has_gravatar/extensions.rb
|
101
|
+
- lib/has_gravatar/version.rb
|
102
|
+
- spec/db/.gitkeep
|
103
|
+
- spec/lib/model_caching_spec.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
- spec/support/data.rb
|
106
|
+
- spec/support/models.rb
|
107
|
+
- spec/support/schema.rb
|
108
|
+
homepage: http://github.com/victorgama/has_gravatar
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.2.0
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Dead simple Gravatar URL generator
|
132
|
+
test_files:
|
133
|
+
- spec/db/.gitkeep
|
134
|
+
- spec/lib/model_caching_spec.rb
|
135
|
+
- spec/spec_helper.rb
|
136
|
+
- spec/support/data.rb
|
137
|
+
- spec/support/models.rb
|
138
|
+
- spec/support/schema.rb
|