url_attributes 1.1.1 → 1.2.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.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/lib/url_attributes/extensions/active_record.rb +5 -2
- data/lib/url_attributes/rspec/have_url_attribute.rb +1 -1
- data/lib/url_attributes/version.rb +1 -1
- data/spec/dummy/app/models/model.rb +2 -0
- data/spec/dummy/db/migrate/20150105143321_add_other_url_to_model.rb +5 -0
- data/spec/dummy/db/schema.rb +2 -1
- data/spec/url_attributes_spec.rb +9 -0
- data/url_attributes.gemspec +3 -1
- metadata +8 -7
- data/spec/dummy/Gemfile +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2b9ac4bb2330e36f9a6ce629b265c2926793569
|
4
|
+
data.tar.gz: e78f758a61bc52cc6f65810e7a42e9e3e2efe0bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb761cd88a6478fa89114448792aa47c928eb61806d57965e75eb939070c85eaf65e2740e46efbc1d6690a670156c044dd60df0db9d66d640e445154b9577b7f
|
7
|
+
data.tar.gz: b3ba4110e2e2a08f22d375c8e55895c2e09dfb6c4626c8f8ddaaaf0412bd2bcf4addeb82f91d1c9a51c413a88e6c2c15d03b6f079e32de68187b742915536fef
|
data/README.md
CHANGED
@@ -24,8 +24,17 @@ then call the class method `url_attribute` in your model like this:
|
|
24
24
|
This does two things:
|
25
25
|
|
26
26
|
1. It adds a validation to `link` that
|
27
|
-
2. Before save, it strips trailing whitespace from the link and adds
|
28
|
-
if it (or `"https://"`) is not already there.
|
27
|
+
2. Before save, it strips trailing whitespace from the link and adds
|
28
|
+
`"http://"` to the beginning if it (or `"https://"`) is not already there.
|
29
|
+
|
30
|
+
If you want the logic to run somewhere other than `before_save`, pass a
|
31
|
+
`:before` option with the name of another `before_` callback:
|
32
|
+
|
33
|
+
class MyAwesomeModel < ActiveRecord::Base
|
34
|
+
|
35
|
+
url_attribute :link, before: :validation
|
36
|
+
|
37
|
+
end
|
29
38
|
|
30
39
|
## Matcher
|
31
40
|
|
@@ -13,17 +13,20 @@
|
|
13
13
|
module URLAttributes
|
14
14
|
module ActiveRecord
|
15
15
|
|
16
|
-
def url_attribute(attribute_name,
|
16
|
+
def url_attribute(attribute_name, before: :save)
|
17
17
|
validates attribute_name, :url => true, :if => "#{attribute_name}.present?"
|
18
18
|
|
19
|
+
callback_method = :"before_#{before}"
|
20
|
+
|
19
21
|
# Add "http://" to the URL if it's not already there.
|
20
|
-
|
22
|
+
send(callback_method) do |record|
|
21
23
|
url = record[attribute_name]
|
22
24
|
if url.present? && !(url =~ /\A\s*https?:\/\//)
|
23
25
|
url = "http://#{url.try(:strip)}"
|
24
26
|
end
|
25
27
|
record[attribute_name] = url
|
26
28
|
end
|
29
|
+
|
27
30
|
end
|
28
31
|
|
29
32
|
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,12 +11,13 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20150105143321) do
|
15
15
|
|
16
16
|
create_table "models", force: true do |t|
|
17
17
|
t.string "url"
|
18
18
|
t.datetime "created_at"
|
19
19
|
t.datetime "updated_at"
|
20
|
+
t.string "other_url"
|
20
21
|
end
|
21
22
|
|
22
23
|
end
|
data/spec/url_attributes_spec.rb
CHANGED
@@ -65,4 +65,13 @@ describe "ActiveRecord::Base#url_attribute" do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
68
|
+
|
69
|
+
context "when passed a 'before' option" do
|
70
|
+
it "runs the callbacks on the given validation instead of before_save" do
|
71
|
+
model.other_url = " example.com/example "
|
72
|
+
model.run_callbacks :validation
|
73
|
+
expect(model.other_url).to eq "http://example.com/example"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
68
77
|
end
|
data/url_attributes.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = ["georgejulianmillo@gmail.com"]
|
11
11
|
s.summary = "Simple URL attributes for ActiveRecord"
|
12
12
|
s.description = "Validate and sanitize URLs in ActiveRecord"
|
13
|
-
s.homepage = 'http://github.com/
|
13
|
+
s.homepage = 'http://github.com/headstock/url_attributes'
|
14
14
|
s.license = "MIT"
|
15
15
|
|
16
16
|
s.files = `git ls-files -z`.split("\x0")
|
@@ -18,6 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
+
s.required_ruby_version = ">= 2.0.0"
|
22
|
+
|
21
23
|
s.add_dependency "rails", ">= 4.0.0"
|
22
24
|
|
23
25
|
s.add_development_dependency "bundler", "~> 1.7"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: url_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- George Millo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -114,7 +114,6 @@ files:
|
|
114
114
|
- lib/url_attributes/url_validator.rb
|
115
115
|
- lib/url_attributes/version.rb
|
116
116
|
- spec/dummy/.gitignore
|
117
|
-
- spec/dummy/Gemfile
|
118
117
|
- spec/dummy/Gemfile.lock
|
119
118
|
- spec/dummy/README.rdoc
|
120
119
|
- spec/dummy/Rakefile
|
@@ -153,6 +152,7 @@ files:
|
|
153
152
|
- spec/dummy/config/routes.rb
|
154
153
|
- spec/dummy/config/secrets.yml
|
155
154
|
- spec/dummy/db/migrate/20141124095718_create_models.rb
|
155
|
+
- spec/dummy/db/migrate/20150105143321_add_other_url_to_model.rb
|
156
156
|
- spec/dummy/db/schema.rb
|
157
157
|
- spec/dummy/db/seeds.rb
|
158
158
|
- spec/dummy/lib/assets/.keep
|
@@ -169,7 +169,7 @@ files:
|
|
169
169
|
- spec/spec_helper.rb
|
170
170
|
- spec/url_attributes_spec.rb
|
171
171
|
- url_attributes.gemspec
|
172
|
-
homepage: http://github.com/
|
172
|
+
homepage: http://github.com/headstock/url_attributes
|
173
173
|
licenses:
|
174
174
|
- MIT
|
175
175
|
metadata: {}
|
@@ -181,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
181
|
requirements:
|
182
182
|
- - ">="
|
183
183
|
- !ruby/object:Gem::Version
|
184
|
-
version:
|
184
|
+
version: 2.0.0
|
185
185
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
186
|
requirements:
|
187
187
|
- - ">="
|
@@ -189,13 +189,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
189
189
|
version: '0'
|
190
190
|
requirements: []
|
191
191
|
rubyforge_project:
|
192
|
-
rubygems_version: 2.4.
|
192
|
+
rubygems_version: 2.4.4
|
193
193
|
signing_key:
|
194
194
|
specification_version: 4
|
195
195
|
summary: Simple URL attributes for ActiveRecord
|
196
196
|
test_files:
|
197
197
|
- spec/dummy/.gitignore
|
198
|
-
- spec/dummy/Gemfile
|
199
198
|
- spec/dummy/Gemfile.lock
|
200
199
|
- spec/dummy/README.rdoc
|
201
200
|
- spec/dummy/Rakefile
|
@@ -234,6 +233,7 @@ test_files:
|
|
234
233
|
- spec/dummy/config/routes.rb
|
235
234
|
- spec/dummy/config/secrets.yml
|
236
235
|
- spec/dummy/db/migrate/20141124095718_create_models.rb
|
236
|
+
- spec/dummy/db/migrate/20150105143321_add_other_url_to_model.rb
|
237
237
|
- spec/dummy/db/schema.rb
|
238
238
|
- spec/dummy/db/seeds.rb
|
239
239
|
- spec/dummy/lib/assets/.keep
|
@@ -249,3 +249,4 @@ test_files:
|
|
249
249
|
- spec/rails_helper.rb
|
250
250
|
- spec/spec_helper.rb
|
251
251
|
- spec/url_attributes_spec.rb
|
252
|
+
has_rdoc:
|
data/spec/dummy/Gemfile
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
|
4
|
-
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
5
|
-
gem 'rails', '4.1.8'
|
6
|
-
# Use sqlite3 as the database for Active Record
|
7
|
-
gem 'sqlite3'
|
8
|
-
# Use SCSS for stylesheets
|
9
|
-
gem 'sass-rails', '~> 4.0.3'
|
10
|
-
# Use Uglifier as compressor for JavaScript assets
|
11
|
-
gem 'uglifier', '>= 1.3.0'
|
12
|
-
# Use CoffeeScript for .js.coffee assets and views
|
13
|
-
gem 'coffee-rails', '~> 4.0.0'
|
14
|
-
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
15
|
-
# gem 'therubyracer', platforms: :ruby
|
16
|
-
|
17
|
-
# Use jquery as the JavaScript library
|
18
|
-
gem 'jquery-rails'
|
19
|
-
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
|
20
|
-
gem 'turbolinks'
|
21
|
-
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
22
|
-
gem 'jbuilder', '~> 2.0'
|
23
|
-
# bundle exec rake doc:rails generates the API under doc/api.
|
24
|
-
gem 'sdoc', '~> 0.4.0', group: :doc
|
25
|
-
|
26
|
-
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
|
27
|
-
gem 'spring', group: :development
|
28
|
-
|
29
|
-
# Use ActiveModel has_secure_password
|
30
|
-
# gem 'bcrypt', '~> 3.1.7'
|
31
|
-
|
32
|
-
# Use unicorn as the app server
|
33
|
-
# gem 'unicorn'
|
34
|
-
|
35
|
-
# Use Capistrano for deployment
|
36
|
-
# gem 'capistrano-rails', group: :development
|
37
|
-
|
38
|
-
# Use debugger
|
39
|
-
# gem 'debugger', group: [:development, :test]
|
40
|
-
|