geopolitical 0.8.1 → 0.8.2
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 +24 -2
- data/app/controllers/geopolitical/cities_controller.rb +6 -3
- data/app/controllers/geopolitical/geopolitical_controller.rb +11 -12
- data/app/controllers/geopolitical/hoods_controller.rb +5 -2
- data/app/controllers/geopolitical/nations_controller.rb +2 -1
- data/app/controllers/geopolitical/regions_controller.rb +2 -1
- data/app/controllers/geopolitical/zones_controller.rb +2 -0
- data/app/helpers/geopolitical/application_helper.rb +1 -0
- data/app/models/address.rb +17 -6
- data/app/models/city.rb +10 -9
- data/app/models/hood.rb +3 -0
- data/app/models/nation.rb +7 -3
- data/app/models/region.rb +5 -4
- data/app/models/zone.rb +3 -2
- data/app/models/zone_member.rb +3 -2
- data/app/views/geopolitical/addresses/_address.html.haml +6 -0
- data/app/views/geopolitical/addresses/_form.html.haml +17 -0
- data/config/routes.rb +2 -2
- data/lib/geopolitical.rb +10 -5
- data/lib/geopolitical/engine.rb +1 -0
- data/lib/geopolitical/helpers.rb +5 -3
- data/lib/geopolitical/version.rb +2 -1
- data/spec/dummy/log/test.log +1216 -0
- data/spec/fabricators/address_fabricator.rb +8 -0
- data/spec/fabricators/city_fabricator.rb +2 -2
- data/spec/fabricators/hood_fabricator.rb +1 -2
- data/spec/fabricators/nation_fabricator.rb +1 -1
- data/spec/models/city_spec.rb +25 -25
- data/spec/models/hood_spec.rb +4 -7
- data/spec/models/nation_spec.rb +22 -2
- data/spec/models/region_spec.rb +2 -5
- data/spec/spec_helper.rb +6 -6
- metadata +34 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ba638d2868ace9fb9e0caebe149994928b9d6ef
|
4
|
+
data.tar.gz: bb3a1a730a0f71772c57b120538282dde7110fad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56cbf39e36148afb57aad0bb868dfa0b31b75effea99b2c1e0939c1ba672a479a1b1b83ea202fc4d29abb6911441a3b95673ad972341dd637f1c2a7186d092d9
|
7
|
+
data.tar.gz: e0cee615ed978bb7b1a4df5c88d1f0c1a2241f393cbfeb1533f88e5ce4f14404873214dbd5ab0f472def1b344e3258e2a1d73547395b9ef220ebd2f96b79364f
|
data/README.md
CHANGED
@@ -8,8 +8,30 @@ Geopolitical
|
|
8
8
|
|
9
9
|
Geopolitical models ready to use!
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
|
12
|
+
With
|
13
|
+
----
|
14
|
+
|
15
|
+
|
16
|
+
gem "geopolitical"
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
I have
|
21
|
+
------
|
22
|
+
|
23
|
+
|
24
|
+
Hood, City, Region, Nation + Spot.
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
Geopolitical
|
29
|
+
------------
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
13
35
|
|
14
36
|
|
15
37
|
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module Geopolitical
|
2
|
+
# Cities Public Controller
|
2
3
|
class CitiesController < GeopoliticalController
|
3
4
|
# allow "admin"
|
4
5
|
inherit_resources
|
5
|
-
before_filter :load_relatives, :
|
6
|
+
before_filter :load_relatives, only: [:new, :edit, :create, :update]
|
6
7
|
|
7
8
|
def collection
|
8
|
-
@cities = City.ordered.search(params[:search]).page(params[:page])
|
9
|
+
@cities = City.ordered.search(params[:search]).page(params[:page])
|
9
10
|
end
|
10
11
|
|
11
12
|
private
|
@@ -17,7 +18,9 @@ module Geopolitical
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def load_relatives
|
20
|
-
@regions = Region.only(:name).map {|e| [e.name,e.id]}
|
21
|
+
@regions = Region.only(:name).map { |e| [e.name, e.id] }
|
21
22
|
end
|
23
|
+
|
22
24
|
end
|
25
|
+
|
23
26
|
end
|
@@ -1,21 +1,20 @@
|
|
1
1
|
module Geopolitical
|
2
|
-
|
2
|
+
# Main Geopolitical Controller
|
3
|
+
class GeopoliticalController < ActionController::Base
|
3
4
|
|
4
|
-
|
5
|
+
layout 'geopolitical'
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def index
|
8
|
+
@regions = Region.all
|
9
|
+
@cities = City.all
|
10
|
+
end
|
10
11
|
|
12
|
+
private
|
11
13
|
|
12
|
-
|
14
|
+
def permitted_params
|
15
|
+
params.permit!
|
16
|
+
end
|
13
17
|
|
14
|
-
def permitted_params
|
15
|
-
params.permit!
|
16
18
|
end
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
20
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module Geopolitical
|
2
|
+
# Hoods Main Public Interface
|
2
3
|
class HoodsController < GeopoliticalController
|
3
4
|
inherit_resources
|
4
5
|
# belongs_to :city
|
5
6
|
# respond_to :html, :xml, :json
|
6
|
-
before_filter :load_relatives, :
|
7
|
+
before_filter :load_relatives, only: [:new, :edit, :create, :update]
|
7
8
|
|
8
9
|
def collection
|
9
10
|
@hoods = Hood.ordered.page(params[:page])
|
@@ -12,7 +13,9 @@ module Geopolitical
|
|
12
13
|
private
|
13
14
|
|
14
15
|
def load_relatives
|
15
|
-
@cities = City.only(:name).map {|e| [e.name,e.id]}
|
16
|
+
@cities = City.only(:name).map { |e| [e.name, e.id] }
|
16
17
|
end
|
18
|
+
|
17
19
|
end
|
20
|
+
|
18
21
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module Geopolitical
|
2
|
+
# Main Regions Controller
|
2
3
|
class RegionsController < GeopoliticalController
|
3
4
|
inherit_resources
|
4
|
-
before_filter :get_relatives, :
|
5
|
+
before_filter :get_relatives, only: [:new, :edit, :create, :update]
|
5
6
|
|
6
7
|
def collection
|
7
8
|
@regions = Region.ordered.page(params[:page])
|
data/app/models/address.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
#
|
2
|
+
# Geopolitical Address
|
3
|
+
#
|
1
4
|
class Address
|
2
5
|
include Mongoid::Document
|
3
6
|
# include Mongoid::Symbolize
|
@@ -5,9 +8,9 @@ class Address
|
|
5
8
|
include Mongoid::Geospatial
|
6
9
|
|
7
10
|
field :zip, type: String
|
8
|
-
field :name, type: String
|
9
|
-
field :title, type: String
|
10
|
-
field :number, type: String
|
11
|
+
field :name, type: String # My house, my work...
|
12
|
+
field :title, type: String # St, Rd, Av, Area, Park Foo
|
13
|
+
field :number, type: String # least surprise fail
|
11
14
|
field :extra, type: String
|
12
15
|
field :info, type: String
|
13
16
|
|
@@ -18,14 +21,22 @@ class Address
|
|
18
21
|
field :region_name, type: String
|
19
22
|
field :nation_name, type: String
|
20
23
|
|
21
|
-
embedded_in :addressable, polymorphic: true
|
24
|
+
# embedded_in :addressable, polymorphic: true
|
25
|
+
belongs_to :addressable, polymorphic: true
|
22
26
|
|
23
27
|
belongs_to :nation
|
24
28
|
belongs_to :region
|
25
29
|
belongs_to :city
|
26
30
|
belongs_to :hood
|
27
31
|
|
28
|
-
validates :
|
32
|
+
validates :title, presence: true
|
33
|
+
|
34
|
+
before_save :set_caches
|
35
|
+
|
36
|
+
def set_caches
|
37
|
+
self.city_name ||= city.name if city
|
38
|
+
self.nation_name ||= nation.name if nation
|
39
|
+
end
|
29
40
|
|
30
41
|
def print_location
|
31
42
|
"#{hood_name} #{city_name} - #{region_name} "
|
@@ -59,7 +70,7 @@ class Address
|
|
59
70
|
def to_s
|
60
71
|
"#{name} #{number}" + print_location
|
61
72
|
end
|
62
|
-
#index tie_id: 1, created_at: -1
|
73
|
+
# index tie_id: 1, created_at: -1
|
63
74
|
# symbolize :kind, :in => [:street, :avenue, :road], default: :street
|
64
75
|
|
65
76
|
end
|
data/app/models/city.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
#
|
2
|
+
# Cities
|
3
|
+
#
|
1
4
|
class City
|
2
5
|
include Mongoid::Document
|
3
6
|
include Mongoid::Geospatial
|
@@ -7,10 +10,10 @@ class City
|
|
7
10
|
field :zip, type: String
|
8
11
|
field :slug, type: String
|
9
12
|
field :name, type: String, localize: true
|
13
|
+
field :ascii, type: String
|
10
14
|
field :area, type: Integer
|
11
15
|
field :souls, type: Integer
|
12
|
-
field :geom, type: Point,
|
13
|
-
# field :ascii, type: String
|
16
|
+
field :geom, type: Point, spatial: true
|
14
17
|
|
15
18
|
spatial_scope :geom
|
16
19
|
|
@@ -20,34 +23,32 @@ class City
|
|
20
23
|
belongs_to :nation
|
21
24
|
has_many :hoods
|
22
25
|
|
23
|
-
|
24
26
|
index name: 1
|
25
27
|
|
26
28
|
scope :ordered, order_by(name: 1)
|
27
29
|
|
28
30
|
validates :slug, presence: true, uniqueness: true
|
29
|
-
validates :name, uniqueness: {
|
31
|
+
validates :name, uniqueness: { scope: :region_id }
|
30
32
|
|
31
33
|
# scope :close_to, GeoHelper::CLOSE
|
32
34
|
|
33
35
|
before_validation :set_defaults
|
34
36
|
|
35
|
-
|
36
37
|
def set_defaults
|
37
38
|
self.nation ||= region.try(:nation)
|
38
39
|
end
|
39
40
|
|
40
41
|
def abbr
|
42
|
+
return unless region || nation
|
41
43
|
region ? region.abbr : nation.abbr
|
42
44
|
end
|
43
45
|
|
44
|
-
def self.search
|
46
|
+
def self.search(txt)
|
45
47
|
where(slug: /#{txt}/i)
|
46
48
|
end
|
47
49
|
|
48
|
-
def <=>
|
49
|
-
|
50
|
+
def <=>(other)
|
51
|
+
slug <=> other.slug
|
50
52
|
end
|
51
53
|
|
52
|
-
|
53
54
|
end
|
data/app/models/hood.rb
CHANGED
data/app/models/nation.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
#
|
2
|
+
# Nation/Country/Flag
|
3
|
+
#
|
1
4
|
class Nation
|
2
5
|
include Mongoid::Document
|
3
6
|
include Geopolitical::Helpers
|
4
7
|
|
8
|
+
field :_id, type: String, default: ->{ abbr }
|
9
|
+
|
5
10
|
field :gid, type: Integer # geonames id
|
6
11
|
field :slug, type: String
|
7
12
|
field :name, type: String, localize: true
|
@@ -11,8 +16,8 @@ class Nation
|
|
11
16
|
field :cash, type: String
|
12
17
|
field :lang, type: String
|
13
18
|
|
14
|
-
has_many :regions, :
|
15
|
-
has_many :cities,
|
19
|
+
has_many :regions, dependent: :destroy
|
20
|
+
has_many :cities, dependent: :destroy
|
16
21
|
|
17
22
|
scope :ordered, order_by(name: 1)
|
18
23
|
|
@@ -20,5 +25,4 @@ class Nation
|
|
20
25
|
|
21
26
|
alias :currency :cash
|
22
27
|
|
23
|
-
|
24
28
|
end
|
data/app/models/region.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
#
|
2
|
+
# Region/Province/Estado
|
3
|
+
#
|
1
4
|
class Region
|
2
5
|
include Mongoid::Document
|
3
6
|
include Geopolitical::Helpers
|
@@ -10,13 +13,11 @@ class Region
|
|
10
13
|
|
11
14
|
belongs_to :nation
|
12
15
|
|
13
|
-
has_many :cities,
|
16
|
+
has_many :cities, dependent: :destroy
|
14
17
|
|
15
18
|
scope :ordered, order_by(name: 1)
|
16
19
|
|
17
20
|
validates :nation, presence: true
|
18
|
-
validates :name, presence: true, uniqueness: { :
|
19
|
-
|
20
|
-
|
21
|
+
validates :name, presence: true, uniqueness: { scope: :nation_id }
|
21
22
|
|
22
23
|
end
|
data/app/models/zone.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
#
|
2
|
+
# User created zones
|
1
3
|
class Zone
|
2
4
|
include Mongoid::Document
|
3
5
|
|
@@ -7,13 +9,12 @@ class Zone
|
|
7
9
|
field :abbr, type: String
|
8
10
|
field :kind, type: String
|
9
11
|
|
10
|
-
has_many :zone_members, :
|
12
|
+
has_many :zone_members, dependent: :destroy
|
11
13
|
|
12
14
|
scope :ordered, order_by(name: 1)
|
13
15
|
|
14
16
|
validates :name, presence: true, uniqueness: true
|
15
17
|
|
16
|
-
|
17
18
|
def members
|
18
19
|
zone_members.map(&:member)
|
19
20
|
end
|
data/app/models/zone_member.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
=# vjs 'cep'
|
2
|
+
%fieldset.address
|
3
|
+
.row.pull-right= f.link_to_remove "×".html_safe, :class => "close"
|
4
|
+
.row
|
5
|
+
-# .col-sm-3= f.select :kind, Address.get_kind_values, {}, :class => "input-auto"
|
6
|
+
.col-sm-12= ftext f, :title, :placeholder => "Nome"
|
7
|
+
|
8
|
+
.row
|
9
|
+
-# .col-sm-3= f.select :kind, Address.get_kind_values, {}, :class => "input-auto"
|
10
|
+
.col-sm-8= ftext f, :name, :placeholder => "Nome da Rua, Av...", :class => "street-field col-sm-12"
|
11
|
+
.col-sm-2= ftext f, :number, :class => "", :placeholder => "Num"
|
12
|
+
.col-sm-2= ftext f, :zip, :placeholder => "CEP", :class => "cep"
|
13
|
+
.row
|
14
|
+
.col-sm-4= ftext f, :city_name, :class => "city-field"
|
15
|
+
.col-sm-4= ftext f, :hood_name, :placeholder => "Bairro", :class => "input-small col-sm-12"
|
16
|
+
.col-sm-4= ftext f, :info, :placeholder => "Extra" #, :class => "col-sm-12"
|
17
|
+
%hr
|
data/config/routes.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#Rails.application.routes.draw
|
1
|
+
# Rails.application.routes.draw
|
2
2
|
Geopolitical::Engine.routes.draw do
|
3
3
|
resources :zones
|
4
4
|
resources :hoods
|
@@ -8,5 +8,5 @@ Geopolitical::Engine.routes.draw do
|
|
8
8
|
|
9
9
|
resource :geopolitical
|
10
10
|
|
11
|
-
root :
|
11
|
+
root to: 'geopolitical#index'
|
12
12
|
end
|
data/lib/geopolitical.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'mongoid'
|
2
|
+
require 'mongoid_geospatial'
|
3
|
+
require 'geopolitical/engine'
|
4
|
+
require 'geopolitical/helpers'
|
5
5
|
|
6
|
+
#
|
7
|
+
# Geopolitical
|
8
|
+
#
|
9
|
+
# Nations, Regions, Cities...
|
10
|
+
#
|
11
|
+
#
|
6
12
|
module Geopolitical
|
7
|
-
|
8
13
|
end
|