boa_vista_stubs 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a39d77263a372d3ad85a2629aa6c5e161a88df54
4
+ data.tar.gz: cae104b70b931f5ff4aa3f39046f2f12132d0f16
5
+ SHA512:
6
+ metadata.gz: 08d09d2d7cccbb03889e288b0ac4ee46481a666f4cb09b71d1793d655e443d12b8334f622e837f6ba0f8361764ec046bbcc433cea1ed38d04ebede1db8fe8e4b
7
+ data.tar.gz: cde5a5a3d29df6de626298ad9f0e4621864edd84cae6c8b5c4050fb9990f26f9c183669221f818c2392b62bfdeca765d1538a7f603a4f6c636eefb782f17519f
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Kleber Shimabuku
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = BoaVistaStubs
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'BoaVistaStubs'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ module BoaVistaStubs
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ module BoaVistaStubs
2
+ class RequestsController < BoaVistaStubs::ApplicationController
3
+ def index
4
+ # Returns a Document::CPF or Document::CNPJ instance
5
+ document = Document.identify(params[:consulta])
6
+
7
+ log("Start validating document type: #{document.document_type}")
8
+
9
+ if document.valid?
10
+ log("document number: #{document.document_number} is valid.")
11
+ render text: document_response(document.document_type).valid
12
+ else
13
+ log("document number: #{document.document_number} is invalid.")
14
+ render text: document_response(document.document_type).invalid
15
+ end
16
+ end
17
+
18
+ protected
19
+
20
+ def document_response(document_type)
21
+ Document::Response.new(document_type)
22
+ end
23
+
24
+ def log(message)
25
+ Rails.logger.info("[BoaVistaStubs] - #{message}")
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ module BoaVistaStubs
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,27 @@
1
+ module BoaVistaStubs
2
+ class Document::CNPJ
3
+ attr_reader :document_number
4
+
5
+ def initialize(document_number)
6
+ @document_number = document_number
7
+ end
8
+
9
+ def valid?
10
+ allowed.include?(@document_number)
11
+ end
12
+
13
+ def invalid?
14
+ !valid?
15
+ end
16
+
17
+ def document_type
18
+ :CNPJ
19
+ end
20
+
21
+ protected
22
+
23
+ def allowed
24
+ BoaVistaStubs.configuration.valid_cnpj
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ module BoaVistaStubs
2
+ class Document::CPF
3
+ attr_reader :document_number
4
+
5
+ def initialize(document_number)
6
+ @document_number = document_number.slice(3..-1)
7
+ end
8
+
9
+ def valid?
10
+ allowed.include?(@document_number)
11
+ end
12
+
13
+ def invalid?
14
+ !valid?
15
+ end
16
+
17
+ def document_type
18
+ :CPF
19
+ end
20
+
21
+ protected
22
+
23
+ def allowed
24
+ BoaVistaStubs.configuration.valid_cpf
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,35 @@
1
+ module BoaVistaStubs
2
+ class Document::Response
3
+ LAYOUTS = {
4
+ :CPF => {
5
+ valid: 221,
6
+ invalid: 999
7
+ },
8
+ :CNPJ => {
9
+ valid: 138,
10
+ invalid: 901
11
+ }
12
+ }
13
+
14
+ def initialize(document_type)
15
+ @document_type = document_type
16
+ @layout = LAYOUTS[@document_type]
17
+ end
18
+
19
+ def valid
20
+ log("Layout: #{@layout[:valid]}")
21
+ BoaVista::Fixtures.read("layout_#{@layout[:valid]}.txt")[0]
22
+ end
23
+
24
+ def invalid
25
+ log("Layout: #{@layout[:invalid]}")
26
+ BoaVista::Fixtures.read("layout_#{@layout[:invalid]}.txt")[0]
27
+ end
28
+
29
+ protected
30
+
31
+ def log(message)
32
+ Rails.logger.info("[BoaVistaStubs] - #{message}")
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,36 @@
1
+ module BoaVistaStubs
2
+ class Document
3
+
4
+ TYPES = {
5
+ '1' => :CPF,
6
+ '2' => :CNPJ
7
+ }.freeze
8
+
9
+ def self.identify(consulta_params)
10
+ new(consulta_params).identify
11
+ end
12
+
13
+ attr_reader :consulta_params
14
+
15
+ def initialize(consulta_params)
16
+ @consulta_params = consulta_params
17
+ end
18
+
19
+ def identify
20
+ klass = "BoaVistaStubs::Document::#{document_type}".constantize
21
+
22
+ klass.new(document_number)
23
+ end
24
+
25
+ protected
26
+
27
+ def document_number
28
+ @consulta_params.slice(69..82)
29
+ end
30
+
31
+ def document_type
32
+ TYPES[@consulta_params.slice(68..68)]
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>BoaVistaStubs</title>
5
+ <%= stylesheet_link_tag "boa_vista_stubs/application", media: "all" %>
6
+ <%= javascript_include_tag "boa_vista_stubs/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ BoaVistaStubs::Engine.routes.draw do
2
+ get '/stub', to: 'requests#index'
3
+ end
@@ -0,0 +1,5 @@
1
+ module BoaVistaStubs
2
+ class Configuration
3
+ attr_accessor :valid_cpf, :valid_cnpj
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'rails'
2
+
3
+ module BoaVistaStubs
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace BoaVistaStubs
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module BoaVistaStubs
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ require 'boa_vista_stubs/engine'
2
+ require 'boa_vista_stubs/configuration'
3
+
4
+ require 'boa_vista'
5
+ require 'boa_vista/fixtures'
6
+
7
+ module BoaVistaStubs
8
+ class << self
9
+ attr_reader :configuration
10
+ end
11
+
12
+ def self.configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+
16
+ def self.reset
17
+ @configuration = Configuration.new
18
+ end
19
+
20
+ def self.configure
21
+ yield(configuration)
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :boa_vista_stubs do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boa_vista_stubs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kleber Shimabuku
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.22
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.22
27
+ - !ruby/object:Gem::Dependency
28
+ name: boa_vista
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: BoaVistaStubs.
84
+ email:
85
+ - klebershimabuku@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - MIT-LICENSE
91
+ - README.rdoc
92
+ - Rakefile
93
+ - app/assets/javascripts/boa_vista_stubs/application.js
94
+ - app/assets/stylesheets/boa_vista_stubs/application.css
95
+ - app/controllers/boa_vista_stubs/application_controller.rb
96
+ - app/controllers/boa_vista_stubs/requests_controller.rb
97
+ - app/helpers/boa_vista_stubs/application_helper.rb
98
+ - app/models/boa_vista_stubs/document.rb
99
+ - app/models/boa_vista_stubs/document/cnpj.rb
100
+ - app/models/boa_vista_stubs/document/cpf.rb
101
+ - app/models/boa_vista_stubs/document/response.rb
102
+ - app/views/layouts/boa_vista_stubs/application.html.erb
103
+ - config/routes.rb
104
+ - lib/boa_vista_stubs.rb
105
+ - lib/boa_vista_stubs/configuration.rb
106
+ - lib/boa_vista_stubs/engine.rb
107
+ - lib/boa_vista_stubs/version.rb
108
+ - lib/tasks/boa_vista_stubs_tasks.rake
109
+ homepage: https://github.com/klebershimabuku/boa_vista_stubs
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.4.6
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: BoaVistaStubs.
133
+ test_files: []