scaffold_plus 1.7.0 → 1.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/generators/scaffold_plus/geodesic/geodesic_generator.rb +48 -0
- data/lib/scaffold_plus/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07be1c74af7be1b70d689173591c67a9f207eb96
|
4
|
+
data.tar.gz: a3170fff4e3a8eb3d6c47afb0a573c97126f96be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1addc25650114a13fc8b06e29115af6bf36453bab28a3de82ab52eca4f355bbba1aad7c9fff9a2fda7f06a4a5a607f6fbcbced58c5e35bf17d06cee186518ec5
|
7
|
+
data.tar.gz: fd4d3c6cc759505aa1797b2a94340a40e81b6aa61592c375f4693c94bebcae8fd6993d16832ef4900dbda40dcadc381acbd4fc6b7a984d6344fd67e7c1c80296
|
data/README.md
CHANGED
@@ -87,6 +87,13 @@ tries to isolate the country from the address and stores the country
|
|
87
87
|
code (e.g. DE or NL) in a given 'country' attribute. This is currently
|
88
88
|
only implemented for Germany (DE).
|
89
89
|
|
90
|
+
### Add geodesic to resource
|
91
|
+
rails generate scaffold_plus:geodesic
|
92
|
+
|
93
|
+
This helper requires the [geodesic_wgs84](https://github.com/volkerwiegand/geodesic_wgs84)
|
94
|
+
gem. The purpose of this helper is to add a "to_ary" method to the model, which
|
95
|
+
makes it easy to use the resource in calulations like average distance and the like.
|
96
|
+
|
90
97
|
## Testing
|
91
98
|
|
92
99
|
Since I have no experience with test driven development (yet), this is
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module ScaffoldPlus
|
4
|
+
module Generators
|
5
|
+
class GeodesicGenerator < ActiveRecord::Generators::Base
|
6
|
+
desc "Prepare resource for geo functions with geodesic_wgs84 gem"
|
7
|
+
argument :name, type: :string,
|
8
|
+
desc: "The object to be prepared"
|
9
|
+
class_option :latitude, type: :string, default: "lat",
|
10
|
+
desc: 'Attribute used for storing latitude'
|
11
|
+
class_option :longitude, type: :string, default: "lng",
|
12
|
+
desc: 'Attribute used for storing longitude'
|
13
|
+
|
14
|
+
def update_model
|
15
|
+
lat = options.latitude
|
16
|
+
lon = options.longitude
|
17
|
+
file = "app/models/#{name}.rb"
|
18
|
+
prepend_to_file file, "require 'geodesic_wgs84'\n\n"
|
19
|
+
lines = [
|
20
|
+
" def to_ary",
|
21
|
+
" [#{lat}, #{lon}]",
|
22
|
+
" end",
|
23
|
+
"",
|
24
|
+
" after_validation :update_coordinates, on: [:create, :update]",
|
25
|
+
"",
|
26
|
+
" protected",
|
27
|
+
"",
|
28
|
+
" def update_coordinates",
|
29
|
+
" wgs84 = Wgs84.new",
|
30
|
+
" if self.#{lat}.blank? and self.#{lon}.blank?",
|
31
|
+
" if self.#{lat}_dms.present? and self.#{lon}_dms.present?",
|
32
|
+
" self.#{lat}, self.#{lon} = wgs84.lat_lon(self.#{lat}_dms, self.#{lon}_dms)",
|
33
|
+
" end",
|
34
|
+
" end",
|
35
|
+
" if self.#{lat}_dms.blank? and self.#{lon}_dms.blank?",
|
36
|
+
" if self.#{lat}.present? and self.#{lon}.present?",
|
37
|
+
" self.#{lat}_dms, self.#{lon}_dms = wgs84.lat_lon_dms(self.#{lat}, self.#{lon})",
|
38
|
+
" end",
|
39
|
+
" end",
|
40
|
+
" true",
|
41
|
+
" end",
|
42
|
+
""
|
43
|
+
]
|
44
|
+
inject_into_class file, class_name, lines.join("\n")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scaffold_plus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Volker Wiegand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/generators/scaffold_plus/geocoder/geocoder_generator.rb
|
91
91
|
- lib/generators/scaffold_plus/geocoder_init/geocoder_init_generator.rb
|
92
92
|
- lib/generators/scaffold_plus/geocoder_init/templates/geocoder.rb
|
93
|
+
- lib/generators/scaffold_plus/geodesic/geodesic_generator.rb
|
93
94
|
- lib/generators/scaffold_plus/habtm/habtm_generator.rb
|
94
95
|
- lib/generators/scaffold_plus/habtm/templates/habtm_migration.rb
|
95
96
|
- lib/generators/scaffold_plus/has_many/has_many_generator.rb
|