br_railties 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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 +0 -2
- data/lib/br_railties/engine.rb +2 -7
- data/lib/br_railties/version.rb +1 -1
- data/lib/br_railties.rb +0 -4
- metadata +25 -41
- 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: 726ec8e459c19ecf192b6beced6443fd6d842db3a033bc6970ec1e132d029d32
|
4
|
+
data.tar.gz: 61a4fea346dcd9eaaca4926274d9af8f941e7236ca60876a132b6cea266486a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0b9f3f555e3cd8c2575060b459521c5a25a37d7fcbadebd793186ffdaec216d31524143bbfcaa16bc55819806982e8ce6a3289749b9b0e3f17ff14a10cb78b8
|
7
|
+
data.tar.gz: cc5708ff23884bb9fcb6c49610d818e2dbc6463b11060f5e43ea80f26bd118a350afddd355ba0dbbc8867fa4316cd6febf3978f19cc7b9fa11c7a744fb35fd33
|
@@ -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
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/engine_helper'
|
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
metadata
CHANGED
@@ -1,89 +1,83 @@
|
|
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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-05 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
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.5'
|
20
17
|
- - ">="
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0
|
19
|
+
version: '0'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0.5'
|
30
24
|
- - ">="
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0
|
26
|
+
version: '0'
|
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:
|
40
|
-
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: 6.1.7.6
|
33
|
+
version: '0.24'
|
43
34
|
type: :runtime
|
44
35
|
prerelease: false
|
45
36
|
version_requirements: !ruby/object:Gem::Requirement
|
46
37
|
requirements:
|
47
38
|
- - "~>"
|
48
39
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
50
|
-
- - ">="
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: 6.1.7.6
|
40
|
+
version: '0.24'
|
53
41
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
42
|
+
name: railties
|
55
43
|
requirement: !ruby/object:Gem::Requirement
|
56
44
|
requirements:
|
57
45
|
- - "~>"
|
58
46
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
47
|
+
version: 6.1.7
|
60
48
|
- - ">="
|
61
49
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
50
|
+
version: 6.1.7.8
|
63
51
|
type: :runtime
|
64
52
|
prerelease: false
|
65
53
|
version_requirements: !ruby/object:Gem::Requirement
|
66
54
|
requirements:
|
67
55
|
- - "~>"
|
68
56
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
57
|
+
version: 6.1.7
|
70
58
|
- - ">="
|
71
59
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
60
|
+
version: 6.1.7.8
|
73
61
|
- !ruby/object:Gem::Dependency
|
74
62
|
name: eac_rails_gem_support
|
75
63
|
requirement: !ruby/object:Gem::Requirement
|
76
64
|
requirements:
|
77
65
|
- - "~>"
|
78
66
|
- !ruby/object:Gem::Version
|
79
|
-
version: 0.
|
67
|
+
version: '0.10'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 0.10.1
|
80
71
|
type: :development
|
81
72
|
prerelease: false
|
82
73
|
version_requirements: !ruby/object:Gem::Requirement
|
83
74
|
requirements:
|
84
75
|
- - "~>"
|
85
76
|
- !ruby/object:Gem::Version
|
86
|
-
version: 0.
|
77
|
+
version: '0.10'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 0.10.1
|
87
81
|
description:
|
88
82
|
email:
|
89
83
|
executables: []
|
@@ -94,25 +88,15 @@ files:
|
|
94
88
|
- README.rdoc
|
95
89
|
- app/assets/javascripts/br_railties.js
|
96
90
|
- 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
|
91
|
+
- app/validators/br_railties/cnpj_validator.rb
|
92
|
+
- app/validators/br_railties/cpf_cnpj_validator.rb
|
93
|
+
- app/validators/br_railties/cpf_validator.rb
|
103
94
|
- config/locales/en.yml
|
104
95
|
- config/locales/pt-BR.yml
|
105
96
|
- 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
97
|
- lib/br_railties.rb
|
111
98
|
- lib/br_railties/engine.rb
|
112
|
-
- lib/br_railties/ibge/import/federal_units.rb
|
113
|
-
- lib/br_railties/ibge/import/municipalities.rb
|
114
99
|
- lib/br_railties/version.rb
|
115
|
-
- lib/tasks/br_railties.rake
|
116
100
|
homepage: https://github.com/esquilo-azul/br_railties
|
117
101
|
licenses:
|
118
102
|
- MIT
|
@@ -126,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
110
|
requirements:
|
127
111
|
- - ">="
|
128
112
|
- !ruby/object:Gem::Version
|
129
|
-
version: '
|
113
|
+
version: '2.4'
|
130
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
115
|
requirements:
|
132
116
|
- - ">="
|
@@ -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
|