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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ae69743123ec41332c4656f13ba7083fd3130851f120397263ff9c403c428c1
4
- data.tar.gz: fa747d78c39bb61ddf084449cbfd9e80f28b9bc0346285a734ce8b54c896aecb
3
+ metadata.gz: 726ec8e459c19ecf192b6beced6443fd6d842db3a033bc6970ec1e132d029d32
4
+ data.tar.gz: 61a4fea346dcd9eaaca4926274d9af8f941e7236ca60876a132b6cea266486a0
5
5
  SHA512:
6
- metadata.gz: 717e2a3a6a7d8c1c1cfba426efe2a899ce69ba84a6f1cd6a12bc96e284c5c1dacd337723bad406a0d65fb4221e3e15e62345ae3c1cf67a6fce83161d70bdcb3b
7
- data.tar.gz: 45216fc9dfb504783106497bcd57839fc955cc14babadf2e78a7364a295f1933e0b465734e8833c76dd529dbf3680c89db6be71e91f6610e8b8356bbe3f9e205
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
@@ -1,6 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  BrRailties::Engine.routes.draw do
4
- resources(:federal_units, concerns: active_scaffold)
5
- resources(:municipalities, concerns: active_scaffold) { record_select_routes }
6
4
  end
@@ -1,15 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_active_scaffold'
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BrRailties
4
- VERSION = '0.5.0'
4
+ VERSION = '0.6.0'
5
5
  end
data/lib/br_railties.rb CHANGED
@@ -1,10 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'recordselect'
4
-
5
3
  require 'br_railties/engine'
6
- require 'br_railties/ibge/import/federal_units'
7
- require 'br_railties/ibge/import/municipalities'
8
4
 
9
5
  module BrRailties
10
6
  def self.table_name_prefix
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.5.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: 2023-09-18 00:00:00.000000000 Z
11
+ date: 2024-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: eac_active_scaffold
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.5.1
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.5.1
26
+ version: '0'
33
27
  - !ruby/object:Gem::Dependency
34
- name: railties
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: 6.1.7
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: 6.1.7
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 6.1.7.6
40
+ version: '0.24'
53
41
  - !ruby/object:Gem::Dependency
54
- name: recordselect
42
+ name: railties
55
43
  requirement: !ruby/object:Gem::Requirement
56
44
  requirements:
57
45
  - - "~>"
58
46
  - !ruby/object:Gem::Version
59
- version: '3.10'
47
+ version: 6.1.7
60
48
  - - ">="
61
49
  - !ruby/object:Gem::Version
62
- version: 3.10.4
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: '3.10'
57
+ version: 6.1.7
70
58
  - - ">="
71
59
  - !ruby/object:Gem::Version
72
- version: 3.10.4
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.7.2
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.7.2
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/controllers/br_railties/federal_units_controller.rb
98
- - app/controllers/br_railties/municipalities_controller.rb
99
- - app/models/br_railties.rb
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: '0'
113
+ version: '2.4'
130
114
  required_rubygems_version: !ruby/object:Gem::Requirement
131
115
  requirements:
132
116
  - - ">="
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BrRailties
4
- class FederalUnitsController < ApplicationController
5
- active_scaffold :"br_railties/federal_unit" do |conf|
6
- end
7
- end
8
- end
@@ -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
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BrRailties
4
- def self.table_name_prefix
5
- 'br_railties_'
6
- end
7
- end
@@ -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,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class AddIbgeCodeToBrRailtiesFederalUnits < (
4
- Rails.version < '5' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
5
- )
6
- def change
7
- add_column :br_railties_federal_units, :ibge_code, :integer
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class AddIbgeCodeToBrRailtiesMunicipalities < (
4
- Rails.version < '5' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
5
- )
6
- def change
7
- add_column :br_railties_municipalities, :ibge_code, :integer
8
- end
9
- 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
@@ -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