gmaps4rails 1.5.7 → 1.5.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +6 -386
- data/.gitignore +0 -17
- data/.travis.yml +0 -10
- data/Gemfile +0 -9
- data/Gemfile.lock +0 -182
- data/Guardfile +0 -24
- data/MIT-LICENSE +0 -20
- data/README.rdoc +0 -135
- data/Rakefile +0 -4
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee +0 -444
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.bing.js.coffee +0 -174
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.googlemaps.js.coffee +0 -339
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.mapquest.js.coffee +0 -145
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.openlayers.js.coffee +0 -261
- data/app/views/gmaps4rails/_gmaps4rails.html.erb +0 -20
- data/gmaps4rails.gemspec +0 -39
- data/lib/generators/gmaps4rails/install_generator.rb +0 -48
- data/lib/generators/templates/README +0 -2
- data/lib/gmaps4rails.rb +0 -26
- data/lib/gmaps4rails/acts_as_gmappable.rb +0 -54
- data/lib/gmaps4rails/api_wrappers/base_net_methods.rb +0 -40
- data/lib/gmaps4rails/api_wrappers/direction.rb +0 -87
- data/lib/gmaps4rails/api_wrappers/geocoder.rb +0 -54
- data/lib/gmaps4rails/api_wrappers/places.rb +0 -74
- data/lib/gmaps4rails/base.rb +0 -119
- data/lib/gmaps4rails/extensions/enumerable.rb +0 -14
- data/lib/gmaps4rails/extensions/hash.rb +0 -9
- data/lib/gmaps4rails/helper/gmaps4rails_helper.rb +0 -33
- data/lib/gmaps4rails/js_builder.rb +0 -157
- data/lib/gmaps4rails/json_builder.rb +0 -140
- data/lib/gmaps4rails/model_handler.rb +0 -101
- data/lib/gmaps4rails/version.rb +0 -3
- data/lib/gmaps4rails/view_helper.rb +0 -175
- data/lib/tasks/gmaps4rails_tasks.rake +0 -4
- data/lib/tasks/jasmine.rake +0 -8
- data/public/javascripts/gmaps4rails/gmaps4rails.base.js +0 -464
- data/public/javascripts/gmaps4rails/gmaps4rails.bing.js +0 -226
- data/public/javascripts/gmaps4rails/gmaps4rails.googlemaps.js +0 -430
- data/public/javascripts/gmaps4rails/gmaps4rails.mapquest.js +0 -178
- data/public/javascripts/gmaps4rails/gmaps4rails.openlayers.js +0 -265
- data/public/stylesheets/gmaps4rails.css +0 -24
- data/spec/dummy/.gitignore +0 -2
- data/spec/dummy/.rspec +0 -1
- data/spec/dummy/README.rdoc +0 -261
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/assets/javascripts/application.js +0 -15
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/assets/stylesheets/gmaps4rails.css +0 -24
- data/spec/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/dummy/app/controllers/users_controller.rb +0 -101
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/place.rb +0 -16
- data/spec/dummy/app/models/user.rb +0 -12
- data/spec/dummy/app/views/layouts/application.html.erb +0 -16
- data/spec/dummy/app/views/users/_form.html.erb +0 -37
- data/spec/dummy/app/views/users/_map.html.erb +0 -5
- data/spec/dummy/app/views/users/edit.html.erb +0 -6
- data/spec/dummy/app/views/users/index.html.erb +0 -260
- data/spec/dummy/app/views/users/new.html.erb +0 -5
- data/spec/dummy/app/views/users/show.html.erb +0 -30
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/application.rb +0 -62
- data/spec/dummy/config/boot.rb +0 -10
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -37
- data/spec/dummy/config/environments/production.rb +0 -67
- data/spec/dummy/config/environments/test.rb +0 -37
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/gmaps4rails.rb +0 -1
- data/spec/dummy/config/initializers/inflections.rb +0 -15
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/dummy/config/initializers/session_store.rb +0 -8
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config/routes.rb +0 -60
- data/spec/dummy/db/migrate/20120408170155_create_users.rb +0 -16
- data/spec/dummy/db/schema.rb +0 -29
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -25
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/Player.js +0 -22
- data/spec/dummy/public/javascripts/Song.js +0 -7
- data/spec/dummy/public/logo.png +0 -0
- data/spec/dummy/script/rails +0 -6
- data/spec/factories/place_factory.rb +0 -16
- data/spec/factories/user_factory.rb +0 -23
- data/spec/fixtures/google_direction_valid.json +0 -65
- data/spec/fixtures/google_geocoding_toulon_france.json +0 -58
- data/spec/fixtures/google_places_valid.json +0 -45
- data/spec/fixtures/google_wrong_geocoding.json +0 -4
- data/spec/javascripts/basic_methods_spec.js +0 -103
- data/spec/javascripts/helpers/.gitkeep +0 -0
- data/spec/javascripts/helpers/SpecHelper.js +0 -87
- data/spec/javascripts/map_spec.js +0 -49
- data/spec/javascripts/markers_methods_spec.js +0 -368
- data/spec/javascripts/mocks_spec.js +0 -27
- data/spec/javascripts/support/jasmine.yml +0 -10
- data/spec/javascripts/support/jasmine_config.rb +0 -23
- data/spec/javascripts/support/jasmine_runner.rb +0 -20
- data/spec/launchers/all_but_requests.rb +0 -0
- data/spec/launchers/all_specs.rb +0 -0
- data/spec/launchers/requests.rb +0 -0
- data/spec/lib/base_spec.rb +0 -59
- data/spec/lib/direction_spec.rb +0 -53
- data/spec/lib/geocoder_spec.rb +0 -46
- data/spec/lib/js_builder_spec.rb +0 -139
- data/spec/lib/json_builder_spec.rb +0 -232
- data/spec/lib/places_spec.rb +0 -25
- data/spec/models/place_spec.rb +0 -35
- data/spec/models/user_spec.rb +0 -187
- data/spec/spec_helper.rb +0 -44
- data/spec/support/geocoding.rb +0 -41
- data/spec/support/matchers.rb +0 -73
@@ -1,14 +0,0 @@
|
|
1
|
-
module Enumerable
|
2
|
-
#Scopes on models generate Arrays
|
3
|
-
#this method enables short call to the json creation for all elements in the array
|
4
|
-
def to_gmaps4rails(&block)
|
5
|
-
output = "["
|
6
|
-
json_array = []
|
7
|
-
each do |object|
|
8
|
-
json = Gmaps4rails.create_json(object, &block)
|
9
|
-
json_array << json.to_s unless json.nil?
|
10
|
-
end
|
11
|
-
output << json_array * (",")
|
12
|
-
output << "]"
|
13
|
-
end
|
14
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
class Hash
|
2
|
-
|
3
|
-
# this method extracts all info from the hash to create javascript
|
4
|
-
# this javascript is then rendered raw to the view so it can be interpreted and executed
|
5
|
-
def to_gmaps4rails
|
6
|
-
Gmaps4rails.create_js_from_hash(self.with_indifferent_access)
|
7
|
-
end
|
8
|
-
|
9
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Gmaps4railsHelper
|
2
|
-
|
3
|
-
# shortcut helper for marker display with convenient default settings
|
4
|
-
# @params [String] builder is a json string
|
5
|
-
def gmaps4rails(builder)
|
6
|
-
options = {
|
7
|
-
:map_options => { :auto_adjust => true},
|
8
|
-
:markers => { :data => builder, :options => {:do_clustering => true} }
|
9
|
-
}
|
10
|
-
gmaps(options)
|
11
|
-
end
|
12
|
-
|
13
|
-
# full helper to pass all variables and their options
|
14
|
-
# @params [Hash] options is a Hash containing data and options. Example: { markers:{ data: @json, options: { do_clustering: true } } }
|
15
|
-
def gmaps(options)
|
16
|
-
options_with_indifferent_access = options.with_indifferent_access
|
17
|
-
view_helper = Gmaps4rails::ViewHelper.new(options_with_indifferent_access)
|
18
|
-
|
19
|
-
js_dependencies = if Gmaps4rails.escape_js_url
|
20
|
-
view_helper.js_dependencies_array
|
21
|
-
else
|
22
|
-
view_helper.js_dependencies_array.map(&:html_safe)
|
23
|
-
end
|
24
|
-
|
25
|
-
render :partial => '/gmaps4rails/gmaps4rails',
|
26
|
-
:locals => {
|
27
|
-
:options => options_with_indifferent_access,
|
28
|
-
:js_dependencies => js_dependencies,
|
29
|
-
:dom => view_helper.dom_attributes
|
30
|
-
}
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
@@ -1,157 +0,0 @@
|
|
1
|
-
module Gmaps4rails
|
2
|
-
class JsBuilder
|
3
|
-
|
4
|
-
DEFAULT_MAP_ID = "map"
|
5
|
-
DATA_KEYS = [:markers, :polylines, :polygons, :circles, :direction, :kml]
|
6
|
-
|
7
|
-
#the 'option_hash' must have the following structure
|
8
|
-
#{
|
9
|
-
# :map_options => hash,
|
10
|
-
# :markers => { :data => json, :options => hash },
|
11
|
-
# :polylines => { :data => json, :options => hash },
|
12
|
-
# :polygons => { :data => json, :options => hash },
|
13
|
-
# :circles => { :data => json, :options => hash },
|
14
|
-
# :direction => { :data => hash, :options => hash },
|
15
|
-
# :kml => { :data => json, :options => hash }
|
16
|
-
#}
|
17
|
-
#should be with only symbol keys or with indifferent access
|
18
|
-
def initialize(option_hash)
|
19
|
-
@js = Array.new
|
20
|
-
@hash = option_hash
|
21
|
-
end
|
22
|
-
|
23
|
-
def create_js
|
24
|
-
@js << "#{gmap_id} = new #{ map_constructor };"
|
25
|
-
@js << "Gmaps.#{js_function_name} = function() {"
|
26
|
-
|
27
|
-
process_map_options
|
28
|
-
|
29
|
-
@js << "#{gmap_id}.initialize();"
|
30
|
-
|
31
|
-
process_data
|
32
|
-
|
33
|
-
@js << "#{gmap_id}.adjustMapToBounds();"
|
34
|
-
@js << "#{gmap_id}.callback();"
|
35
|
-
@js << "};"
|
36
|
-
@js << "Gmaps.oldOnload = window.onload;\n window.onload = function() { Gmaps.triggerOldOnload(); Gmaps.loadMaps(); };" if load_map?
|
37
|
-
|
38
|
-
@js * ("\n")
|
39
|
-
end
|
40
|
-
|
41
|
-
def process_map_options
|
42
|
-
return unless map_options
|
43
|
-
map_options.each do |option_key, option_value|
|
44
|
-
next if [:class, :container_class].include? option_key.to_sym
|
45
|
-
case option_key.to_sym
|
46
|
-
when :bounds, :raw #particular case, render the content unescaped
|
47
|
-
@js << "#{gmap_id}.map_options.#{option_key} = #{option_value};"
|
48
|
-
else
|
49
|
-
@js << "#{gmap_id}.map_options.#{option_key} = #{option_value.to_json};"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def process_data
|
55
|
-
data.each do |name, hash|
|
56
|
-
datum = ::Gmaps4rails::JsBuilder::Datum.new(gmap_id, name, hash)
|
57
|
-
@js.concat datum.create_js
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def map_options
|
62
|
-
@hash[:map_options]
|
63
|
-
end
|
64
|
-
|
65
|
-
def data
|
66
|
-
@hash.select{|key, value| DATA_KEYS.include?(key.to_sym) }
|
67
|
-
end
|
68
|
-
|
69
|
-
def load_map?
|
70
|
-
@hash[:last_map].nil? || @hash[:last_map] == true
|
71
|
-
end
|
72
|
-
|
73
|
-
def js_function_name
|
74
|
-
"load_" + map_id
|
75
|
-
end
|
76
|
-
|
77
|
-
def gmap_id
|
78
|
-
@gmap_id ||= "Gmaps." + map_id
|
79
|
-
end
|
80
|
-
|
81
|
-
def map_id
|
82
|
-
@map_id ||= map_options.try(:[],:id) || DEFAULT_MAP_ID
|
83
|
-
end
|
84
|
-
|
85
|
-
def map_constructor
|
86
|
-
map_options.try(:[],:provider) ? "Gmaps4Rails#{map_options[:provider].capitalize}()" : "Gmaps4RailsGoogle()"
|
87
|
-
end
|
88
|
-
|
89
|
-
class Datum
|
90
|
-
# example:
|
91
|
-
# - name: :markers
|
92
|
-
# - hash: { :data => json, :options => hash }
|
93
|
-
|
94
|
-
delegate :options, :data, :to => :@element_info
|
95
|
-
|
96
|
-
def initialize(gmap_id, name, hash)
|
97
|
-
@gmap_id, @name, @js = gmap_id, name, Array.new
|
98
|
-
@element_info = OpenStruct.new(hash)
|
99
|
-
end
|
100
|
-
|
101
|
-
def create_js
|
102
|
-
if @name.to_sym == :direction
|
103
|
-
create_direction_js
|
104
|
-
else
|
105
|
-
create_standard_js
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def create_standard_js
|
110
|
-
@js << "#{@gmap_id}.#{@name} = #{data};"
|
111
|
-
|
112
|
-
set_configuration_variables
|
113
|
-
|
114
|
-
@js << "#{@gmap_id}.create_#{@name}();"
|
115
|
-
end
|
116
|
-
|
117
|
-
def create_direction_js
|
118
|
-
@js << "#{@gmap_id}.direction_conf.origin = '#{data["from"]}';"
|
119
|
-
@js << "#{@gmap_id}.direction_conf.destination = '#{data["to"]}';"
|
120
|
-
|
121
|
-
set_direction_variables
|
122
|
-
|
123
|
-
@js << "#{@gmap_id}.create_direction();"
|
124
|
-
end
|
125
|
-
|
126
|
-
def set_configuration_variables
|
127
|
-
return unless options
|
128
|
-
options.each do |option_key, option_value|
|
129
|
-
@js << if option_key.to_sym == :raw
|
130
|
-
"#{@gmap_id}.#{@name}_conf.#{option_key} = #{option_value};"
|
131
|
-
else
|
132
|
-
"#{@gmap_id}.#{@name}_conf.#{option_key} = #{option_value.to_json};"
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def set_direction_variables
|
138
|
-
return unless options
|
139
|
-
options.each do |option_key, option_value|
|
140
|
-
if option_key.to_sym == :waypoints
|
141
|
-
waypoints = Array.new
|
142
|
-
option_value.each do |waypoint|
|
143
|
-
waypoints << { "location" => waypoint, "stopover" => true }.to_json
|
144
|
-
end
|
145
|
-
@js << "#{@gmap_id}.direction_conf.waypoints = [#{waypoints * (",")}];"
|
146
|
-
else
|
147
|
-
@js << "#{@gmap_id}.direction_conf.#{option_key} = #{option_value.to_json};"
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
|
156
|
-
end
|
157
|
-
|
@@ -1,140 +0,0 @@
|
|
1
|
-
module Gmaps4rails
|
2
|
-
# the to_gmaps4rails method accepts a block to customize:
|
3
|
-
# - infowindow
|
4
|
-
# - picture
|
5
|
-
# - title
|
6
|
-
# - sidebar
|
7
|
-
# - json
|
8
|
-
#
|
9
|
-
# This works this way:
|
10
|
-
# @json = User.all.to_gmaps4rails do |user, marker|
|
11
|
-
# marker.infowindow render_to_string(:partial => "/users/my_template", :locals => { :object => user}).gsub(/\n/, '').gsub(/"/, '\"')
|
12
|
-
# marker.picture({
|
13
|
-
# :picture => "http://www.blankdots.com/img/github-32x32.png",
|
14
|
-
# :width => "32",
|
15
|
-
# :height => "32"
|
16
|
-
# })
|
17
|
-
# marker.title "i'm the title"
|
18
|
-
# marker.sidebar "i'm the sidebar"
|
19
|
-
# marker.json({ :id => user.id })
|
20
|
-
# end
|
21
|
-
#
|
22
|
-
# For backward compability, a mere string could be passed:
|
23
|
-
# @json = User.all.to_gmaps4rails do |user, marker|
|
24
|
-
# "\"id\": #{user.id}"
|
25
|
-
# end
|
26
|
-
#
|
27
|
-
class JsonBuilder
|
28
|
-
|
29
|
-
delegate :position, :lat_column, :lng_column, :to => :@options
|
30
|
-
|
31
|
-
def initialize(object)
|
32
|
-
@object, @json_hash, @custom_json = object, Hash.new, nil
|
33
|
-
@options = OpenStruct.new @object.gmaps4rails_options
|
34
|
-
end
|
35
|
-
|
36
|
-
def process(&block)
|
37
|
-
if compliant?
|
38
|
-
handle_block(&block) if block_given?
|
39
|
-
handle_model_methods
|
40
|
-
return_json
|
41
|
-
else
|
42
|
-
nil
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def infowindow(string)
|
47
|
-
@json_hash[:description] = string
|
48
|
-
true
|
49
|
-
end
|
50
|
-
|
51
|
-
def title(string)
|
52
|
-
@json_hash[:title] = string
|
53
|
-
true
|
54
|
-
end
|
55
|
-
|
56
|
-
def sidebar(string)
|
57
|
-
@json_hash[:sidebar] = string
|
58
|
-
true
|
59
|
-
end
|
60
|
-
|
61
|
-
def json(json)
|
62
|
-
return @json_hash.merge! json if json.is_a? Hash
|
63
|
-
true
|
64
|
-
end
|
65
|
-
|
66
|
-
def picture(hash)
|
67
|
-
@json_hash.merge! hash
|
68
|
-
true
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
|
73
|
-
def model_attributes
|
74
|
-
{
|
75
|
-
:description => :gmaps4rails_infowindow,
|
76
|
-
:title => :gmaps4rails_title,
|
77
|
-
:sidebar => :gmaps4rails_sidebar,
|
78
|
-
:marker_picture => :gmaps4rails_marker_picture
|
79
|
-
}.merge(coordinates_attributes)
|
80
|
-
end
|
81
|
-
|
82
|
-
def coordinates_attributes
|
83
|
-
position_from_array? ? {:position => position } : {:lat => lat_column, :lng => lng_column}
|
84
|
-
end
|
85
|
-
|
86
|
-
def handle_model_methods
|
87
|
-
model_attributes.each do |json_name, method_name|
|
88
|
-
if @object.respond_to? method_name
|
89
|
-
if json_name == :marker_picture
|
90
|
-
@json_hash.merge!(@object.send(method_name)) unless @json_hash.has_key? "picture"
|
91
|
-
elsif json_name == :position
|
92
|
-
@json_hash.merge!(:lat => lat, :lng => lng)
|
93
|
-
else
|
94
|
-
@json_hash[json_name] = @object.send(method_name) unless @json_hash.has_key? json_name
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
# returns the proper json
|
101
|
-
# three cases here:
|
102
|
-
# - no custom json provided
|
103
|
-
# - custom json provided as a hash (marker.json { :id => user.id }) => merge hashes then create json
|
104
|
-
# - custom json provided as string (marker.json {"\"id\": #{user.id}" } => create json from hash then insert string inside
|
105
|
-
def return_json
|
106
|
-
return @json_hash.to_json if @custom_json.nil?
|
107
|
-
case @custom_json
|
108
|
-
when Hash
|
109
|
-
@json_hash.merge! @custom_json
|
110
|
-
return @json_hash.to_json
|
111
|
-
when String
|
112
|
-
output = @json_hash.to_json
|
113
|
-
return output.insert(1, @custom_json + ",")
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def compliant?
|
118
|
-
!(lat.blank? && lng.blank?)
|
119
|
-
end
|
120
|
-
|
121
|
-
def handle_block(&block)
|
122
|
-
block_result = yield(@object, self)
|
123
|
-
@custom_json = block_result unless block_result == true
|
124
|
-
end
|
125
|
-
|
126
|
-
def position_from_array?
|
127
|
-
position #if gmaps4rails_options[:position] is filled, means user is indicating an array
|
128
|
-
end
|
129
|
-
|
130
|
-
def lat
|
131
|
-
position_from_array? ? @object.send("#{position}")[0] : @object.send("#{lat_column}")
|
132
|
-
end
|
133
|
-
|
134
|
-
def lng
|
135
|
-
position_from_array? ? @object.send("#{position}")[1] : @object.send("#{lng_column}")
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
module Gmaps4rails
|
2
|
-
|
3
|
-
class ModelHandler
|
4
|
-
|
5
|
-
attr_accessor :options, :object
|
6
|
-
|
7
|
-
delegate :process_geocoding, :check_process, :checker, :lat_column, :lng_column, :position, :msg, :validation,
|
8
|
-
:language, :protocol, :address, :callback, :normalized_address,
|
9
|
-
:to => :options
|
10
|
-
|
11
|
-
def initialize(object, gmaps4rails_options)
|
12
|
-
@options = ::OpenStruct.new(gmaps4rails_options)
|
13
|
-
@object = object
|
14
|
-
end
|
15
|
-
|
16
|
-
# saves coordinates according to the various options
|
17
|
-
def retrieve_coordinates
|
18
|
-
return if prevent_geocoding?
|
19
|
-
checked_coordinates do
|
20
|
-
position? ? set_position : set_lat_lng
|
21
|
-
# save normalized address if required
|
22
|
-
object.send("#{normalized_address}=", coordinates.first[:matched_address]) if normalized_address
|
23
|
-
# Call the callback method to let the user do what he wants with the data
|
24
|
-
object.send callback, coordinates.first[:full_data] if callback
|
25
|
-
# update checker if required
|
26
|
-
object.send("#{checker}=", true) if check_geocoding?
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
# sets array for non relationnal db
|
33
|
-
def set_position
|
34
|
-
object.send("#{position}=", [lat, lng])
|
35
|
-
end
|
36
|
-
|
37
|
-
#sets regular columns
|
38
|
-
def set_lat_lng
|
39
|
-
object.send("#{lng_column}=", lng)
|
40
|
-
object.send("#{lat_column}=", lat)
|
41
|
-
end
|
42
|
-
|
43
|
-
def lat
|
44
|
-
coordinates.first[:lat]
|
45
|
-
end
|
46
|
-
|
47
|
-
def lng
|
48
|
-
coordinates.first[:lng]
|
49
|
-
end
|
50
|
-
|
51
|
-
def position?
|
52
|
-
position
|
53
|
-
end
|
54
|
-
|
55
|
-
def checked_coordinates(&block)
|
56
|
-
yield if coordinates
|
57
|
-
end
|
58
|
-
|
59
|
-
def coordinates
|
60
|
-
@coordinates ||= get_coordinates
|
61
|
-
end
|
62
|
-
|
63
|
-
def get_coordinates
|
64
|
-
Gmaps4rails.geocode(object.send(address), language, false, protocol)
|
65
|
-
rescue GeocodeStatus, GeocodeInvalidQuery => e #address was invalid, add error to address.
|
66
|
-
Rails.logger.warn(e)
|
67
|
-
object.errors[address] << msg if condition_eval(object, validation)
|
68
|
-
false
|
69
|
-
rescue GeocodeNetStatus => e #connection error, No need to prevent save.
|
70
|
-
Rails.logger.warn(e)
|
71
|
-
false
|
72
|
-
end
|
73
|
-
|
74
|
-
# to prevent geocoding each time a save is made
|
75
|
-
# if process_geocoding is a TrueClass or a FalseClass, 'check_process' and 'checker' play an additional role
|
76
|
-
# if process_geocoding is a Proc or a Symbol, 'check_process' and 'checker' are skipped since process_geocoding bears the whole logic
|
77
|
-
def prevent_geocoding?
|
78
|
-
if process_geocoding.is_a?(TrueClass) || process_geocoding.is_a?(FalseClass)
|
79
|
-
return true if !condition_eval(object, process_geocoding)
|
80
|
-
condition_eval(object, check_process) && object.send(checker)
|
81
|
-
else
|
82
|
-
!condition_eval(object, process_geocoding)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
# Do we have to check the geocoding
|
87
|
-
def check_geocoding?
|
88
|
-
if process_geocoding.is_a?(TrueClass) || process_geocoding.is_a?(FalseClass)
|
89
|
-
condition_eval(object, check_process)
|
90
|
-
else
|
91
|
-
false
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def condition_eval(*args)
|
96
|
-
Gmaps4rails.condition_eval(*args)
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|