unico-training 7.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +1 -0
- data/.rubocop.yml +13 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +35 -0
- data/Rakefile +43 -0
- data/app/business/material_code_generator.rb +43 -0
- data/app/business/similarity_control_adjuster.rb +2 -0
- data/app/business/similarity_control_checker.rb +2 -0
- data/app/business/unico/similarity_control_adjuster.rb +129 -0
- data/app/business/unico/similarity_control_checker.rb +96 -0
- data/app/controllers/agencies_controller.rb +2 -0
- data/app/controllers/bank_accounts_controller.rb +2 -0
- data/app/controllers/banks_controller.rb +2 -0
- data/app/controllers/creditors_controller.rb +2 -0
- data/app/controllers/document_types_controller.rb +2 -0
- data/app/controllers/material_classes_controller.rb +2 -0
- data/app/controllers/materials_controller.rb +2 -0
- data/app/controllers/reference_units_controller.rb +2 -0
- data/app/controllers/registration_cadastral_certificates_controller.rb +2 -0
- data/app/controllers/regularization_or_administrative_sanction_reasons_controller.rb +2 -0
- data/app/controllers/similarity_controls_controller.rb +2 -0
- data/app/controllers/unico/agencies_controller.rb +5 -0
- data/app/controllers/unico/bank_accounts_controller.rb +17 -0
- data/app/controllers/unico/banks_controller.rb +3 -0
- data/app/controllers/unico/creditors_controller.rb +3 -0
- data/app/controllers/unico/document_types_controller.rb +3 -0
- data/app/controllers/unico/material_classes_controller.rb +3 -0
- data/app/controllers/unico/materials_controller.rb +27 -0
- data/app/controllers/unico/reference_units_controller.rb +3 -0
- data/app/controllers/unico/registration_cadastral_certificates_controller.rb +30 -0
- data/app/controllers/unico/regularization_or_administrative_sanction_reasons_controller.rb +3 -0
- data/app/controllers/unico/similarity_controls_controller.rb +68 -0
- data/app/decorators/agency_decorator.rb +3 -0
- data/app/decorators/bank_account_decorator.rb +3 -0
- data/app/decorators/bank_decorator.rb +3 -0
- data/app/decorators/creditor_decorator.rb +11 -0
- data/app/decorators/document_type_decorator.rb +3 -0
- data/app/decorators/material_class_decorator.rb +52 -0
- data/app/decorators/reference_unit_decorator.rb +3 -0
- data/app/decorators/registration_cadastral_certificate_decorator.rb +6 -0
- data/app/decorators/regularization_or_administrative_sanction_reason_decorator.rb +3 -0
- data/app/decorators/similarity_control_decorator.rb +5 -0
- data/app/enumerations/account_type.rb +3 -0
- data/app/enumerations/bank_account_kind.rb +3 -0
- data/app/enumerations/cbo_type.rb +3 -0
- data/app/enumerations/condominium_type.rb +3 -0
- data/app/enumerations/customization_model.rb +10 -0
- data/app/enumerations/data_type.rb +3 -0
- data/app/enumerations/gender.rb +3 -0
- data/app/enumerations/habilitation_kind.rb +4 -0
- data/app/enumerations/issuer.rb +11 -0
- data/app/enumerations/job_status.rb +3 -0
- data/app/enumerations/legal_nature_level.rb +3 -0
- data/app/enumerations/marital_status.rb +3 -0
- data/app/enumerations/material_classification_type.rb +3 -0
- data/app/enumerations/nationality.rb +3 -0
- data/app/enumerations/organ_responsible.rb +3 -0
- data/app/enumerations/personable_type.rb +4 -0
- data/app/enumerations/regularization_or_administrative_sanction_reason_type.rb +3 -0
- data/app/enumerations/regularization_or_administrative_sanction_reason_type.yml +5 -0
- data/app/enumerations/regulatory_act_classification.rb +3 -0
- data/app/enumerations/regulatory_act_type.rb +9 -0
- data/app/enumerations/similarity_table.rb +23 -0
- data/app/enumerations/state_list.rb +5 -0
- data/app/enumerations/status.rb +3 -0
- data/app/enumerations/taxable_type.rb +7 -0
- data/app/models/address.rb +2 -0
- data/app/models/agency.rb +2 -0
- data/app/models/bank.rb +2 -0
- data/app/models/bank_account.rb +2 -0
- data/app/models/city.rb +2 -0
- data/app/models/cnae.rb +2 -0
- data/app/models/communication_source.rb +2 -0
- data/app/models/company.rb +2 -0
- data/app/models/company_size.rb +2 -0
- data/app/models/condominium.rb +2 -0
- data/app/models/country.rb +2 -0
- data/app/models/creditor.rb +2 -0
- data/app/models/creditor_balance.rb +2 -0
- data/app/models/creditor_bank_account.rb +2 -0
- data/app/models/creditor_document.rb +2 -0
- data/app/models/creditor_representative.rb +2 -0
- data/app/models/creditor_secondary_cnae.rb +2 -0
- data/app/models/currency.rb +2 -0
- data/app/models/customer.rb +2 -0
- data/app/models/customization.rb +54 -0
- data/app/models/customization_datum.rb +39 -0
- data/app/models/dissemination_source.rb +2 -0
- data/app/models/district.rb +2 -0
- data/app/models/document_type.rb +2 -0
- data/app/models/identity.rb +2 -0
- data/app/models/individual.rb +2 -0
- data/app/models/inscriptio_cursualis/address.rb +24 -0
- data/app/models/inscriptio_cursualis/city.rb +22 -0
- data/app/models/inscriptio_cursualis/condominium.rb +15 -0
- data/app/models/inscriptio_cursualis/country.rb +15 -0
- data/app/models/inscriptio_cursualis/district.rb +16 -0
- data/app/models/inscriptio_cursualis/land_subdivision.rb +12 -0
- data/app/models/inscriptio_cursualis/neighborhood.rb +33 -0
- data/app/models/inscriptio_cursualis/state.rb +20 -0
- data/app/models/inscriptio_cursualis/street.rb +38 -0
- data/app/models/inscriptio_cursualis/street_type.rb +18 -0
- data/app/models/land_subdivision.rb +2 -0
- data/app/models/legal_nature.rb +2 -0
- data/app/models/material.rb +2 -0
- data/app/models/material_class.rb +2 -0
- data/app/models/neighborhood.rb +2 -0
- data/app/models/occupation_base_group.rb +2 -0
- data/app/models/occupation_classification.rb +2 -0
- data/app/models/occupation_group.rb +2 -0
- data/app/models/occupation_main_group.rb +2 -0
- data/app/models/occupation_subgroup.rb +2 -0
- data/app/models/partner.rb +2 -0
- data/app/models/person.rb +2 -0
- data/app/models/persona/company.rb +71 -0
- data/app/models/persona/company_size.rb +12 -0
- data/app/models/persona/creditor.rb +102 -0
- data/app/models/persona/identity.rb +14 -0
- data/app/models/persona/individual.rb +40 -0
- data/app/models/persona/legal_nature.rb +21 -0
- data/app/models/persona/partner.rb +13 -0
- data/app/models/persona/person.rb +57 -0
- data/app/models/prefecture.rb +2 -0
- data/app/models/reference_unit.rb +2 -0
- data/app/models/registration_cadastral_certificate.rb +2 -0
- data/app/models/regularization_or_administrative_sanction.rb +2 -0
- data/app/models/regularization_or_administrative_sanction_reason.rb +2 -0
- data/app/models/regulatory_act.rb +2 -0
- data/app/models/risk_degree.rb +2 -0
- data/app/models/similarity_control.rb +2 -0
- data/app/models/similarity_control_item.rb +2 -0
- data/app/models/similarity_control_table.rb +2 -0
- data/app/models/state.rb +2 -0
- data/app/models/street.rb +2 -0
- data/app/models/street_type.rb +2 -0
- data/app/models/unico/agency.rb +25 -0
- data/app/models/unico/bank.rb +18 -0
- data/app/models/unico/bank_account.rb +31 -0
- data/app/models/unico/cnae.rb +19 -0
- data/app/models/unico/communication_source.rb +15 -0
- data/app/models/unico/creditor_balance.rb +8 -0
- data/app/models/unico/creditor_bank_account.rb +21 -0
- data/app/models/unico/creditor_document.rb +37 -0
- data/app/models/unico/creditor_representative.rb +19 -0
- data/app/models/unico/creditor_secondary_cnae.rb +6 -0
- data/app/models/unico/currency.rb +13 -0
- data/app/models/unico/customer.rb +25 -0
- data/app/models/unico/dissemination_source.rb +19 -0
- data/app/models/unico/document_type.rb +21 -0
- data/app/models/unico/material.rb +33 -0
- data/app/models/unico/material_class.rb +119 -0
- data/app/models/unico/occupation_base_group.rb +17 -0
- data/app/models/unico/occupation_classification.rb +22 -0
- data/app/models/unico/occupation_group.rb +16 -0
- data/app/models/unico/occupation_main_group.rb +17 -0
- data/app/models/unico/occupation_subgroup.rb +17 -0
- data/app/models/unico/prefecture.rb +31 -0
- data/app/models/unico/reference_unit.rb +18 -0
- data/app/models/unico/registration_cadastral_certificate.rb +55 -0
- data/app/models/unico/regularization_or_administrative_sanction.rb +16 -0
- data/app/models/unico/regularization_or_administrative_sanction_reason.rb +18 -0
- data/app/models/unico/regulatory_act.rb +27 -0
- data/app/models/unico/risk_degree.rb +12 -0
- data/app/models/unico/similarity_control.rb +59 -0
- data/app/models/unico/similarity_control_item.rb +41 -0
- data/app/models/unico/similarity_control_table.rb +8 -0
- data/app/uploaders/image_uploader.rb +13 -0
- data/app/uploaders/individual_image_uploader.rb +9 -0
- data/app/uploaders/prefecture_logo_uploader.rb +5 -0
- data/app/uploaders/unico_uploader.rb +5 -0
- data/app/uploaders/uploader.rb +13 -0
- data/app/validators/mail_validator.rb +7 -0
- data/app/validators/person_validator.rb +9 -0
- data/app/views/agencies/_data_attributes.html.jbuilder +6 -0
- data/app/views/agencies/_form.html.erb +26 -0
- data/app/views/bank_accounts/_data_attributes.html.jbuilder +3 -0
- data/app/views/bank_accounts/_form.html.erb +51 -0
- data/app/views/bank_accounts/_main.html.erb +35 -0
- data/app/views/bank_accounts/_show.html.erb +70 -0
- data/app/views/banks/_form.html.erb +13 -0
- data/app/views/cnaes/_data_attributes.html.jbuilder +4 -0
- data/app/views/cnaes/_list_form.html.erb +12 -0
- data/app/views/creditor_balances/_form.html.erb +55 -0
- data/app/views/creditor_bank_accounts/_form.html.erb +36 -0
- data/app/views/creditor_documents/_form.html.erb +32 -0
- data/app/views/creditor_representatives/_list_form.html.erb +12 -0
- data/app/views/creditors/_accounts.html.erb +15 -0
- data/app/views/creditors/_balance.html.erb +15 -0
- data/app/views/creditors/_cnaes.html.erb +36 -0
- data/app/views/creditors/_data_attributes.html.jbuilder +7 -0
- data/app/views/creditors/_documents.html.erb +26 -0
- data/app/views/creditors/_form.html.erb +151 -0
- data/app/views/creditors/_form_buttons.html.erb +14 -0
- data/app/views/creditors/_main.html.erb +68 -0
- data/app/views/creditors/_modal_form.html.erb +3 -0
- data/app/views/creditors/_regularization_or_administrative_sanctions.html.erb +26 -0
- data/app/views/creditors/_representatives.html.erb +37 -0
- data/app/views/creditors/_show.html.erb +105 -0
- data/app/views/creditors/index.json.jbuilder +11 -0
- data/app/views/document_types/_data_attributes.html.jbuilder +4 -0
- data/app/views/document_types/_form.html.erb +3 -0
- data/app/views/document_types/_list_form.html.erb +11 -0
- data/app/views/material_classes/_data_attributes.json.jbuilder +4 -0
- data/app/views/material_classes/_form.html.erb +59 -0
- data/app/views/material_classes/_form_buttons.html.erb +11 -0
- data/app/views/material_classes/_modal_form.html.erb +8 -0
- data/app/views/material_classes/index.json.jbuilder +9 -0
- data/app/views/materials/_data_attributes.html.jbuilder +5 -0
- data/app/views/materials/_form.html.erb +25 -0
- data/app/views/materials/_main.html.erb +34 -0
- data/app/views/materials/index.json.jbuilder +7 -0
- data/app/views/reference_units/_form.html.erb +9 -0
- data/app/views/registration_cadastral_certificates/_actions.html.erb +11 -0
- data/app/views/registration_cadastral_certificates/_form.html.erb +62 -0
- data/app/views/registration_cadastral_certificates/_form_buttons.html.erb +9 -0
- data/app/views/registration_cadastral_certificates/index.html.erb +9 -0
- data/app/views/regularization_or_administrative_sanction_reasons/_data_attributes.html.jbuilder +3 -0
- data/app/views/regularization_or_administrative_sanction_reasons/_form.html.erb +2 -0
- data/app/views/regularization_or_administrative_sanctions/_form.html.erb +28 -0
- data/app/views/similarity_controls/processing.html.erb +25 -0
- data/app/views/similarity_controls/show.json.jbuilder +3 -0
- data/app/workers/base_worker.rb +62 -0
- data/app/workers/similarity_control_worker.rb +2 -0
- data/app/workers/unico/similarity_control_worker.rb +19 -0
- data/build.sh +17 -0
- data/config/database.sample.yml +8 -0
- data/config/database.semaphore.yml +17 -0
- data/config/environment.rb +0 -0
- data/config/initializers/active_record_block.rb +3 -0
- data/config/initializers/active_record_filter.rb +3 -0
- data/config/initializers/active_record_modal.rb +3 -0
- data/config/locales/account_type.yml +5 -0
- data/config/locales/activerecord.yml +14 -0
- data/config/locales/agency.yml +17 -0
- data/config/locales/bank.yml +12 -0
- data/config/locales/bank_account.yml +20 -0
- data/config/locales/bank_account_kind.yml +8 -0
- data/config/locales/cbo_type.yml +5 -0
- data/config/locales/communication_source.yml +10 -0
- data/config/locales/controllers.yml +9 -0
- data/config/locales/creditor.yml +35 -0
- data/config/locales/creditor_balance.yml +18 -0
- data/config/locales/creditor_bank_account.yml +17 -0
- data/config/locales/creditor_document.yml +15 -0
- data/config/locales/creditor_representative.yml +11 -0
- data/config/locales/customization_model.yml +11 -0
- data/config/locales/dissemination_source.yml +11 -0
- data/config/locales/document_type.yml +12 -0
- data/config/locales/habilitation_kind.yml +6 -0
- data/config/locales/issuer.yml +32 -0
- data/config/locales/job_status.yml +6 -0
- data/config/locales/material.yml +21 -0
- data/config/locales/material_class.yml +17 -0
- data/config/locales/material_classification_type.yml +6 -0
- data/config/locales/organ_responsible.yml +6 -0
- data/config/locales/prefecture.yml +10 -0
- data/config/locales/reference_unit.yml +11 -0
- data/config/locales/registration_cadastral_certificate.yml +24 -0
- data/config/locales/regularization_or_administrative_sanction.yml +15 -0
- data/config/locales/regularization_or_administrative_sanction_reason.yml +11 -0
- data/config/locales/regulatory_act.yml +29 -0
- data/config/locales/regulatory_act_classification.yml +7 -0
- data/config/locales/regulatory_act_type.yml +10 -0
- data/config/locales/similarity_control.yml +19 -0
- data/config/locales/similarity_table.yml +8 -0
- data/config/locales/state_list.yml +30 -0
- data/config/locales/status.yml +5 -0
- data/config/locales/street.yml +19 -0
- data/db/functions/constraints/01_add_constraints.sql +49 -0
- data/db/migrate/20110116144640_add_unaccent_extension.rb +5 -0
- data/db/migrate/20110429235848_create_people.rb +13 -0
- data/db/migrate/20110530180855_create_countries.rb +10 -0
- data/db/migrate/20110531131347_create_states.rb +11 -0
- data/db/migrate/20110601163113_create_cities.rb +14 -0
- data/db/migrate/20110601172922_add_country_id_to_states.rb +6 -0
- data/db/migrate/20110601201806_create_districts.rb +10 -0
- data/db/migrate/20110602124204_create_street_types.rb +9 -0
- data/db/migrate/20110602135553_create_streets.rb +17 -0
- data/db/migrate/20110602175632_create_neighborhoods.rb +12 -0
- data/db/migrate/20110602184257_add_phone_to_people.rb +7 -0
- data/db/migrate/20110602184907_add_email_to_people.rb +5 -0
- data/db/migrate/20110602185306_add_code_to_people.rb +5 -0
- data/db/migrate/20110602190207_create_person_identities.rb +16 -0
- data/db/migrate/20110602201455_create_land_subdivisions.rb +15 -0
- data/db/migrate/20110603131109_create_condominium_types.rb +9 -0
- data/db/migrate/20110603141048_create_condominiums.rb +29 -0
- data/db/migrate/20110603163203_remove_number_from_condominium.rb +9 -0
- data/db/migrate/20110606163747_remove_code_from_people.rb +5 -0
- data/db/migrate/20110606165434_remove_neighborhood_id_from_condominiums.rb +6 -0
- data/db/migrate/20110606170743_remove_code_from_countries.rb +5 -0
- data/db/migrate/20110606172221_remove_code_from_states.rb +5 -0
- data/db/migrate/20110606172748_remove_code_from_cities.rb +5 -0
- data/db/migrate/20110606174103_remove_code_from_districts.rb +5 -0
- data/db/migrate/20110607135059_create_currencies.rb +10 -0
- data/db/migrate/20110616191453_create_genders.rb +9 -0
- data/db/migrate/20110616192113_remove_gender_from_people.rb +5 -0
- data/db/migrate/20110616192206_add_gender_id_to_people.rb +6 -0
- data/db/migrate/20110621195226_create_address_types.rb +9 -0
- data/db/migrate/20110622170457_create_company_sizes.rb +11 -0
- data/db/migrate/20110622205700_create_addresses.rb +27 -0
- data/db/migrate/20110627190518_create_legal_natures.rb +10 -0
- data/db/migrate/20110627204600_add_ancestry_to_legal_natures.rb +6 -0
- data/db/migrate/20110629204622_create_companies.rb +24 -0
- data/db/migrate/20110629221035_create_contributors.rb +12 -0
- data/db/migrate/20110629224915_add_name_to_companies.rb +5 -0
- data/db/migrate/20110704052310_add_cpf_to_people.rb +5 -0
- data/db/migrate/20110706140744_add_cep_to_addresses.rb +5 -0
- data/db/migrate/20110712135510_create_prefectures.rb +27 -0
- data/db/migrate/20110722183838_create_address_tickets.rb +10 -0
- data/db/migrate/20110811202352_add_number_to_addresses.rb +5 -0
- data/db/migrate/20110811202544_add_zip_code_to_addresses.rb +5 -0
- data/db/migrate/20110811202804_add_block_to_addresses.rb +5 -0
- data/db/migrate/20110811202940_add_room_to_addresses.rb +5 -0
- data/db/migrate/20110811203043_remove_cep_from_addresses.rb +9 -0
- data/db/migrate/20110811204502_remove_zip_code_from_streets.rb +9 -0
- data/db/migrate/20110815164912_rename_table_people_to_individuals.rb +9 -0
- data/db/migrate/20110815165559_rename_table_contributors_to_people.rb +9 -0
- data/db/migrate/20110815171945_rename_table_person_identities_to_individual_identities.rb +9 -0
- data/db/migrate/20110815182338_rename_column_person_id_in_identity_to_individual_id.rb +9 -0
- data/db/migrate/20110815193318_remove_street_id_from_prefectures.rb +11 -0
- data/db/migrate/20110815193801_remove_neighborhood_id_from_prefectures.rb +11 -0
- data/db/migrate/20110815194308_remove_number_from_prefectures.rb +9 -0
- data/db/migrate/20110815194430_remove_zip_code_from_prefectures.rb +9 -0
- data/db/migrate/20110815194457_remove_complement_from_prefectures.rb +9 -0
- data/db/migrate/20110816024105_add_company_size_as_fk_to_companies.rb +5 -0
- data/db/migrate/20110816024522_add_legal_nature_as_fk_to_companies.rb +5 -0
- data/db/migrate/20110816030813_add_person_id_as_fk_to_companies.rb +5 -0
- data/db/migrate/20110816195312_create_partners.rb +18 -0
- data/db/migrate/20110817140815_create_customers.rb +13 -0
- data/db/migrate/20110817210250_add_correspondence_to_addresses.rb +5 -0
- data/db/migrate/20110901172241_remove_street_id_from_condominium.rb +5 -0
- data/db/migrate/20110902133329_alter_column_digit_to_code_on_cities.rb +5 -0
- data/db/migrate/20110903171330_add_neighborhood_id_to_prefectures.rb +6 -0
- data/db/migrate/20110905113916_add_column_default_to_countries.rb +5 -0
- data/db/migrate/20110905121020_add_column_default_to_cities.rb +5 -0
- data/db/migrate/20110905122437_remove_neighborhood_id_from_prefectures_again.rb +11 -0
- data/db/migrate/20110905162912_add_column_default_to_districts.rb +5 -0
- data/db/migrate/20110905172053_add_column_default_to_states.rb +5 -0
- data/db/migrate/20110905192053_remove_city_id_from_street.rb +11 -0
- data/db/migrate/20110905192751_add_acronym_to_street_types.rb +5 -0
- data/db/migrate/20110906120319_add_gender_id_to_people_again.rb +5 -0
- data/db/migrate/20110908133532_add_address_type_id_to_addresses.rb +7 -0
- data/db/migrate/20110908175305_create_neighborhoods_streets.rb +13 -0
- data/db/migrate/20110909194606_remove_name_from_individuals_and_companies.rb +11 -0
- data/db/migrate/20110912153839_remove_contact_fields_from_individuals.rb +15 -0
- data/db/migrate/20110912160521_remove_contact_fields_from_companies.rb +15 -0
- data/db/migrate/20110912173117_add_contact_columns_to_people.rb +8 -0
- data/db/migrate/20110914221204_add_latitude_and_longitude_to_address.rb +6 -0
- data/db/migrate/20110919142728_add_default_to_correspondence_in_addresses.rb +9 -0
- data/db/migrate/20110922143914_remove_gender_id_from_people.rb +11 -0
- data/db/migrate/20110922175818_rename_individual_identities_to_identities.rb +5 -0
- data/db/migrate/20110929113404_add_code_to_states.rb +5 -0
- data/db/migrate/20111005135305_remove_ancestry_from_legal_natures.rb +9 -0
- data/db/migrate/20111005135734_add_awesome_nested_set_columns_to_legal_natures.rb +10 -0
- data/db/migrate/20111013002056_remove_gender_id_from_individuals.rb +6 -0
- data/db/migrate/20111013002322_drop_table_genders.rb +5 -0
- data/db/migrate/20111013011843_add_gender_to_individuals.rb +5 -0
- data/db/migrate/20111013033830_remove_default_from_countries.rb +5 -0
- data/db/migrate/20111013034546_remove_default_from_states.rb +5 -0
- data/db/migrate/20111013034922_remove_default_from_cities.rb +5 -0
- data/db/migrate/20111014190458_change_choose_simple_default_on_companies.rb +9 -0
- data/db/migrate/20111017063746_use_composited_index_for_addressable_on_addresses.rb +13 -0
- data/db/migrate/20111017065519_add_index_on_individual_id_on_identities.rb +5 -0
- data/db/migrate/20111017065533_add_index_on_state_id_on_identities.rb +5 -0
- data/db/migrate/20111017070508_use_composited_index_on_personable_on_people.rb +15 -0
- data/db/migrate/20111017071127_add_index_on_country_id_on_states.rb +5 -0
- data/db/migrate/20111018124812_remove_coordinates_from_addresses.rb +5 -0
- data/db/migrate/20111030170019_remove_default_flag_from_districts.rb +5 -0
- data/db/migrate/20111104192714_remove_column_prefectures_city_id.rb +5 -0
- data/db/migrate/20111105040503_remove_column_prefectures_acronym.rb +5 -0
- data/db/migrate/20111107162734_add_precision_to_condominiums_built_area.rb +5 -0
- data/db/migrate/20111107162816_add_precision_to_condominiums_area_common_user.rb +5 -0
- data/db/migrate/20111114165749_add_image_to_prefectures.rb +5 -0
- data/db/migrate/20111124121605_remove_column_addresses_address_type_id.rb +5 -0
- data/db/migrate/20111124121622_drop_table_address_types.rb +5 -0
- data/db/migrate/20111213130749_remove_column_states_code.rb +5 -0
- data/db/migrate/20111226113722_add_city_id_to_districts.rb +6 -0
- data/db/migrate/20111226122849_drop_table_address_tickets.rb +5 -0
- data/db/migrate/20111226124756_remove_neighboord_id_from_land_subdivisions.rb +5 -0
- data/db/migrate/20111226124852_remove_district_id_from_land_subdivisions.rb +5 -0
- data/db/migrate/20120124181637_add_level_to_legal_natures.rb +5 -0
- data/db/migrate/20120127104149_readd_code_to_states.rb +5 -0
- data/db/migrate/20120314224041_drop_table_condominium_types_and_associations.rb +8 -0
- data/db/migrate/20120314225506_add_condominium_type_to_condominiums.rb +5 -0
- data/db/migrate/20120315161607_remove_columns_to_condominiums.rb +13 -0
- data/db/migrate/20120315174647_remove_condominium_id_to_adressess.rb +9 -0
- data/db/migrate/20120315200108_add_condominium_id_to_addresses.rb +5 -0
- data/db/migrate/20120316124724_add_district_id_to_neighborhoods.rb +7 -0
- data/db/migrate/20120316171434_remove_district_id_to_addresses.rb +7 -0
- data/db/migrate/20120316174453_add_index_and_foreign_key_to_addresses.rb +6 -0
- data/db/migrate/20120321222453_move_partners_of_economic_registrations_to_company.rb +14 -0
- data/db/migrate/20120521141003_create_unico_countries.rb +5 -0
- data/db/migrate/20120521141007_create_unico_states.rb +5 -0
- data/db/migrate/20120521141013_create_unico_cities.rb +5 -0
- data/db/migrate/20120521141021_create_unico_districts.rb +5 -0
- data/db/migrate/20120521141103_create_unico_neighborhoods.rb +5 -0
- data/db/migrate/20120521191721_rename_neighborhoods_streets_to_streets_unico_neighborhoods.rb +5 -0
- data/db/migrate/20120530152810_rename_streets_to_unico_streets.rb +5 -0
- data/db/migrate/20120530152952_rename_streets_unico_neighborhoods_to_unico_neighborhoods_unico_streets.rb +5 -0
- data/db/migrate/20120530153640_rename_street_types_to_unico_street_types.rb +5 -0
- data/db/migrate/20120530162433_rename_land_subdivisions_to_unico_land_subdivisions.rb +5 -0
- data/db/migrate/20120530180410_rename_condominiums_to_unico_condominiums.rb +5 -0
- data/db/migrate/20120531114233_rename_unico_condominiums_to_unico_condominia.rb +5 -0
- data/db/migrate/20120531165934_rename_addresses_to_unico_addresses.rb +5 -0
- data/db/migrate/20120605101823_rename_company_sizes_to_unico_company_sizes.rb +5 -0
- data/db/migrate/20120605103033_rename_legal_natures_to_unico_legal_natures.rb +5 -0
- data/db/migrate/20120605202644_rename_people_to_unico_people.rb +5 -0
- data/db/migrate/20120605213011_rename_companies_to_unico_companies.rb +5 -0
- data/db/migrate/20120605213109_rename_identities_to_unico_identities.rb +5 -0
- data/db/migrate/20120605213241_rename_partners_to_unico_partners.rb +5 -0
- data/db/migrate/20120605215523_rename_individuals_to_unico_individuals.rb +5 -0
- data/db/migrate/20120614175605_rename_customers_to_unico_customers.rb +5 -0
- data/db/migrate/20120614183133_rename_prefectures_to_unico_prefectures.rb +5 -0
- data/db/migrate/20120620130440_add_benefited_to_company_sizes.rb +5 -0
- data/db/migrate/20120620164340_remove_benefited_from_company_sizes.rb +5 -0
- data/db/migrate/20120714152059_rename_currencies_to_unico_currencies.rb +5 -0
- data/db/migrate/20120723134307_migrate_address_to_person.rb +7 -0
- data/db/migrate/20120904235430_add_precision_to_unico_currencies.rb +5 -0
- data/db/migrate/20121019142850_create_unico_risk_degrees.rb +13 -0
- data/db/migrate/20121019151228_create_unico_cnaes.rb +18 -0
- data/db/migrate/20121025165054_add_city_id_to_unico_streets.rb +13 -0
- data/db/migrate/20121026125540_add_syndicated_affiliated_to_unico_companies.rb +5 -0
- data/db/migrate/20121108231044_add_marital_status_to_individual.rb +5 -0
- data/db/migrate/20121108231957_add_place_of_birth_to_individual.rb +9 -0
- data/db/migrate/20121113155708_add_trade_name_to_unico_companies.rb +5 -0
- data/db/migrate/20130204185551_add_code_to_unico_countries.rb +5 -0
- data/db/migrate/20130204185635_add_code_to_unico_street_types.rb +5 -0
- data/db/migrate/20130218100005_create_unico_occupation_classifications.rb +16 -0
- data/db/migrate/20130218191619_add_original_id_and_original_system_to_unico_people.rb +6 -0
- data/db/migrate/20130307185439_add_tce_mg_code_to_cities.rb +5 -0
- data/db/migrate/20130410130902_add_gist_index_to_unico_people.rb +18 -0
- data/db/migrate/20130410235225_add_gist_index_to_unico_occupation_classifications.rb +14 -0
- data/db/migrate/20130411162741_add_image_to_individual.rb +5 -0
- data/db/migrate/20130415204954_add_nationality_and_country_of_birth_id_to_unico_individuals.rb +8 -0
- data/db/migrate/20130415220244_add_index_on_country_of_birth_id_on_individuals.rb +5 -0
- data/db/migrate/20130418122109_add_secret_token_to_unico_customers.rb +10 -0
- data/db/migrate/20130425134706_add_column_inactive_to_addresses.rb +5 -0
- data/db/migrate/20130425134838_add_column_inactive_to_people.rb +5 -0
- data/db/migrate/20130425174621_add_column_inactive_to_streets.rb +5 -0
- data/db/migrate/20130517140021_add_column_uf_to_companies.rb +5 -0
- data/db/migrate/20130702112232_create_unico_regulatory_acts.rb +30 -0
- data/db/migrate/20130702144123_create_unico_communication_sources.rb +8 -0
- data/db/migrate/20130702151131_create_unico_dissemination_sources.rb +14 -0
- data/db/migrate/20130702152037_create_unico_dissemination_sources_unico_regulatory_acts.rb +18 -0
- data/db/migrate/20130703134328_create_unico_creditors.rb +25 -0
- data/db/migrate/20130705110811_create_unico_creditor_secondary_cnaes.rb +16 -0
- data/db/migrate/20130705134815_create_unico_creditor_representatives.rb +17 -0
- data/db/migrate/20130705143512_create_unico_creditor_balances.rb +21 -0
- data/db/migrate/20130705155916_create_unico_document_types.rb +11 -0
- data/db/migrate/20130705163831_create_unico_creditor_documents.rb +21 -0
- data/db/migrate/20130708140521_create_unico_banks.rb +10 -0
- data/db/migrate/20130708141313_create_unico_agencies.rb +18 -0
- data/db/migrate/20130708142321_create_unico_bank_accounts.rb +17 -0
- data/db/migrate/20130708150305_create_unico_creditor_bank_accounts.rb +22 -0
- data/db/migrate/20130708163542_create_unico_regularization_or_administrative_sanction_reasons.rb +9 -0
- data/db/migrate/20130708170709_create_unico_regularization_or_administrative_sanctions.rb +22 -0
- data/db/migrate/20130708180241_create_unico_registration_cadastral_certificates.rb +27 -0
- data/db/migrate/20130709175321_add_organ_responsible_for_registration_to_unico_creditors.rb +5 -0
- data/db/migrate/20130716143951_setup_unico_hstore.rb +9 -0
- data/db/migrate/20130716144626_add_custom_data_to_unico_creditor.rb +5 -0
- data/db/migrate/20130724132535_add_application_kind_closing_date_and_capability_kind_to_creditors.rb +7 -0
- data/db/migrate/20130725162650_add_state_acronym_to_prefecture.rb +6 -0
- data/db/migrate/20130731153025_create_missing_secret_token_for_customer.rb +9 -0
- data/db/migrate/20130911135646_change_rerulatory_act_type_on_regulatory_acts.rb +5 -0
- data/db/migrate/20131001170551_create_versions.rb +18 -0
- data/db/migrate/20131002191733_add_domain_to_prefecture.rb +5 -0
- data/db/migrate/20131023160005_add_time_zone_to_prefectures.rb +5 -0
- data/db/migrate/20140508085731_add_object_changes_to_versions.rb +5 -0
- data/db/migrate/20140515191425_add_disabled_to_customers.rb +5 -0
- data/db/migrate/20140730124639_create_unico_reference_units.rb +9 -0
- data/db/migrate/20140806124608_create_table_unico_material_classes.rb +16 -0
- data/db/migrate/20140806124639_change_acronym_from_unico_reference_units.rb +5 -0
- data/db/migrate/20140929200836_add_cpf_cnpj_to_people.rb +6 -0
- data/db/migrate/20140930083205_add_normalized_name_to_people.rb +5 -0
- data/db/migrate/20140930133849_migrate_data_of_people.rb +7 -0
- data/db/migrate/20140930165938_add_index_to_normalized_name_on_people.rb +5 -0
- data/db/migrate/20150716114056_add_inactive_to_address_tables.rb +7 -0
- data/db/migrate/20160520184356_create_unico_materials.rb +24 -0
- data/db/migrate/20161201184437_create_unico_similarity_controls.rb +15 -0
- data/db/migrate/20161201194536_create_unico_similarity_control_items.rb +18 -0
- data/db/migrate/20161202111046_create_unico_similarity_control_tables.rb +13 -0
- data/db/migrate/20161209113445_add_job_status_to_unico_similarity_controls.rb +7 -0
- data/db/migrate/20170404170636_add_cnh_to_unico_individuals.rb +6 -0
- data/db/migrate/20170503094509_change_mobile_limit_on_people.rb +5 -0
- data/db/migrate/20170724135645_add_active_column_to_unico_occupation_classifications.rb +5 -0
- data/db/migrate/20170726135645_create_occupation_groups.rb +10 -0
- data/db/migrate/20170726135646_create_occupation_main_groups.rb +15 -0
- data/db/migrate/20170726135647_create_occupation_subgroups.rb +15 -0
- data/db/migrate/20170727135648_create_occupation_base_groups.rb +15 -0
- data/db/migrate/20170727174947_add_occupation_base_group_to_occupation_classifications.rb +6 -0
- data/db/migrate/20170728135645_add_type_to_unico_occupation_classifications.rb +5 -0
- data/db/migrate/20170728135646_drop_constraint_on_unico_occupation_classifications.rb +5 -0
- data/db/migrate/20170728135647_remove_lft_rgt_from_occupation_classifications.rb +13 -0
- data/lib/active_record/block.rb +44 -0
- data/lib/active_record/filter.rb +63 -0
- data/lib/active_record/filters/base.rb +38 -0
- data/lib/active_record/filters/filter.rb +65 -0
- data/lib/active_record/modal.rb +42 -0
- data/lib/belongs_to_resource.rb +111 -0
- data/lib/custom_data.rb +131 -0
- data/lib/custom_data_query.rb +15 -0
- data/lib/custom_postgres_copy.rb +9 -0
- data/lib/extensions.rb +5 -0
- data/lib/import/files/cities.csv +5571 -0
- data/lib/import/files/cnaes.csv +2385 -0
- data/lib/import/files/company_sizes.csv +6 -0
- data/lib/import/files/countries.csv +329 -0
- data/lib/import/files/legal_natures.csv +72 -0
- data/lib/import/files/material_classes.csv +215 -0
- data/lib/import/files/occupation_base_groups.csv +618 -0
- data/lib/import/files/occupation_classifications.csv +10184 -0
- data/lib/import/files/occupation_groups.csv +11 -0
- data/lib/import/files/occupation_main_groups.csv +50 -0
- data/lib/import/files/occupation_subgroups.csv +196 -0
- data/lib/import/files/states.csv +28 -0
- data/lib/import/files/street_types.csv +130 -0
- data/lib/import/files/updated_street_types.csv +291 -0
- data/lib/importer_helper.rb +32 -0
- data/lib/inscriptio_cursualis.rb +3 -0
- data/lib/inscriptio_cursualis/model.rb +8 -0
- data/lib/persona.rb +3 -0
- data/lib/persona/model.rb +8 -0
- data/lib/simple_decorator.rb +7 -0
- data/lib/simple_decorator/base.rb +11 -0
- data/lib/simple_decorator/common_decorated.rb +78 -0
- data/lib/simple_decorator/header.rb +43 -0
- data/lib/simple_decorator/plug.rb +23 -0
- data/lib/simple_decorator/rails_helpers.rb +16 -0
- data/lib/street_type_updater.rb +60 -0
- data/lib/tasks/importers/address.rake +56 -0
- data/lib/tasks/importers/inscriptio_cursualis_all.rake +45 -0
- data/lib/tasks/importers/persona.rake +29 -0
- data/lib/tasks/importers/unico_all.rake +69 -0
- data/lib/tasks/updaters/city/tce_mg_code.rake +22 -0
- data/lib/tasks/updaters/street_type.rake +15 -0
- data/lib/time_zone.rb +15 -0
- data/lib/unico.rb +13 -0
- data/lib/unico/engine.rb +16 -0
- data/lib/unico/model.rb +8 -0
- data/lib/unico/version.rb +5 -0
- data/spec/business/similarity_control_adjuster_spec.rb +54 -0
- data/spec/business/similarity_control_checker_spec.rb +146 -0
- data/spec/fixtures/integraLogo.png +0 -0
- data/spec/lib/active_record/modal_spec.rb +27 -0
- data/spec/lib/persona/model_spec.rb +15 -0
- data/spec/lib/simple_decorator/base_spec.rb +49 -0
- data/spec/lib/simple_decorator/common_decorated_spec.rb +147 -0
- data/spec/lib/simple_decorator/header_spec.rb +164 -0
- data/spec/lib/simple_decorator/plug_spec.rb +64 -0
- data/spec/lib/street_type_updater_spec.rb +37 -0
- data/spec/lib/unico/model_spec.rb +15 -0
- data/spec/locale_helper.rb +37 -0
- data/spec/models/address_spec.rb +125 -0
- data/spec/models/agency_spec.rb +26 -0
- data/spec/models/bank_account_spec.rb +37 -0
- data/spec/models/bank_spec.rb +27 -0
- data/spec/models/city_spec.rb +20 -0
- data/spec/models/cnae_spec.rb +16 -0
- data/spec/models/communication_source_spec.rb +17 -0
- data/spec/models/company_size_spec.rb +17 -0
- data/spec/models/company_spec.rb +82 -0
- data/spec/models/condominium_spec.rb +14 -0
- data/spec/models/country_spec.rb +15 -0
- data/spec/models/creditor_balance_spec.rb +10 -0
- data/spec/models/creditor_bank_account_spec.rb +20 -0
- data/spec/models/creditor_document_spec.rb +60 -0
- data/spec/models/creditor_representative_spec.rb +8 -0
- data/spec/models/creditor_secondary_cnae_spec.rb +8 -0
- data/spec/models/creditor_spec.rb +38 -0
- data/spec/models/currency_spec.rb +28 -0
- data/spec/models/customer_spec.rb +26 -0
- data/spec/models/dissemination_source_spec.rb +28 -0
- data/spec/models/district_spec.rb +18 -0
- data/spec/models/document_type_spec.rb +11 -0
- data/spec/models/identity_spec.rb +20 -0
- data/spec/models/individual_spec.rb +60 -0
- data/spec/models/inscriptio_cursualis/address_spec.rb +7 -0
- data/spec/models/inscriptio_cursualis/city_spec.rb +7 -0
- data/spec/models/inscriptio_cursualis/condominium_spec.rb +7 -0
- data/spec/models/inscriptio_cursualis/country_spec.rb +7 -0
- data/spec/models/inscriptio_cursualis/district_spec.rb +7 -0
- data/spec/models/inscriptio_cursualis/land_subdivision_spec.rb +7 -0
- data/spec/models/inscriptio_cursualis/neighborhood_spec.rb +7 -0
- data/spec/models/inscriptio_cursualis/state_spec.rb +7 -0
- data/spec/models/inscriptio_cursualis/street_spec.rb +7 -0
- data/spec/models/inscriptio_cursualis/street_type_spec.rb +7 -0
- data/spec/models/land_subdivision_spec.rb +13 -0
- data/spec/models/legal_nature_spec.rb +14 -0
- data/spec/models/material_class_spec.rb +147 -0
- data/spec/models/material_spec.rb +25 -0
- data/spec/models/neighborhood_spec.rb +73 -0
- data/spec/models/occupation_base_group_spec.rb +18 -0
- data/spec/models/occupation_classification_spec.rb +17 -0
- data/spec/models/occupation_group_spec.rb +17 -0
- data/spec/models/occupation_main_group_spec.rb +18 -0
- data/spec/models/occupation_subgroup_spec.rb +18 -0
- data/spec/models/partner_spec.rb +24 -0
- data/spec/models/person_spec.rb +129 -0
- data/spec/models/persona/company_size_spec.rb +7 -0
- data/spec/models/persona/company_spec.rb +7 -0
- data/spec/models/persona/creditor_spec.rb +7 -0
- data/spec/models/persona/identity_spec.rb +7 -0
- data/spec/models/persona/individual_spec.rb +7 -0
- data/spec/models/persona/legal_nature_spec.rb +7 -0
- data/spec/models/persona/partner_spec.rb +7 -0
- data/spec/models/persona/person_spec.rb +7 -0
- data/spec/models/prefecture_spec.rb +48 -0
- data/spec/models/reference_unit_spec.rb +15 -0
- data/spec/models/registration_cadastral_certificate_spec.rb +77 -0
- data/spec/models/regularization_or_administrative_sanction_reason_spec.rb +14 -0
- data/spec/models/regularization_or_administrative_sanction_spec.rb +21 -0
- data/spec/models/regulatory_act_spec.rb +23 -0
- data/spec/models/risk_degree_spec.rb +16 -0
- data/spec/models/similarity_control_item_spec.rb +12 -0
- data/spec/models/similarity_control_spec.rb +30 -0
- data/spec/models/similarity_control_table_spec.rb +10 -0
- data/spec/models/state_spec.rb +18 -0
- data/spec/models/street_spec.rb +55 -0
- data/spec/models/street_type_spec.rb +16 -0
- data/spec/models/unico/agency_spec.rb +7 -0
- data/spec/models/unico/bank_account_spec.rb +7 -0
- data/spec/models/unico/bank_spec.rb +7 -0
- data/spec/models/unico/communication_source_spec.rb +7 -0
- data/spec/models/unico/creditor_balance_spec.rb +7 -0
- data/spec/models/unico/creditor_bank_account_spec.rb +7 -0
- data/spec/models/unico/creditor_document_spec.rb +7 -0
- data/spec/models/unico/creditor_representative_spec.rb +7 -0
- data/spec/models/unico/creditor_secondary_cnae_spec.rb +7 -0
- data/spec/models/unico/currency_spec.rb +7 -0
- data/spec/models/unico/customer_spec.rb +7 -0
- data/spec/models/unico/dissemination_source_spec.rb +7 -0
- data/spec/models/unico/document_type_spec.rb +7 -0
- data/spec/models/unico/material_class_spec.rb +7 -0
- data/spec/models/unico/material_spec.rb +7 -0
- data/spec/models/unico/prefecture_spec.rb +7 -0
- data/spec/models/unico/reference_unit_spec.rb +7 -0
- data/spec/models/unico/registration_cadastral_certificate_spec.rb +7 -0
- data/spec/models/unico/regularization_or_administrative_sanction_reason_spec.rb +7 -0
- data/spec/models/unico/regularization_or_administrative_sanction_spec.rb +7 -0
- data/spec/models/unico/regulatory_act_spec.rb +7 -0
- data/spec/models/unico/similarity_control_item_spec.rb +7 -0
- data/spec/models/unico/similarity_control_spec.rb +7 -0
- data/spec/models/unico/similarity_control_table_spec.rb +7 -0
- data/spec/spec_helper.rb +79 -0
- data/spec/uploaders/image_uploader_spec.rb +39 -0
- data/spec/uploaders/prefecture_logo_uploader_spec.rb +5 -0
- data/spec/validators/person_validator_spec.rb +56 -0
- data/unico.gemspec +40 -0
- metadata +979 -0
@@ -0,0 +1,6 @@
|
|
1
|
+
class AddOccupationBaseGroupToOccupationClassifications < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
add_column :unico_occupation_classifications, :occupation_base_group_id, :integer
|
4
|
+
add_index :unico_occupation_classifications, :occupation_base_group_id, name: :idx_occupation_classifications_on_occupation_base_group_id
|
5
|
+
end
|
6
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class RemoveLftRgtFromOccupationClassifications < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
remove_column :unico_occupation_classifications, :lft
|
4
|
+
remove_column :unico_occupation_classifications, :rgt
|
5
|
+
remove_column :unico_occupation_classifications, :parent_id
|
6
|
+
end
|
7
|
+
|
8
|
+
def down
|
9
|
+
add_column :unico_occupation_classifications, :lft, :integer
|
10
|
+
add_column :unico_occupation_classifications, :rgt, :integer
|
11
|
+
add_column :unico_occupation_classifications, :parent_id, :integer
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Block
|
3
|
+
# Block destroy and update just overwriting destroyable? and updateable?
|
4
|
+
# methods
|
5
|
+
#
|
6
|
+
def self.included(base)
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
|
9
|
+
base.load_cant_be_updated_validate
|
10
|
+
base.load_cant_be_destroyed_callback
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def load_cant_be_updated_validate
|
15
|
+
validate do
|
16
|
+
if persisted? && !updateable?
|
17
|
+
attribute_names.each do |attr|
|
18
|
+
errors.add(attr, :cant_be_updated) if send("#{attr}_changed?")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def load_cant_be_destroyed_callback
|
25
|
+
before_destroy :cant_be_destroyed, if: -> { !destroyable? }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def destroyable?
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
def updateable?
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def cant_be_destroyed
|
40
|
+
errors.add(:base, :cant_be_destroyed)
|
41
|
+
false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Filter
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def filterize(attributes = modal_attributes_with_options, options = {})
|
7
|
+
if attributes.is_a?(Hash)
|
8
|
+
options = attributes
|
9
|
+
attributes = accessible_attributes
|
10
|
+
end
|
11
|
+
|
12
|
+
attributes = Array(attributes)
|
13
|
+
|
14
|
+
class_eval(<<-eoruby, __FILE__, __LINE__ + 1)
|
15
|
+
def self.filter(params)
|
16
|
+
Filters::Filter.new(self, #{attributes}, #{options}).call(params)
|
17
|
+
end
|
18
|
+
eoruby
|
19
|
+
end
|
20
|
+
|
21
|
+
def orderize(*attributes)
|
22
|
+
options = attributes.extract_options!
|
23
|
+
|
24
|
+
if options.any?
|
25
|
+
include_table = options.fetch(:on)
|
26
|
+
table_name = include_table.to_s.classify.constantize.table_name
|
27
|
+
attributes = "#{table_name}.#{attributes.first}" if include_table.present?
|
28
|
+
else
|
29
|
+
attributes = [:name] if attributes.empty?
|
30
|
+
|
31
|
+
attributes.map! do |attribute|
|
32
|
+
# Converte symbols para Arel::Nodes::Ordering
|
33
|
+
attribute = arel_table[attribute].asc if attribute.is_a?(Symbol)
|
34
|
+
|
35
|
+
if attribute.is_a?(Arel::Attributes::Attribute)
|
36
|
+
attribute = attribute.asc
|
37
|
+
end
|
38
|
+
|
39
|
+
if attribute.class < Arel::Nodes::Ordering
|
40
|
+
# Converte Arel::Nodes::Ordering para string com prefixo
|
41
|
+
# da tabela e quoted
|
42
|
+
arel_table.engine.connection.visitor.accept attribute
|
43
|
+
else
|
44
|
+
attribute
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
attributes = attributes.join(', ')
|
49
|
+
end
|
50
|
+
|
51
|
+
class_eval(<<-eoruby, __FILE__, __LINE__ + 1)
|
52
|
+
def self.ordered
|
53
|
+
query = order('#{attributes}')
|
54
|
+
|
55
|
+
#{"query = query.joins(:#{include_table})" if include_table.present?}
|
56
|
+
|
57
|
+
query
|
58
|
+
end
|
59
|
+
eoruby
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Filters
|
3
|
+
module Base
|
4
|
+
def scoped
|
5
|
+
@scoped ||= if association
|
6
|
+
klass.joins(association.name)
|
7
|
+
else
|
8
|
+
klass.all
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def association
|
13
|
+
@association ||= klass.reflect_on_association(options[:using]) if association?
|
14
|
+
end
|
15
|
+
|
16
|
+
def association?
|
17
|
+
options.key?(:using)
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_column(klass, name)
|
21
|
+
column_name = name.is_a?(Hash) ? name.keys.first : name
|
22
|
+
|
23
|
+
table_column = klass.arel_table.engine.columns.detect { |column| column.name.to_sym == column_name.to_sym }
|
24
|
+
|
25
|
+
column_struct(table_column, name) if table_column
|
26
|
+
end
|
27
|
+
|
28
|
+
def column_struct(column, name)
|
29
|
+
type = name.is_a?(Hash) ? name.values.first : column.type
|
30
|
+
relation = column.try :relation
|
31
|
+
|
32
|
+
OpenStruct.new(relation: relation,
|
33
|
+
name: column.name,
|
34
|
+
type: type)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Filters
|
3
|
+
class Filter
|
4
|
+
include ActiveRecord::Filters::Base
|
5
|
+
|
6
|
+
attr_accessor :klass
|
7
|
+
attr_accessor :attributes
|
8
|
+
attr_accessor :options
|
9
|
+
|
10
|
+
def initialize(klass, attributes, options)
|
11
|
+
self.klass = klass
|
12
|
+
self.attributes = attributes
|
13
|
+
self.options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(params)
|
17
|
+
relation = scoped
|
18
|
+
|
19
|
+
columns.inject(relation) do |relation, column|
|
20
|
+
# TODO: have a better way to compare this?
|
21
|
+
param = if association? && relation.arel_table != column.relation
|
22
|
+
key = "#{association.name}_attributes"
|
23
|
+
params[key][column.name] if params[key]
|
24
|
+
else
|
25
|
+
params[column.name]
|
26
|
+
end
|
27
|
+
|
28
|
+
next relation if param.blank?
|
29
|
+
|
30
|
+
column_name = klass.arel_table[column.name]
|
31
|
+
|
32
|
+
case column.type
|
33
|
+
when :string
|
34
|
+
relation.where(column_name.matches("#{param}%"))
|
35
|
+
when :decimal, :float, :integer
|
36
|
+
relation.where(column_name.eq(I18n::Alchemy::NumericParser.parse(param)))
|
37
|
+
when :time
|
38
|
+
# TODO: why arel uses arel/attributes/time for date columns?
|
39
|
+
relation.where(column_name.eq(I18n::Alchemy::DateParser.parse(param)))
|
40
|
+
else
|
41
|
+
relation.where(column_name.eq(param))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
protected
|
47
|
+
|
48
|
+
def columns
|
49
|
+
@columns ||= begin
|
50
|
+
columns = attributes.map do |attribute|
|
51
|
+
find_column(klass, attribute)
|
52
|
+
end
|
53
|
+
|
54
|
+
if association
|
55
|
+
columns += association.klass.accessible_attributes.map do |attribute|
|
56
|
+
find_column(association.klass, attribute)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
columns.compact
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Modal
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
class_attribute :_modal_attributes
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def attr_modal(*attributes)
|
11
|
+
self._modal_attributes = Set.new(attrs_map(*attributes)) + (_modal_attributes || [])
|
12
|
+
end
|
13
|
+
|
14
|
+
def modal_attributes
|
15
|
+
modal_attributes_with_options.map { |attr| attr.is_a?(Hash) ? attr.keys.first : attr }
|
16
|
+
end
|
17
|
+
|
18
|
+
def modal_attributes_with_options
|
19
|
+
_modal_attributes || allowed_modal_attributes
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def attrs_map(*attributes)
|
25
|
+
options = attributes.extract_options!
|
26
|
+
attributes = attributes.map(&:to_s)
|
27
|
+
|
28
|
+
options.stringify_keys!
|
29
|
+
|
30
|
+
attributes.tap { |attr| attr.push options if options.any? }
|
31
|
+
end
|
32
|
+
|
33
|
+
def allowed_modal_attributes
|
34
|
+
if respond_to?(:accessible_attributes)
|
35
|
+
accessible_attributes.to_set.reject do |a|
|
36
|
+
a.ends_with?('_attributes') || a.ends_with?('_ids')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# Atua como se fosse um belongs_to do active_record, mas ao invés de manter um
|
2
|
+
# relacionamento com um model do active_record, mantem um relacionamento com um
|
3
|
+
# model do active_resource.
|
4
|
+
#
|
5
|
+
# Ex:
|
6
|
+
#
|
7
|
+
# class BudgetStructure < ActiveResource::Base
|
8
|
+
# ...
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# class Contract < ActiveRecord::Base
|
12
|
+
# include BelongsToResource
|
13
|
+
#
|
14
|
+
# belongs_to_resource :budget_structure
|
15
|
+
# belongs_to_resource :budget_allocation
|
16
|
+
#
|
17
|
+
# private
|
18
|
+
#
|
19
|
+
# def budget_allocation_params
|
20
|
+
# { includes: :expense_nature, methods: :amount }
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# c = Contract.last
|
25
|
+
#
|
26
|
+
# c.budget_structure_id
|
27
|
+
# => 3
|
28
|
+
# c.buget_allocation.expense_nature.id
|
29
|
+
# => 1
|
30
|
+
# c.buget_allocation.amount
|
31
|
+
# => 500.0
|
32
|
+
#
|
33
|
+
# c.budget_structure
|
34
|
+
# => consulta faz find na API
|
35
|
+
# => <#BudgetStructure teste>
|
36
|
+
#
|
37
|
+
# c.budget_structure = BudgetStucture.last
|
38
|
+
# c.budget_structure
|
39
|
+
# => não precisa fazer consulta na API e já atualiza o id
|
40
|
+
# => <#BudgetStructure novo>
|
41
|
+
#
|
42
|
+
# c.budget_structure(false)
|
43
|
+
# => não usa o cache, ou seja força o find na API
|
44
|
+
# => <#BudgetStructure novo>
|
45
|
+
#
|
46
|
+
# c.budget_structure_id = 34
|
47
|
+
# c.budget_structure
|
48
|
+
# => vai fazer a consulta na API pra atualizar o cache, porque mudou o id
|
49
|
+
# => <#BudgetStructure outro>
|
50
|
+
module BelongsToResource
|
51
|
+
extend ActiveSupport::Concern
|
52
|
+
|
53
|
+
module ClassMethods
|
54
|
+
def belongs_to_resource(resource_name, options = {})
|
55
|
+
resource_class = options.fetch(:resource_class) { resource_name.to_s.camelize.constantize }
|
56
|
+
resource_id = options.fetch(:resource_id, "#{resource_name}_id")
|
57
|
+
|
58
|
+
create_reflection :belongs_to, resource_name, { foreign_key: resource_id }, self
|
59
|
+
|
60
|
+
send(:class_eval, <<-eoruby, __FILE__, __LINE__ + 1)
|
61
|
+
def #{resource_name}(use_cache = true)
|
62
|
+
return unless #{resource_id}
|
63
|
+
|
64
|
+
if use_cache
|
65
|
+
#{resource_name}_cached
|
66
|
+
else
|
67
|
+
#{resource_class}.find(#{resource_id}, params: #{resource_name}_params)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def #{resource_name}=(new_resource)
|
72
|
+
self.#{resource_id} = new_resource.try(:id)
|
73
|
+
self.old_#{resource_id} = #{resource_id}
|
74
|
+
self.#{resource_name}_cache = new_resource
|
75
|
+
end
|
76
|
+
|
77
|
+
def #{resource_id}=(new_id)
|
78
|
+
self.old_#{resource_id} = #{resource_id}
|
79
|
+
|
80
|
+
if self.class.superclass <= ActiveResource::Base
|
81
|
+
self.attributes[:#{resource_id}] = new_id
|
82
|
+
else
|
83
|
+
super
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
attr_accessor :old_#{resource_id}
|
90
|
+
attr_accessor :#{resource_name}_cache
|
91
|
+
|
92
|
+
def #{resource_name}_cached
|
93
|
+
if #{resource_id}
|
94
|
+
if old_#{resource_id} != #{resource_id}
|
95
|
+
self.#{resource_name}_cache = #{resource_class}.find(#{resource_id}, params: #{resource_name}_params)
|
96
|
+
self.old_#{resource_id} = #{resource_id}
|
97
|
+
end
|
98
|
+
else
|
99
|
+
self.#{resource_name}_cache = nil
|
100
|
+
end
|
101
|
+
|
102
|
+
#{resource_name}_cache
|
103
|
+
end
|
104
|
+
|
105
|
+
def #{resource_name}_params
|
106
|
+
{}
|
107
|
+
end
|
108
|
+
eoruby
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/lib/custom_data.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
module Unico
|
2
|
+
module CustomData
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def reload_custom_data
|
7
|
+
return unless custom_data
|
8
|
+
|
9
|
+
custom_data.each do |data|
|
10
|
+
define_method(data.method_name) do
|
11
|
+
custom_data[data.method_name]
|
12
|
+
end
|
13
|
+
|
14
|
+
if data.select?
|
15
|
+
define_method("#{data.method_name}_humanize") do
|
16
|
+
data.humanized_option(custom_data[data.method_name])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
define_method("#{data.method_name}=") do |value|
|
21
|
+
self.custom_data = custom_data.merge(data.method_name => value)
|
22
|
+
end
|
23
|
+
|
24
|
+
next unless data.modal?
|
25
|
+
define_method(data.normalized_data) do
|
26
|
+
if send(data.method_name).present?
|
27
|
+
data.modal_entity.classify.constantize.send(:find, send(data.method_name))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def custom_attributes
|
34
|
+
return unless custom_data
|
35
|
+
|
36
|
+
custom_data.map(&:method_name)
|
37
|
+
end
|
38
|
+
|
39
|
+
def custom_data
|
40
|
+
class_name = name.underscore
|
41
|
+
current_state = ::Prefecture.last.state_acronym
|
42
|
+
|
43
|
+
Customization.new(current_state, class_name).data
|
44
|
+
rescue
|
45
|
+
{}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def custom_data
|
50
|
+
attributes['custom_data'] || {}
|
51
|
+
end
|
52
|
+
|
53
|
+
def validate_custom_data
|
54
|
+
self.class.reload_custom_data
|
55
|
+
presence_validator
|
56
|
+
dependency_validator
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
delegate :normalized_data, to: :customization_data, allow_nil: true
|
62
|
+
|
63
|
+
def presence_validator
|
64
|
+
return unless self.class.custom_data
|
65
|
+
|
66
|
+
self.class.custom_data.each do |item|
|
67
|
+
date_validator(item)
|
68
|
+
|
69
|
+
next unless item.required && dependency_requirement_fulfilled?(item)
|
70
|
+
string_presence_validator(item)
|
71
|
+
numeric_presence_validator(item)
|
72
|
+
date_presence_validator(item)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def dependency_validator
|
77
|
+
self.class.custom_data.each do |item|
|
78
|
+
next unless item.dependency_name.present?
|
79
|
+
|
80
|
+
if send(item.method_name).present? && !dependency_requirement_fulfilled?(item)
|
81
|
+
errors.add(item.method_name.to_sym, :should_be_blank)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def dependency_requirement_fulfilled?(item)
|
87
|
+
return true if item.dependency_name.nil?
|
88
|
+
|
89
|
+
if item.dependency_value.present?
|
90
|
+
send(item.dependency_name) == item.dependency_value
|
91
|
+
else
|
92
|
+
send(item.dependency_name).present?
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def string_presence_validator(item)
|
97
|
+
return unless item.string? || item.text? || item.select? || item.modal?
|
98
|
+
|
99
|
+
if custom_data[item.method_name].nil? || custom_data[item.method_name].empty?
|
100
|
+
errors.add(item.normalized_data.to_sym, :blank)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def numeric_presence_validator(item)
|
105
|
+
return unless item.decimal? || item.integer?
|
106
|
+
|
107
|
+
if BigDecimal(custom_data[item.normalized_data] || '0') == BigDecimal('0')
|
108
|
+
errors.add(item.normalized_data.to_sym, :blank)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def date_presence_validator(item)
|
113
|
+
return unless item.date?
|
114
|
+
|
115
|
+
if custom_data[item.normalized_data].empty?
|
116
|
+
errors.add(item.normalized_data.to_sym, :blank)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def date_validator(item)
|
121
|
+
return unless item.date?
|
122
|
+
return if custom_data.blank?
|
123
|
+
|
124
|
+
begin
|
125
|
+
custom_data[item.normalized_data].to_date
|
126
|
+
rescue ArgumentError
|
127
|
+
errors.add(item.normalized_data.to_sym, :invalid)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|