interage-request 0.2.0 → 0.2.1

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: 83e4804dec76967fdc3a51551d2d7bbed163464544acacea44d74adedcb2f9f4
4
- data.tar.gz: cf05912afeeef17680c418babf304c47455b22617eca91b4c39759ba7ddfcf97
3
+ metadata.gz: 15230f74201e69eb0c6bff7855b00da6a604e3b4a67936e86e710aed76d16c24
4
+ data.tar.gz: 1b7720990fc7eebe2969ae87849b7c104b7f036e6da3762772a5676ec4c1abd4
5
5
  SHA512:
6
- metadata.gz: 8c28d57ab9fa9c4135fa0020abc8c5afcca732d53a5745f39a2f192fd2d82ea5a1cc7fa34fb4f9922fb6e612c066206da64b86707db7dc7a57ca012454000d7a
7
- data.tar.gz: 7fb7f13ed9f00f46ba954b603d399525c149e1515f87da99712aa2562e80dd1cda7322c3cf60d97a9aff4825a30a13391bafe29cfc1462b94d0a73b63d749a99
6
+ metadata.gz: bc3e902e3885513ee2d108d2c53c8aa661febd3e5a180592cf9566c21bded357a043d0b4cb4871efa8f94a7605e428e9967a89bee1e3233ce8922c7acd91e95e
7
+ data.tar.gz: 1a0b8b1e2f0292eefe40b50b707c426c50af2f55dd42a9214a2088a2ddebb5a5d6ea14d3cfcfec83812059969141393def99fb496e451bea859e7b9aa9346676
data/CHANGES CHANGED
@@ -1,3 +1,16 @@
1
+ Version 0.2.0:
2
+ - Cria binário de publicar gem
3
+ - Atualiza Documentação
4
+ - Ajusta binário do CI
5
+ - Altera url do repositório git
6
+ - Ajusta README
7
+ - Atualiza documentação
8
+ - Ajusta geradores e adiciona form
9
+ - Adiciona gem empacotadas no gitignore
10
+ - Refatora a classe ApplicationRequest
11
+ - Atualiza arquivo de versão
12
+ - Atualiza dependencias de desenvolvimento
13
+
1
14
  Version 0.1.3:
2
15
  - Altera arquivos VERSION e CHANGES para 0.1.3
3
16
  - Empacota nova versão da gem
data/Gemfile CHANGED
@@ -18,5 +18,5 @@ group :development, :test do
18
18
  # https://github.com/presidentbeef/brakeman
19
19
  gem 'brakeman', '~> 4.8', '>= 4.8.1', require: false
20
20
  # https://github.com/rails/rails/tree/master/activesupport#download-and-installation
21
- gem 'activesupport', '~> 5.2', '>= 5.2.4.2'
21
+ gem 'activesupport', '~> 6.0'
22
22
  end
@@ -1,16 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- interage-request (0.2.0)
4
+ interage-request (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activesupport (5.2.4.2)
9
+ activesupport (6.0.3.1)
10
10
  concurrent-ruby (~> 1.0, >= 1.0.2)
11
11
  i18n (>= 0.7, < 2)
12
12
  minitest (~> 5.1)
13
13
  tzinfo (~> 1.1)
14
+ zeitwerk (~> 2.2, >= 2.2.2)
14
15
  ast (2.4.0)
15
16
  brakeman (4.8.1)
16
17
  coderay (1.1.2)
@@ -20,7 +21,7 @@ GEM
20
21
  concurrent-ruby (~> 1.0)
21
22
  jaro_winkler (1.5.4)
22
23
  method_source (1.0.0)
23
- minitest (5.14.0)
24
+ minitest (5.14.1)
24
25
  parallel (1.19.1)
25
26
  parser (2.7.1.2)
26
27
  ast (~> 2.4.0)
@@ -60,12 +61,13 @@ GEM
60
61
  tzinfo (1.2.7)
61
62
  thread_safe (~> 0.1)
62
63
  unicode-display_width (1.7.0)
64
+ zeitwerk (2.3.0)
63
65
 
64
66
  PLATFORMS
65
67
  ruby
66
68
 
67
69
  DEPENDENCIES
68
- activesupport (~> 5.2, >= 5.2.4.2)
70
+ activesupport (~> 6.0)
69
71
  brakeman (~> 4.8, >= 4.8.1)
70
72
  bundler (~> 2.0)
71
73
  interage-request!
data/README.md CHANGED
@@ -36,16 +36,16 @@ class ApplicationRequest < ::Interage::ApplicationRequest
36
36
  end
37
37
  ```
38
38
 
39
- And `ApplicationForm`
39
+ And `ApplicationBuilder`
40
40
 
41
41
 
42
42
  ```ruby
43
- # app/models/application_form.rb
44
- class ApplicationForm < ::Interage::ApplicationForm
43
+ # app/builders/application_builder.rb
44
+ class ApplicationBuilder < ::Interage::ApplicationBuilder
45
45
  end
46
46
  ```
47
47
 
48
- To create a request and form classes you also can use a Rails generator:
48
+ To create a request and builder classes you also can use a Rails generator:
49
49
 
50
50
 
51
51
  ```bash
@@ -55,29 +55,52 @@ rails g interage:request:create store/order client_name payment_form
55
55
  This will create this classes:
56
56
 
57
57
  ```ruby
58
- # app/requests/orders_request.rb
58
+ # app/requests/store/base_request.rb
59
59
  module Store
60
- class OrdersRequest < ApplicationRequest
60
+ class BaseRequest < ::ApplicationRequest
61
61
  private
62
62
 
63
+ def api_base_url
64
+ "#{ENV.fetch('STORE_BASE_URL')}/v1/"
65
+ end
66
+
67
+ def headers
68
+ { 'Authorization-Token': ENV.fetch('STORE_AUTHORIZATION_TOKEN') }
69
+ end
70
+ end
71
+ end
72
+
73
+ # app/requests/store/orders_request.rb
74
+ module Store
75
+ class OrdersRequest < ::Store::BaseRequest
76
+ private
77
+
78
+ def key_name
79
+ :order
80
+ end
81
+
63
82
  def klass
64
83
  ::Store::Order
65
84
  end
66
85
  end
67
86
  end
68
87
 
69
- # app/models/order.rb
70
- class Order < ApplicationForm
71
- attr_accessor :client_name, :payment_form
88
+ # app/builders/store/order.rb
89
+ module Store
90
+ class Order < ApplicationBuilder
91
+ attr_accessor :client_name,
92
+ :payment_form
72
93
 
73
- def requester
74
- @requester ||= ::Store::OrderRequest.new
75
- end
94
+ def requester
95
+ @requester ||= ::Store::OrdersRequest.new
96
+ end
76
97
 
77
- private
98
+ private
78
99
 
79
- def changeable_attributes
80
- { client_name: client_name, payment_form: payment_form }
100
+ def changeable_attributes
101
+ { client_name: client_name,
102
+ payment_form: payment_form }
103
+ end
81
104
  end
82
105
  end
83
106
  ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.2.0
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ source config;
6
+
7
+ execute bin/ci;
8
+
9
+ execute release_start;
10
+
11
+ CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`;
12
+ RELEASE_VERSION=${CURRENT_BRANCH##*/v};
13
+
14
+ execute gem build interage-request.gemspec;
15
+
16
+ execute gem push interage-request-${RELEASE_VERSION}.gem;
17
+
18
+ execute release_finish;
@@ -2,7 +2,9 @@ Description:
2
2
  Explain the generator
3
3
 
4
4
  Example:
5
- rails g interage:request:create ClientsByDocument Client
5
+ rails g interage:request:create store/order client_name payment_form
6
6
 
7
7
  This will create:
8
- /app/requests/clients_by_document_request.rb
8
+ /app/requests/store/base_request.rb
9
+ /app/requests/store/orders_request.rb
10
+ /app/builders/order.rb
@@ -6,58 +6,119 @@ module Interage
6
6
  class CreateGenerator < Rails::Generators::NamedBase
7
7
  source_root File.expand_path('templates', __dir__)
8
8
 
9
- desc 'Generates a request and form.'
9
+ desc 'Generates a request and builder.'
10
10
 
11
11
  def initialize(args, *_options)
12
12
  super
13
13
 
14
- @form_filename = args.first
15
- first_arg = form_filename.split('/')
16
- @modulu = first_arg.shift.camelize if first_arg.size > 1
17
- @form_name = first_arg.join('/').camelize
18
- @form_fullname = "/#{form_filename}".camelize
19
- @request_filename = "#{form_filename}_request"
14
+ @tab = ' '
15
+ @arguments = args
16
+ @request_param = arguments.shift.to_s.underscore
20
17
  end
21
18
 
22
19
  def create_request
23
- create_file(new_request_file, sample_request_file)
20
+ if create_base_request?
21
+ template('base_request.rb', new_base_request_file)
22
+ end
24
23
 
25
- create_file(new_form_file, sample_form_file)
24
+ template('request.rb', new_request_file)
25
+
26
+ template('builder.rb', new_builder_file)
26
27
  end
27
28
 
28
29
  private
29
30
 
30
- attr_reader :modulu, :form_filename, :form_name, :form_fullname,
31
- :request_filename, :request_name
31
+ attr_reader :tab, :arguments, :request_param
32
+
33
+ def create_base_request?
34
+ !File.exist?(new_base_request_file) && modulu_exists?
35
+ end
36
+
37
+ def new_base_request_file
38
+ Rails.root.join("app/requests/#{base_request_path}.rb")
39
+ end
40
+
41
+ def base_request_path
42
+ "#{main_modulu.underscore}/base_request"
43
+ end
32
44
 
33
45
  def new_request_file
34
- Rails.root.join("app/requests/#{request_filename}.rb")
46
+ Rails.root.join("app/requests/#{request_path}.rb")
47
+ end
48
+
49
+ def request_path
50
+ @request_path ||= begin
51
+ path =
52
+ request_param.gsub(prefix_class_name, prefix_class_name.pluralize)
53
+ "#{path}_request"
54
+ end
55
+ end
56
+
57
+ def request_class
58
+ @request_class ||= request_path.split('/').last.camelize
59
+ end
60
+
61
+ def request_full_class
62
+ (modulus + [request_class]).join('::')
63
+ end
64
+
65
+ def new_builder_file
66
+ Rails.root.join("app/builders/#{prefix_class_name}.rb")
35
67
  end
36
68
 
37
- def sample_request_file
38
- file = modulu.blank? ? 'request' : 'request_namespace'
69
+ def builder_class
70
+ @builder_class ||= builder_full_class.split('::').last
71
+ end
72
+
73
+ def builder_full_class
74
+ @builder_full_class ||= prefix_class_name.camelize
75
+ end
76
+
77
+ def builder_accessors
78
+ ":#{arguments.join(",\n#{tabs(modulus.count + 8)}:")}"
79
+ end
80
+
81
+ def builder_changeable_attributes
82
+ arguments.map { |argument| "#{argument}: #{argument}" }
83
+ .join(",\n#{tabs(modulus.count + 3)}")
84
+ end
39
85
 
40
- File.read(File.expand_path("templates/#{file}.rb", __dir__))
41
- .gsub('{{REQUEST_NAME}}', "#{form_name}Request".camelize)
42
- .gsub('{{FORM_NAME}}', form_fullname)
43
- .gsub('{{MODULU}}', modulu)
86
+ def request_extend_class
87
+ modulu_exists? ? base_request_path.camelize : 'ApplicationRequest'
44
88
  end
45
89
 
46
- def new_form_file
47
- Rails.root.join("app/forms/#{form_filename}.rb")
90
+ def modulu_exists?
91
+ main_modulu.present?
48
92
  end
49
93
 
50
- def sample_form_file
51
- file = modulu.blank? ? 'form' : 'form_namespace'
94
+ def main_modulu
95
+ modulus.first.to_s
96
+ end
97
+
98
+ def modulus_init
99
+ 0.upto(modulus.count - 1).map do |i|
100
+ "#{tabs(i)}module #{modulus[i]}"
101
+ end
102
+ end
103
+
104
+ def modules_end
105
+ modulus.count.downto(1).map { |i| "#{tabs(i - 1)}end" }
106
+ end
107
+
108
+ def modulus
109
+ @modulus ||= begin
110
+ names = builder_full_class.split('::')
111
+
112
+ names.take(names.count - 1)
113
+ end
114
+ end
52
115
 
53
- File.read(File.expand_path("templates/#{file}.rb", __dir__))
54
- .gsub('{{FORM_ATTRIBUTES}}', form_attributes)
55
- .gsub('{{FORM_NAME}}', form_name)
56
- .gsub('{{MODULU}}', modulu)
116
+ def tabs(size = nil)
117
+ tab * (size || modulus.count).to_i
57
118
  end
58
119
 
59
- def form_attributes
60
- ":#{@args.join(', :')}"
120
+ def prefix_class_name
121
+ @prefix_class_name ||= request_param.split('_by_').first
61
122
  end
62
123
  end
63
124
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module <%= main_modulu %>
4
+ class BaseRequest < ::ApplicationRequest
5
+ private
6
+
7
+ def api_base_url
8
+ "#{ENV.fetch('<%= main_modulu.upcase %>_BASE_URL')}/v1/"
9
+ end
10
+
11
+ def headers
12
+ { 'Authorization-Token': ENV.fetch('<%= main_modulu.upcase %>_AUTHORIZATION_TOKEN') }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ <%= "\n#{modulus_init.join("\n")}" if modulu_exists? %>
3
+ <%= tabs %>class <%= builder_class %> < ApplicationBuilder
4
+ <%= tabs %> attr_accessor <%= builder_accessors %>
5
+
6
+ <%= tabs %> def requester
7
+ <%= tabs %> @requester ||= ::<%= request_full_class %>.new
8
+ <%= tabs %> end
9
+
10
+ <%= tabs %> private
11
+
12
+ <%= tabs %> def changeable_attributes
13
+ <%= tabs %> { <%= builder_changeable_attributes %> }
14
+ <%= tabs %> end
15
+ <%= tabs %>end<%= "\n#{modules_end.join("\n")}" if modulu_exists? %>
@@ -1,9 +1,13 @@
1
1
  # frozen_string_literal: true
2
+ <%= "\n#{modulus_init.join("\n")}" if modulu_exists? %>
3
+ <%= tabs %>class <%= request_class %> < ::<%= request_extend_class %>
4
+ <%= tabs %> private
2
5
 
3
- class {{REQUEST_NAME}} < ApplicationRequest
4
- private
6
+ <%= tabs %> def key_name
7
+ <%= tabs %> :<%= builder_class.underscore %>
8
+ <%= tabs %> end
5
9
 
6
- def klass
7
- {{FORM_NAME}}
8
- end
9
- end
10
+ <%= tabs %> def klass
11
+ <%= tabs %> ::<%= builder_full_class %>
12
+ <%= tabs %> end
13
+ <%= tabs %>end<%= "\n#{modules_end.join("\n")}" if modulu_exists? %>
@@ -6,3 +6,4 @@ Example:
6
6
 
7
7
  This will create:
8
8
  /app/requests/application_request.rb
9
+ /app/builders/application_builder.rb
@@ -10,7 +10,7 @@ module Interage
10
10
  def create_application_request
11
11
  copy_file('application_request.rb', application_request_path)
12
12
 
13
- copy_file('application_form.rb', application_form_path)
13
+ copy_file('application_builder.rb', application_builder_path)
14
14
  end
15
15
 
16
16
  private
@@ -19,8 +19,8 @@ module Interage
19
19
  Rails.root.join('app/requests/application_request.rb')
20
20
  end
21
21
 
22
- def application_form_path
23
- Rails.root.join('app/forms/application_form.rb')
22
+ def application_builder_path
23
+ Rails.root.join('app/builders/application_builder.rb')
24
24
  end
25
25
  end
26
26
  end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationBuilder < ::Interage::ApplicationBuilder
4
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Interage
4
- class ApplicationForm < ::Interage::Request::Form
4
+ class ApplicationBuilder < ::Interage::Request::Builder
5
5
  def self.paginate(*args)
6
6
  new.requester.paginate(*args)
7
7
  end
@@ -9,10 +9,10 @@ module Interage
9
9
  end
10
10
 
11
11
  autoload :Base, 'interage/request/base'
12
- autoload :Form, 'interage/request/form'
12
+ autoload :Builder, 'interage/request/builder'
13
13
  autoload :Start, 'interage/request/start'
14
14
  end
15
15
 
16
- autoload :ApplicationForm, 'interage/application_form'
16
+ autoload :ApplicationBuilder, 'interage/application_builder'
17
17
  autoload :ApplicationRequest, 'interage/application_request'
18
18
  end
@@ -43,7 +43,7 @@ module Interage
43
43
  end
44
44
 
45
45
  def klass
46
- Interage::Request::Form
46
+ Interage::Request::Builder
47
47
  end
48
48
 
49
49
  def get(*args)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Interage
4
4
  module Request
5
- class Form
5
+ class Builder
6
6
  include ActiveModel::Model
7
7
 
8
8
  attr_accessor :id, :created_at, :updated_at
@@ -18,7 +18,11 @@ module Interage
18
18
  end
19
19
 
20
20
  def perform
21
- @response = http.start { |h| h.request(request) }
21
+ @response = Net::HTTP.start(uri.host, uri.port) do |http|
22
+ http.use_ssl = true if ssl?
23
+
24
+ http.request(request)
25
+ end
22
26
 
23
27
  self
24
28
  end
@@ -50,10 +54,6 @@ module Interage
50
54
 
51
55
  alias ssl? ssl
52
56
 
53
- def http
54
- @http ||= Net::HTTP.new(uri.hostname, uri.port, use_ssl: ssl?)
55
- end
56
-
57
57
  def request
58
58
  @request ||= begin
59
59
  request = klass.new(uri)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Interage
4
4
  module Request
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interage-request
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Walmir Neto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-17 00:00:00.000000000 Z
11
+ date: 2020-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,25 +73,25 @@ files:
73
73
  - bin/bundle
74
74
  - bin/ci
75
75
  - bin/console
76
+ - bin/publish
76
77
  - bin/rspec
77
78
  - bin/rubocop
78
79
  - bin/setup
79
80
  - interage-request.gemspec
80
81
  - lib/generators/interage/request/create/USAGE
81
82
  - lib/generators/interage/request/create/create_generator.rb
82
- - lib/generators/interage/request/create/templates/form.rb
83
- - lib/generators/interage/request/create/templates/form_namespace.rb
83
+ - lib/generators/interage/request/create/templates/base_request.rb
84
+ - lib/generators/interage/request/create/templates/builder.rb
84
85
  - lib/generators/interage/request/create/templates/request.rb
85
- - lib/generators/interage/request/create/templates/request_namespace.rb
86
86
  - lib/generators/interage/request/install/USAGE
87
87
  - lib/generators/interage/request/install/install_generator.rb
88
- - lib/generators/interage/request/install/templates/application_form.rb
88
+ - lib/generators/interage/request/install/templates/application_builder.rb
89
89
  - lib/generators/interage/request/install/templates/application_request.rb
90
- - lib/interage/application_form.rb
90
+ - lib/interage/application_builder.rb
91
91
  - lib/interage/application_request.rb
92
92
  - lib/interage/request.rb
93
93
  - lib/interage/request/base.rb
94
- - lib/interage/request/form.rb
94
+ - lib/interage/request/builder.rb
95
95
  - lib/interage/request/start.rb
96
96
  - lib/interage/request/version.rb
97
97
  homepage: https://github.com/InterageASH/application-request
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubygems_version: 3.0.6
120
+ rubygems_version: 3.0.8
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Application Request for Interage
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class {{FORM_NAME}} < ApplicationForm
4
- attr_accessor {{FORM_ATTRIBUTES}}
5
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module {{MODULU}}
4
- class {{FORM_NAME}} < ApplicationForm
5
- attr_accessor {{FORM_ATTRIBUTES}}
6
- end
7
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module {{MODULU}}
4
- class {{REQUEST_NAME}} < ApplicationRequest
5
- private
6
-
7
- def klass
8
- {{FORM_NAME}}
9
- end
10
- end
11
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class ApplicationForm < ::Interage::ApplicationForm
4
- end