br_railties 0.5.0 → 0.6.1
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/Gemfile +4 -2
- data/app/assets/javascripts/br_railties.js +0 -1
- data/app/assets/stylesheets/br_railties.scss +0 -1
- data/app/validators/br_railties/cnpj_validator.rb +17 -0
- data/app/validators/br_railties/cpf_cnpj_validator.rb +21 -0
- data/app/validators/br_railties/cpf_validator.rb +17 -0
- data/config/routes.rb +1 -3
- data/lib/br_railties/engine.rb +2 -7
- data/lib/br_railties/version.rb +1 -1
- data/lib/br_railties.rb +2 -6
- metadata +26 -56
- data/app/controllers/br_railties/federal_units_controller.rb +0 -8
- data/app/controllers/br_railties/municipalities_controller.rb +0 -15
- data/app/models/br_railties/federal_unit.rb +0 -13
- data/app/models/br_railties/municipality.rb +0 -11
- data/app/models/br_railties.rb +0 -7
- data/config/initializers/menus.rb +0 -6
- data/db/migrate/20190218210506_create_br_railties_federal_units.rb +0 -14
- data/db/migrate/20190221200607_create_br_railties_municipalities.rb +0 -17
- data/db/migrate/20190226015936_add_ibge_code_to_br_railties_federal_units.rb +0 -9
- data/db/migrate/20190227152340_add_ibge_code_to_br_railties_municipalities.rb +0 -9
- data/lib/br_railties/ibge/import/federal_units.rb +0 -43
- data/lib/br_railties/ibge/import/municipalities.rb +0 -51
- data/lib/tasks/br_railties.rake +0 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4d55012a279697a0e55ba95a77ca853069984a6bc9c30802a393f7df6c60a89f
|
|
4
|
+
data.tar.gz: 1eb423594e9ed3f1d89f3b3f6f210ca18828be61d63f906705bef2b8e505d5a1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: acee113d426546195f786a8ee4400976a68649cd0829fab1658d2123eda4ab0e435d8b8d60b9282422f736a832ebc78cdaa9119fc285c44f3cc2c567e9b24f9d
|
|
7
|
+
data.tar.gz: b98acd667a888e83d358591e527b4d4621da39f777233a57e995594c27f1f8fe40f6562496049c30754db3bc38f48cf58c1a973e53c147b0231dab1644f883ef
|
data/Gemfile
CHANGED
|
@@ -4,5 +4,7 @@ source 'https://rubygems.org'
|
|
|
4
4
|
|
|
5
5
|
gemspec
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
gem 'rails', '>= 6.1.7.10', '< 7'
|
|
8
|
+
|
|
9
|
+
local_gemfile = File.join(File.dirname(__FILE__), 'Gemfile.local')
|
|
10
|
+
eval_gemfile local_gemfile if File.exist?(local_gemfile)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//= require eac_active_scaffold
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
@import 'eac_active_scaffold';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'cnpj'
|
|
4
|
+
|
|
5
|
+
module BrRailties
|
|
6
|
+
class CnpjValidator < ActiveModel::EachValidator
|
|
7
|
+
def validate_each(record, attribute, value)
|
|
8
|
+
cnpj = ::CNPJ.new(value)
|
|
9
|
+
return if cnpj.valid? && value == cnpj.stripped
|
|
10
|
+
|
|
11
|
+
record.errors.add(
|
|
12
|
+
attribute,
|
|
13
|
+
options[:message] || 'CNPJ inválido (14 caracteres, somente dígitos)'
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'cnpj'
|
|
4
|
+
require 'cpf'
|
|
5
|
+
|
|
6
|
+
module BrRailties
|
|
7
|
+
class CpfCnpjValidator < ActiveModel::EachValidator
|
|
8
|
+
def validate_each(record, attribute, value)
|
|
9
|
+
cpf = ::CPF.new(value)
|
|
10
|
+
return if cpf.valid? && value == cpf.stripped
|
|
11
|
+
|
|
12
|
+
cnpj = ::CNPJ.new(value)
|
|
13
|
+
return if cnpj.valid? && value == cnpj.stripped
|
|
14
|
+
|
|
15
|
+
record.errors.add(
|
|
16
|
+
attribute,
|
|
17
|
+
options[:message] || 'CPF/CNPJ inválido (9 ou 14 caracteres, somente dígitos)'
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'cpf'
|
|
4
|
+
|
|
5
|
+
module BrRailties
|
|
6
|
+
class CpfValidator < ActiveModel::EachValidator
|
|
7
|
+
def validate_each(record, attribute, value)
|
|
8
|
+
cpf = ::CPF.new(value)
|
|
9
|
+
return if cpf.valid? && value == cpf.stripped
|
|
10
|
+
|
|
11
|
+
record.errors.add(
|
|
12
|
+
attribute,
|
|
13
|
+
options[:message] || 'CPF inválido (9 caracteres, somente dígitos)'
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/config/routes.rb
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
BrRailties::Engine.routes.draw do
|
|
4
|
-
resources(:federal_units, concerns: active_scaffold)
|
|
5
|
-
resources(:municipalities, concerns: active_scaffold) { record_select_routes }
|
|
3
|
+
BrRailties::Engine.routes.draw do # rubocop:disable Lint/EmptyBlock
|
|
6
4
|
end
|
data/lib/br_railties/engine.rb
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require '
|
|
3
|
+
require 'eac_rails_utils'
|
|
4
4
|
|
|
5
5
|
module BrRailties
|
|
6
6
|
class Engine < ::Rails::Engine
|
|
7
7
|
isolate_namespace BrRailties
|
|
8
|
-
|
|
9
|
-
initializer :append_migrations do |app|
|
|
10
|
-
config.paths['db/migrate'].expanded.each do |expanded_path|
|
|
11
|
-
app.config.paths['db/migrate'] << expanded_path
|
|
12
|
-
end
|
|
13
|
-
end
|
|
8
|
+
include ::EacRailsUtils::EngineHelper
|
|
14
9
|
end
|
|
15
10
|
end
|
data/lib/br_railties/version.rb
CHANGED
data/lib/br_railties.rb
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'recordselect'
|
|
4
|
-
|
|
5
|
-
require 'br_railties/engine'
|
|
6
|
-
require 'br_railties/ibge/import/federal_units'
|
|
7
|
-
require 'br_railties/ibge/import/municipalities'
|
|
8
|
-
|
|
9
3
|
module BrRailties
|
|
10
4
|
def self.table_name_prefix
|
|
11
5
|
'br_railties_'
|
|
12
6
|
end
|
|
13
7
|
end
|
|
8
|
+
|
|
9
|
+
require 'br_railties/engine'
|
metadata
CHANGED
|
@@ -1,91 +1,71 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: br_railties
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Esquilo Azul Company
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-07-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: cpf_cnpj
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
20
|
-
- - ">="
|
|
21
|
-
- !ruby/object:Gem::Version
|
|
22
|
-
version: 0.5.1
|
|
19
|
+
version: '1.1'
|
|
23
20
|
type: :runtime
|
|
24
21
|
prerelease: false
|
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
23
|
requirements:
|
|
27
24
|
- - "~>"
|
|
28
25
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: '
|
|
30
|
-
- - ">="
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: 0.5.1
|
|
26
|
+
version: '1.1'
|
|
33
27
|
- !ruby/object:Gem::Dependency
|
|
34
|
-
name:
|
|
28
|
+
name: eac_rails_utils
|
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
|
36
30
|
requirements:
|
|
37
31
|
- - "~>"
|
|
38
32
|
- !ruby/object:Gem::Version
|
|
39
|
-
version:
|
|
33
|
+
version: '0.28'
|
|
40
34
|
- - ">="
|
|
41
35
|
- !ruby/object:Gem::Version
|
|
42
|
-
version:
|
|
36
|
+
version: 0.28.1
|
|
43
37
|
type: :runtime
|
|
44
38
|
prerelease: false
|
|
45
39
|
version_requirements: !ruby/object:Gem::Requirement
|
|
46
40
|
requirements:
|
|
47
41
|
- - "~>"
|
|
48
42
|
- !ruby/object:Gem::Version
|
|
49
|
-
version:
|
|
43
|
+
version: '0.28'
|
|
50
44
|
- - ">="
|
|
51
45
|
- !ruby/object:Gem::Version
|
|
52
|
-
version:
|
|
46
|
+
version: 0.28.1
|
|
53
47
|
- !ruby/object:Gem::Dependency
|
|
54
|
-
name:
|
|
48
|
+
name: eac_rails_gem_support
|
|
55
49
|
requirement: !ruby/object:Gem::Requirement
|
|
56
50
|
requirements:
|
|
57
51
|
- - "~>"
|
|
58
52
|
- !ruby/object:Gem::Version
|
|
59
|
-
version: '
|
|
53
|
+
version: '0.12'
|
|
60
54
|
- - ">="
|
|
61
55
|
- !ruby/object:Gem::Version
|
|
62
|
-
version:
|
|
63
|
-
type: :
|
|
56
|
+
version: 0.12.2
|
|
57
|
+
type: :development
|
|
64
58
|
prerelease: false
|
|
65
59
|
version_requirements: !ruby/object:Gem::Requirement
|
|
66
60
|
requirements:
|
|
67
61
|
- - "~>"
|
|
68
62
|
- !ruby/object:Gem::Version
|
|
69
|
-
version: '
|
|
63
|
+
version: '0.12'
|
|
70
64
|
- - ">="
|
|
71
65
|
- !ruby/object:Gem::Version
|
|
72
|
-
version:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
requirement: !ruby/object:Gem::Requirement
|
|
76
|
-
requirements:
|
|
77
|
-
- - "~>"
|
|
78
|
-
- !ruby/object:Gem::Version
|
|
79
|
-
version: 0.7.2
|
|
80
|
-
type: :development
|
|
81
|
-
prerelease: false
|
|
82
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
83
|
-
requirements:
|
|
84
|
-
- - "~>"
|
|
85
|
-
- !ruby/object:Gem::Version
|
|
86
|
-
version: 0.7.2
|
|
87
|
-
description:
|
|
88
|
-
email:
|
|
66
|
+
version: 0.12.2
|
|
67
|
+
description:
|
|
68
|
+
email:
|
|
89
69
|
executables: []
|
|
90
70
|
extensions: []
|
|
91
71
|
extra_rdoc_files: []
|
|
@@ -94,31 +74,21 @@ files:
|
|
|
94
74
|
- README.rdoc
|
|
95
75
|
- app/assets/javascripts/br_railties.js
|
|
96
76
|
- app/assets/stylesheets/br_railties.scss
|
|
97
|
-
- app/
|
|
98
|
-
- app/
|
|
99
|
-
- app/
|
|
100
|
-
- app/models/br_railties/federal_unit.rb
|
|
101
|
-
- app/models/br_railties/municipality.rb
|
|
102
|
-
- config/initializers/menus.rb
|
|
77
|
+
- app/validators/br_railties/cnpj_validator.rb
|
|
78
|
+
- app/validators/br_railties/cpf_cnpj_validator.rb
|
|
79
|
+
- app/validators/br_railties/cpf_validator.rb
|
|
103
80
|
- config/locales/en.yml
|
|
104
81
|
- config/locales/pt-BR.yml
|
|
105
82
|
- config/routes.rb
|
|
106
|
-
- db/migrate/20190218210506_create_br_railties_federal_units.rb
|
|
107
|
-
- db/migrate/20190221200607_create_br_railties_municipalities.rb
|
|
108
|
-
- db/migrate/20190226015936_add_ibge_code_to_br_railties_federal_units.rb
|
|
109
|
-
- db/migrate/20190227152340_add_ibge_code_to_br_railties_municipalities.rb
|
|
110
83
|
- lib/br_railties.rb
|
|
111
84
|
- lib/br_railties/engine.rb
|
|
112
|
-
- lib/br_railties/ibge/import/federal_units.rb
|
|
113
|
-
- lib/br_railties/ibge/import/municipalities.rb
|
|
114
85
|
- lib/br_railties/version.rb
|
|
115
|
-
- lib/tasks/br_railties.rake
|
|
116
86
|
homepage: https://github.com/esquilo-azul/br_railties
|
|
117
87
|
licenses:
|
|
118
88
|
- MIT
|
|
119
89
|
metadata:
|
|
120
90
|
source_code_uri: https://github.com/esquilo-azul/br_railties
|
|
121
|
-
post_install_message:
|
|
91
|
+
post_install_message:
|
|
122
92
|
rdoc_options: []
|
|
123
93
|
require_paths:
|
|
124
94
|
- lib
|
|
@@ -126,15 +96,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
126
96
|
requirements:
|
|
127
97
|
- - ">="
|
|
128
98
|
- !ruby/object:Gem::Version
|
|
129
|
-
version: '
|
|
99
|
+
version: '3.2'
|
|
130
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
101
|
requirements:
|
|
132
102
|
- - ">="
|
|
133
103
|
- !ruby/object:Gem::Version
|
|
134
104
|
version: '0'
|
|
135
105
|
requirements: []
|
|
136
|
-
rubygems_version: 3.
|
|
137
|
-
signing_key:
|
|
106
|
+
rubygems_version: 3.4.19
|
|
107
|
+
signing_key:
|
|
138
108
|
specification_version: 4
|
|
139
109
|
summary: Brazilian resources for Rails.
|
|
140
110
|
test_files: []
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module BrRailties
|
|
4
|
-
class MunicipalitiesController < ApplicationController
|
|
5
|
-
record_select per_page: 10,
|
|
6
|
-
search_on: [:name],
|
|
7
|
-
order_by: 'name ASC',
|
|
8
|
-
model: ::BrRailties::Municipality,
|
|
9
|
-
full_text_search: true
|
|
10
|
-
|
|
11
|
-
active_scaffold :"br_railties/municipality" do |conf|
|
|
12
|
-
conf.columns[:federal_unit].form_ui = :select
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module BrRailties
|
|
4
|
-
class FederalUnit < ActiveRecord::Base
|
|
5
|
-
validates :acronym, presence: true, uniqueness: { case_sensitive: false }, length: { in: 2..2 }
|
|
6
|
-
validates :name, presence: true, uniqueness: { case_sensitive: false }
|
|
7
|
-
validates :ibge_code, presence: true, uniqueness: true, numericality: { greater_than: 0 }
|
|
8
|
-
|
|
9
|
-
def acronym=(value)
|
|
10
|
-
self[:acronym] = value.to_s.upcase
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module BrRailties
|
|
4
|
-
class Municipality < ActiveRecord::Base
|
|
5
|
-
belongs_to :federal_unit, class_name: 'BrRailties::FederalUnit'
|
|
6
|
-
|
|
7
|
-
validates :federal_unit, presence: true
|
|
8
|
-
validates :name, presence: true, uniqueness: { case_sensitive: false, scope: [:federal_unit] }
|
|
9
|
-
validates :ibge_code, presence: true, uniqueness: true, numericality: { greater_than: 0 }
|
|
10
|
-
end
|
|
11
|
-
end
|
data/app/models/br_railties.rb
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
::Rails.application.root_menu.group(:admin).group(:br_railties, :br_railties).within do |g|
|
|
4
|
-
g.action(:federal_units).label(-> { ::BrRailties::FederalUnit.plural_name })
|
|
5
|
-
g.action(:municipalities).label(-> { ::BrRailties::Municipality.plural_name })
|
|
6
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class CreateBrRailtiesFederalUnits < (
|
|
4
|
-
Rails.version < '5' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
|
|
5
|
-
)
|
|
6
|
-
def change
|
|
7
|
-
create_table :br_railties_federal_units do |t|
|
|
8
|
-
t.string :acronym
|
|
9
|
-
t.string :name
|
|
10
|
-
|
|
11
|
-
t.timestamps null: false
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
class CreateBrRailtiesMunicipalities < (
|
|
4
|
-
Rails.version < '5' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
|
|
5
|
-
)
|
|
6
|
-
def change
|
|
7
|
-
create_table :br_railties_municipalities do |t|
|
|
8
|
-
t.string :name
|
|
9
|
-
t.references :federal_unit, index: true
|
|
10
|
-
|
|
11
|
-
t.timestamps null: false
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
add_foreign_key :br_railties_municipalities, :br_railties_federal_units,
|
|
15
|
-
column: :federal_unit_id
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'json'
|
|
4
|
-
|
|
5
|
-
module BrRailties
|
|
6
|
-
module Ibge
|
|
7
|
-
module Import
|
|
8
|
-
class FederalUnits
|
|
9
|
-
SOURCE_URL = 'https://servicodados.ibge.gov.br/api/v1/localidades/estados'
|
|
10
|
-
|
|
11
|
-
def initialize
|
|
12
|
-
run
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
def run
|
|
18
|
-
source_data.each do |fu_source_data|
|
|
19
|
-
import(fu_source_data.except('regiao'))
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def source_data
|
|
24
|
-
JSON.parse(Net::HTTP.get(URI.parse(SOURCE_URL)))
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def import(raw)
|
|
28
|
-
data = { acronym: raw['sigla'], name: raw['nome'], ibge_code: raw['id'] }
|
|
29
|
-
record = record_by_data(data)
|
|
30
|
-
record.attributes = data
|
|
31
|
-
::Rails.logger.info("Importing: #{record.attributes}")
|
|
32
|
-
record.save!
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def record_by_data(data)
|
|
36
|
-
::BrRailties::FederalUnit.find_by(ibge_code: data[:ibge_code]) ||
|
|
37
|
-
::BrRailties::FederalUnit.find_by(acronym: data[:acronym]) ||
|
|
38
|
-
::BrRailties::FederalUnit.new
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'json'
|
|
4
|
-
|
|
5
|
-
module BrRailties
|
|
6
|
-
module Ibge
|
|
7
|
-
module Import
|
|
8
|
-
class Municipalities
|
|
9
|
-
SOURCE_URL = 'https://servicodados.ibge.gov.br/api/v1/localidades/municipios'
|
|
10
|
-
|
|
11
|
-
def initialize
|
|
12
|
-
run
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
def run
|
|
18
|
-
source_data.each do |municipality_source_data|
|
|
19
|
-
import(municipality_source_data)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def source_data
|
|
24
|
-
JSON.parse(Net::HTTP.get(URI.parse(SOURCE_URL)))
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def import(raw)
|
|
28
|
-
data = { federal_unit: find_federal_unit(raw), name: raw['nome'], ibge_code: raw['id'] }
|
|
29
|
-
record = record_by_data(data)
|
|
30
|
-
record.attributes = data
|
|
31
|
-
::Rails.logger.info("Importing: #{record.attributes}")
|
|
32
|
-
record.save!
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def find_federal_unit(raw)
|
|
36
|
-
raw = raw['microrregiao']['mesorregiao']['UF']
|
|
37
|
-
::BrRailties::FederalUnit.find_by(ibge_code: raw['id']) ||
|
|
38
|
-
::BrRailties::FederalUnit.find_by(acronym: raw['sigla']) ||
|
|
39
|
-
raise("Federal unit not found (Raw data: #{raw})")
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def record_by_data(data)
|
|
43
|
-
::BrRailties::Municipality.find_by(ibge_code: data[:ibge_code]) ||
|
|
44
|
-
::BrRailties::Municipality.find_by(name: data[:name],
|
|
45
|
-
federal_unit: data[:federal_unit]) ||
|
|
46
|
-
::BrRailties::Municipality.new
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
data/lib/tasks/br_railties.rake
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
namespace :br_railties do
|
|
4
|
-
namespace :ibge do
|
|
5
|
-
namespace :import do
|
|
6
|
-
desc 'Importa unidades federativas do cadastro do IBGE.'
|
|
7
|
-
task federal_units: :environment do |_t, _args|
|
|
8
|
-
::BrRailties::Ibge::Import::FederalUnits.new
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
desc 'Importa municípios do cadastro do IBGE.'
|
|
12
|
-
task municipalities: :environment do |_t, _args|
|
|
13
|
-
::BrRailties::Ibge::Import::Municipalities.new
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|