geopolitical 1.0.2 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fef1dedddcdd21d6255957be49ef4e19bc24383d
4
- data.tar.gz: 289ec378f7e4eb945f237139a5a98115a4472b45
3
+ metadata.gz: 3e5f18cc9f1bcf0dc111ab2545a439e13982cb6b
4
+ data.tar.gz: 1b9139b45fb6091fa6b0f50435507829d94dc5d1
5
5
  SHA512:
6
- metadata.gz: a559223be651d74a7bcdce4361f2ff776955ae0e2c4dab57d80036ddfe8e7289139d4ff31f7a29fb53d6a2c5b27c9d57ab2d085a471773293bbf687a10b78e7d
7
- data.tar.gz: 069865af512ce7c3f060feea9c79fbf8d7c5d3be697a0c690a3f3ae43cfe0d114aa7b0a805d7e13157f7a7219fbb80bbb8fee0923aafca79c1dab2b3b7288978
6
+ metadata.gz: 3a40d4e8c3284d3de08d7997311807e2ae7dd8f53aebf491701a0e9944c96a4240a8d33fe1b8251b69941f2eb39816d99ff283c76edeec5b24454a6bf74e242d
7
+ data.tar.gz: e9cb615e832174edf67b2949f55b768af7eba05c1d05275037dd757312fa2c7bd3197b31865f747b3775225e7971571a531fc0e6870bfae4a79eac68e9effe98
data/Gemfile CHANGED
@@ -4,7 +4,6 @@ gem 'mongoid', '>= 5.0.0.beta'
4
4
 
5
5
  gemspec
6
6
 
7
-
8
7
  gem 'rails'
9
8
  gem 'faker'
10
9
  gem 'fabrication'
data/Guardfile CHANGED
@@ -13,8 +13,8 @@ guard :rspec, cmd: 'bundle exec rspec' do
13
13
  watch(/^spec\/spec_helper\.rb$/) { 'spec' }
14
14
  watch(/^app\/(.+)\.rb$/) { |m| "spec/#{m[1]}_spec.rb" }
15
15
  watch(/^lib\/(.+)\.rb$/) { |m| "spec/lib/#{m[1]}_spec.rb" }
16
- watch(%r{^app/models/concerns/(.+)\.rb$}) { |m| "spec/models/*._spec.rb" }
17
- watch(%r{^app/controllers/(.+)_(controller)\.rb$}) do |m|
16
+ watch(%r{^app/models/concerns/(.+)\.rb$}) { |_m| 'spec/models/*._spec.rb' }
17
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) do |m|
18
18
  [
19
19
  "spec/routing/#{m[1]}_routing_spec.rb",
20
20
  "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
@@ -1,7 +1,6 @@
1
1
  module Geopolitical
2
2
  # Nations Public Controller
3
3
  class NationsController < GeopoliticalController
4
-
5
4
  def collection
6
5
  @nations = Nation.ordered
7
6
  end
data/app/models/city.rb CHANGED
@@ -6,8 +6,8 @@ class City
6
6
  include Mongoid::Geospatial
7
7
  include Geopolitocracy
8
8
 
9
- field :area, type: Integer # m2 square area
10
- field :geom, type: Point, spatial: true
9
+ field :area, type: Integer # m2 square area
10
+ field :geom, type: Point, spatial: true
11
11
  # field :capital, type: String
12
12
 
13
13
  spatial_scope :geom
@@ -43,7 +43,7 @@ class City
43
43
  return unless City.where(slug: slug).first
44
44
  self.slug += "-#{region.abbr}"
45
45
  return unless City.where(slug: slug).first
46
- fail "Two cities with the same name in #{region}: '#{slug}'"
46
+ raise "Two cities with the same name in #{region}: '#{slug}'"
47
47
  end
48
48
 
49
49
  def phone
@@ -5,15 +5,15 @@ module Geopolitocracy
5
5
  included do
6
6
  # field :gid, type: Integer # geonames id
7
7
 
8
- field :name, type: String, localize: true
9
- field :abbr, type: String
10
- field :nick, type: String
8
+ field :name, type: String, localize: true
9
+ field :abbr, type: String
10
+ field :nick, type: String
11
11
 
12
- field :souls, type: Integer # Population
12
+ field :souls, type: Fixnum # Population
13
13
 
14
- field :ascii, type: String
15
- field :code, type: String
16
- field :slug, type: String # , default: -> { name }
14
+ field :ascii, type: String
15
+ field :code, type: String
16
+ field :slug, type: String # , default: -> { name }
17
17
 
18
18
  field :postal, type: String # , default: -> { name }
19
19
  field :phone, type: String # , default: -> { name }
@@ -32,24 +32,29 @@ module Geopolitocracy
32
32
 
33
33
  scope :ordered, -> { order_by(name: 1) }
34
34
 
35
+ def ensure_slug
36
+ self.slug ||= name
37
+ end
38
+
39
+ def name=(txt)
40
+ txt = txt.titleize unless txt =~ /[A-Z][a-z]/
41
+ super txt
42
+ end
43
+
44
+ def slug=(txt)
45
+ return unless txt
46
+ self[:slug] = ActiveSupport::Inflector
47
+ .transliterate(txt).delete('.').gsub(/\W/, '-').downcase
48
+ end
49
+
50
+ def to_s
51
+ name || slug
52
+ end
53
+
35
54
  def self.search(txt, lazy = false)
36
55
  key = ActiveSupport::Inflector.transliterate(txt).gsub(/\W/, '-')
37
56
  char = lazy ? nil : '$'
38
57
  where(slug: /^#{key}#{char}/i)
39
58
  end
40
59
  end
41
-
42
- def ensure_slug
43
- self.slug ||= name
44
- end
45
-
46
- def slug=(txt)
47
- return unless txt
48
- self[:slug] = ActiveSupport::Inflector.transliterate(txt)
49
- .gsub(/\W/, '-').downcase
50
- end
51
-
52
- def to_s
53
- name || slug
54
- end
55
60
  end
data/app/models/hood.rb CHANGED
@@ -12,6 +12,11 @@ class Hood
12
12
  validates :city, presence: true
13
13
  validates :name, uniqueness: { scope: :city_id }
14
14
 
15
+ def ensure_slug
16
+ return unless city
17
+ self.slug ||= "#{city.slug}-#{name}"
18
+ end
19
+
15
20
  def phone
16
21
  self[:phone] || city.phone
17
22
  end
data/app/models/nation.rb CHANGED
@@ -14,8 +14,8 @@ class Nation
14
14
  field :lang, type: String # Official/main language
15
15
  field :langs, type: Array # All official languages
16
16
 
17
- alias_method :currency, :cash
18
- alias_method :iso_3166_3, :code3
17
+ alias currency cash
18
+ alias iso_3166_3 code3
19
19
 
20
20
  validates :abbr, uniqueness: true, presence: true
21
21
 
data/app/models/region.rb CHANGED
@@ -9,7 +9,7 @@ class Region
9
9
 
10
10
  belongs_to :nation
11
11
 
12
- has_many :cities, dependent: :destroy
12
+ has_many :cities, dependent: :destroy
13
13
 
14
14
  belongs_to :capital, inverse_of: :region_capital, class_name: 'City'
15
15
 
@@ -1,4 +1,4 @@
1
1
  # :nodoc:
2
2
  module Geopolitical
3
- VERSION = '1.0.2'
3
+ VERSION = '1.0.3'.freeze
4
4
  end
data/spec/dummy/bin/rails CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path('../../config/application', __FILE__)
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
3
  require_relative '../config/boot'
4
4
  require 'rails/commands'
@@ -13,7 +13,7 @@ Dummy::Application.configure do
13
13
  config.eager_load = false
14
14
 
15
15
  # Configure static asset server for tests with Cache-Control for performance.
16
- config.serve_static_files = true
16
+ config.serve_static_files = true
17
17
  config.static_cache_control = 'public, max-age=3600'
18
18
 
19
19
  # Show full error reports and disable caching.
data/spec/dummy/config.ru CHANGED
@@ -1,4 +1,4 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
4
  run Rails.application