paperclip-location 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +6 -0
- data/lib/paperclip/location.rb +2 -0
- data/lib/paperclip/location/processor.rb +30 -0
- data/lib/paperclip/location/railtie.rb +14 -0
- data/lib/paperclip/paperclip.rb +1 -0
- data/paperclip-location.gemspec +26 -0
- data/spec/paperclip/location/processor_spec.rb +70 -0
- data/spec/photos/with-exif.jpg +0 -0
- data/spec/photos/without-exif.jpg +0 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/support/photos.rb +16 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 75420e6a446f612b56b79ebc87a8cd3bcf35d58e
|
4
|
+
data.tar.gz: 08346e2ada1feda7fa6ec4bbd58ae9e3947e5546
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6dcd3f47db40ac085d342fc9c4f16cfda48f2d468f6a01432f3d7b7c00f2598031ba48c49e3f506e84f9a02240ea7221df2629d113e0df1687a7263d456f07b9
|
7
|
+
data.tar.gz: 494ebfbebe92985f077136e27d5715a196d6021c018d2a60617f42bfd1648975be8f4e1949082f79ab75b5597a48a85923e8e149b0dc9a02a6800cd77334a81b
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Sean Doyle
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Location Paperclip::Processor
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/seanpdoyle/paperclip-location.png)](https://travis-ci.org/seanpdoyle/paperclip-location)
|
4
|
+
|
5
|
+
Extracts GeoLocation data from an image during Paperclip processing
|
6
|
+
and attaches it to the associated model.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
```ruby
|
12
|
+
gem 'paperclip-location', github: 'seanpdoyle/paperclip-location'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install paperclip-location
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Use it like any other `Paperclip::Processor`
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
class PlaceOfInterest < ActiveRecord::Base
|
29
|
+
|
30
|
+
has_attached_file :photo, styles: { large: '600x600#' },
|
31
|
+
processors: [:thumbnail, :location]
|
32
|
+
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
The processor expects that the model in question has the following:
|
37
|
+
|
38
|
+
* `location_locked` - a boolean flag to determine if the location has been manually overridden
|
39
|
+
* `lat` - a float representing the latitude
|
40
|
+
* `lng` - a float representing the longitude
|
41
|
+
|
42
|
+
If you don't have either, run a migration to add them
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
class AddLocationToModel < ActiveRecord::Migration
|
46
|
+
def self.change
|
47
|
+
add_column :model, :location_locked, :boolean, default: false, null: false
|
48
|
+
add_column :model, :lat, :float
|
49
|
+
add_column :model, :lng, :float
|
50
|
+
end
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
These field names will be customizable in future versions
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
1. Fork it
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
60
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
62
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'paperclip'
|
2
|
+
require 'exifr'
|
3
|
+
|
4
|
+
module Paperclip
|
5
|
+
module Location
|
6
|
+
class Processor < Paperclip::Processor
|
7
|
+
|
8
|
+
delegate :location_locked?, to: :instance, allow_nil: true
|
9
|
+
delegate :instance, to: :attachment, allow_nil: true
|
10
|
+
delegate :gps, to: :exif
|
11
|
+
|
12
|
+
def make
|
13
|
+
if can_process?
|
14
|
+
instance.lat = gps.latitude
|
15
|
+
instance.lng = gps.longitude
|
16
|
+
end
|
17
|
+
file
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def can_process?
|
22
|
+
!location_locked? && gps.present? && instance.present?
|
23
|
+
end
|
24
|
+
|
25
|
+
def exif
|
26
|
+
@exif ||= EXIFR::JPEG.new(file.path)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'paperclip'
|
2
|
+
require 'paperclip/location/processor'
|
3
|
+
|
4
|
+
module Paperclip
|
5
|
+
module Location
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
initializer "paperclip-location.configure_rails_initialization" do
|
8
|
+
Paperclip.configure do |c|
|
9
|
+
c.register_processor :location, Paperclip::Location::Processor.new
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'paperclip/location'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "paperclip-location"
|
7
|
+
spec.version = "0.0.2"
|
8
|
+
spec.authors = ["Sean Doyle"]
|
9
|
+
spec.email = ["sean.p.doyle24@gmail.com"]
|
10
|
+
spec.description = %q{extract geolocation during Paperclip processing}
|
11
|
+
spec.summary = %q{extract geolocation EXIF data during Paperclip processing}
|
12
|
+
spec.homepage = "https://github.com/seanpdoyle/paperclip-location"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.1"
|
22
|
+
spec.add_development_dependency "rspec", "~> 2.14"
|
23
|
+
|
24
|
+
spec.add_dependency "paperclip", "~> 3.5"
|
25
|
+
spec.add_dependency "exifr", "~> 1.1"
|
26
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
def does_nothing(model)
|
4
|
+
%w(lat? lng?).each do |field|
|
5
|
+
expect(model).not_to receive(field)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Paperclip::Location::Processor do
|
10
|
+
subject { described_class.new nil }
|
11
|
+
it { should be_a Paperclip::Processor }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe Paperclip::Location::Processor, '#make' do
|
15
|
+
let(:model) { double :model }
|
16
|
+
let(:attachment) { double :attachment, instance: model }
|
17
|
+
subject { described_class.new(file, {}, attachment) }
|
18
|
+
|
19
|
+
it "returns the original file, unmodified" do
|
20
|
+
file = File.new(Photos::WITHOUT_EXIF.path)
|
21
|
+
expect(described_class.new(file).make).to be file
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when the model's location is locked" do
|
25
|
+
let(:file){ File.new(Photos::WITH_EXIF.path) }
|
26
|
+
|
27
|
+
before do
|
28
|
+
expect(model).to receive(:location_locked?) { true }
|
29
|
+
end
|
30
|
+
|
31
|
+
after do
|
32
|
+
subject.make
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'does not modify the Attachment model' do
|
36
|
+
does_nothing(model)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when the model's location is not locked" do
|
41
|
+
before do
|
42
|
+
expect(model).to receive(:location_locked?) { false }
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'given a file with EXIF GPS data' do
|
46
|
+
let(:file){ File.new(Photos::WITH_EXIF.path) }
|
47
|
+
|
48
|
+
after do
|
49
|
+
subject.make
|
50
|
+
end
|
51
|
+
|
52
|
+
it "sets the `lat` and `lng` on the Attachment's model" do
|
53
|
+
expect(model).to receive(:lat=).with(Photos::WITH_EXIF.lat)
|
54
|
+
expect(model).to receive(:lng=).with(Photos::WITH_EXIF.lng)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'given a file without EXIF' do
|
59
|
+
let(:file){ File.new(Photos::WITHOUT_EXIF.path) }
|
60
|
+
|
61
|
+
after do
|
62
|
+
subject.make
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'does not modify the Attachment model' do
|
66
|
+
does_nothing(model)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
Binary file
|
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module Photos
|
4
|
+
ROOT = File.join(File.dirname(File.realpath(__FILE__)), '../', 'photos')
|
5
|
+
WITH_EXIF = OpenStruct.new(
|
6
|
+
path: File.join(ROOT, 'with-exif.jpg'),
|
7
|
+
lat: 39.99783333333334,
|
8
|
+
lng: -75.2495
|
9
|
+
).freeze
|
10
|
+
|
11
|
+
WITHOUT_EXIF = OpenStruct.new(
|
12
|
+
path: File.join(ROOT, 'without-exif.jpg'),
|
13
|
+
lat: nil,
|
14
|
+
lng: nil
|
15
|
+
).freeze
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paperclip-location
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Doyle
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-31 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
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: paperclip
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.5'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: exifr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.1'
|
83
|
+
description: extract geolocation during Paperclip processing
|
84
|
+
email:
|
85
|
+
- sean.p.doyle24@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
|
+
- .travis.yml
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- lib/paperclip/location.rb
|
98
|
+
- lib/paperclip/location/processor.rb
|
99
|
+
- lib/paperclip/location/railtie.rb
|
100
|
+
- lib/paperclip/paperclip.rb
|
101
|
+
- paperclip-location.gemspec
|
102
|
+
- spec/paperclip/location/processor_spec.rb
|
103
|
+
- spec/photos/with-exif.jpg
|
104
|
+
- spec/photos/without-exif.jpg
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
- spec/support/photos.rb
|
107
|
+
homepage: https://github.com/seanpdoyle/paperclip-location
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.2.0
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: extract geolocation EXIF data during Paperclip processing
|
131
|
+
test_files:
|
132
|
+
- spec/paperclip/location/processor_spec.rb
|
133
|
+
- spec/photos/with-exif.jpg
|
134
|
+
- spec/photos/without-exif.jpg
|
135
|
+
- spec/spec_helper.rb
|
136
|
+
- spec/support/photos.rb
|