pakyow-core 1.0.0.rc3 → 1.0.0.rc4

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: 12e96f8e6d8402b05a724cf25346153e3dd6e983a781553b048f5f22ee5f9658
4
- data.tar.gz: 34981bf9cb7538249e849bdf3974ab610e11beb47a780b51deb16663478cd926
3
+ metadata.gz: a2459ddb34a6178feacae487fae09c9c63da79c6bc2e972c9f87a5b62eef5223
4
+ data.tar.gz: dced9f2b9edfacb5d882974dc5d75f00bb5a6530d4c80557f3887dd3f6caadd6
5
5
  SHA512:
6
- metadata.gz: d681b76e4c741396812704e3af8b548f6e6d400985cd27c8bafbd59ae3597c5aa799981a2b99ed65f1bc161d41e8bfbe15c0dc1dab4c9e96e818bfbe25621efb
7
- data.tar.gz: 8596bc0d9d783cf15af6178b0f4acaf681c1decf56ecfffd1da1a8b209a4a4c704d9050f165d2de7c7534f1a4b7e0af36c7bff525533c487e744bd1949f183ed
6
+ metadata.gz: 2b992515ae92571231c20dad536fb82fb22b750a0b72bc4fc01742787610d7977c39da170347a28ab2bad0b14d4a9cf683b38552b4c48320e094ea186daf19ac
7
+ data.tar.gz: '029912f307a40c71748e4103f7fec56b1bfef1a6e8ce8807bb4d2fc7dd8b3b76e35afa7bf1ffb128f9afd858001c77c95e2dcf194096213b006ae93813828eed'
data/lib/pakyow/app.rb CHANGED
@@ -188,7 +188,7 @@ module Pakyow
188
188
  app_connection = isolated(:Connection).new(self, connection)
189
189
  super(app_connection)
190
190
  rescue => error
191
- if respond_to?(:controller_for_connection) && controller = controller_for_connection(app_connection)
191
+ if app_connection && respond_to?(:controller_for_connection) && controller = controller_for_connection(app_connection)
192
192
  controller.handle_error(error)
193
193
  else
194
194
  raise error
@@ -6,7 +6,7 @@ module Pakyow
6
6
  class App
7
7
  class Connection
8
8
  module Session
9
- class Abstract < DelegateClass(Support::IndifferentHash)
9
+ class Base < DelegateClass(Support::IndifferentHash)
10
10
  def initialize(connection, options, values = Support::IndifferentHash.new)
11
11
  @connection, @options = connection, options
12
12
  super(values)
@@ -5,13 +5,13 @@ require "base64"
5
5
  require "pakyow/support/indifferentize"
6
6
  require "pakyow/support/message_verifier"
7
7
 
8
- require "pakyow/app/connection/session/abstract"
8
+ require "pakyow/app/connection/session/base"
9
9
 
10
10
  module Pakyow
11
11
  class App
12
12
  class Connection
13
13
  module Session
14
- class Cookie < Abstract
14
+ class Cookie < Base
15
15
  def initialize(connection, options)
16
16
  if (cookie = connection.cookies[options.name]) && cookie.is_a?(Support::IndifferentHash)
17
17
  super(connection, options, Support::IndifferentHash.new(cookie[:value].to_h))
@@ -125,9 +125,9 @@ module Pakyow
125
125
  class_state :tasks, default: []
126
126
  class_state :mounts, default: []
127
127
  class_state :frameworks, default: {}
128
- class_state :booted, default: false, getter: false
129
- class_state :server, default: nil, getter: false
130
- class_state :env, default: nil, getter: false
128
+ class_state :booted, default: false, reader: false
129
+ class_state :server, default: nil, reader: false
130
+ class_state :env, default: nil, reader: false
131
131
  class_state :setup_error, default: nil
132
132
 
133
133
  class << self
data/lib/pakyow/plugin.rb CHANGED
@@ -260,7 +260,7 @@ module Pakyow
260
260
  #
261
261
  @parent.endpoints << Endpoint.new(
262
262
  name: [config.name.to_s, endpoint.name].join("_"),
263
- method: :get,
263
+ method: endpoint.method,
264
264
  builder: endpoint.builder
265
265
  )
266
266
 
@@ -276,7 +276,7 @@ module Pakyow
276
276
 
277
277
  @parent.endpoints << Endpoint.new(
278
278
  name: endpoint_name,
279
- method: :get,
279
+ method: endpoint.method,
280
280
  builder: endpoint.builder
281
281
  )
282
282
  end
@@ -19,10 +19,6 @@ module Pakyow
19
19
  module Acceptance
20
20
  using Support::Refinements::Array::Ensurable
21
21
 
22
- def self.name
23
- :acceptance
24
- end
25
-
26
22
  def self.message(**)
27
23
  "must be accepted"
28
24
  end
@@ -32,6 +28,6 @@ module Pakyow
32
28
  end
33
29
  end
34
30
 
35
- Validator.register_validation(Acceptance)
31
+ Validator.register_validation(Acceptance, :acceptance)
36
32
  end
37
33
  end
@@ -10,10 +10,6 @@ module Pakyow
10
10
  module Email
11
11
  REGEX = /\A[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\z/i
12
12
 
13
- def self.name
14
- :email
15
- end
16
-
17
13
  def self.message(**)
18
14
  "must be a valid email address"
19
15
  end
@@ -23,6 +19,6 @@ module Pakyow
23
19
  end
24
20
  end
25
21
 
26
- Validator.register_validation(Email)
22
+ Validator.register_validation(Email, :email)
27
23
  end
28
24
  end
@@ -8,10 +8,6 @@ module Pakyow
8
8
  #
9
9
  # @api public
10
10
  module Length
11
- def self.name
12
- :length
13
- end
14
-
15
11
  def self.message(minimum: nil, maximum: nil, **)
16
12
  if minimum && maximum
17
13
  "must have between #{minimum} and #{maximum} characters"
@@ -39,6 +35,6 @@ module Pakyow
39
35
  end
40
36
  end
41
37
 
42
- Validator.register_validation(Length)
38
+ Validator.register_validation(Length, :length)
43
39
  end
44
40
  end
@@ -15,10 +15,6 @@ module Pakyow
15
15
  #
16
16
  # @api public
17
17
  module Presence
18
- def self.name
19
- :presence
20
- end
21
-
22
18
  def self.message(**)
23
19
  "cannot be blank"
24
20
  end
@@ -34,6 +30,6 @@ module Pakyow
34
30
  end
35
31
  end
36
32
 
37
- Validator.register_validation(Presence)
33
+ Validator.register_validation(Presence, :presence)
38
34
  end
39
35
  end
@@ -1,13 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "pakyow/support/class_state"
4
+ require "pakyow/support/extension"
4
5
 
5
6
  require "pakyow/errors"
6
7
 
7
8
  module Pakyow
8
9
  class Validator
9
10
  class Result
10
- def initialize
11
+ def initialize(key)
12
+ @key = key
11
13
  @errors = []
12
14
  end
13
15
 
@@ -19,9 +21,12 @@ module Pakyow
19
21
  @errors.empty?
20
22
  end
21
23
 
22
- def messages
24
+ def messages(type: :default)
23
25
  @errors.map { |validation, options|
24
- options[:message] || validation.message(**options)
26
+ Verifier.formatted_message(
27
+ (options[:message] || validation.message(**options)),
28
+ type: type, key: @key
29
+ )
25
30
  }
26
31
  end
27
32
  end
@@ -30,8 +35,8 @@ module Pakyow
30
35
  class_state :validation_objects, default: {}
31
36
 
32
37
  class << self
33
- def register_validation(validation_object)
34
- @validation_objects[validation_object.name] = validation_object
38
+ def register_validation(validation_object, validation_name)
39
+ @validation_objects[validation_name] = validation_object
35
40
  end
36
41
 
37
42
  # @api private
@@ -68,7 +73,7 @@ module Pakyow
68
73
  end
69
74
 
70
75
  def call(values, context: nil)
71
- result = Result.new
76
+ result = Result.new(@key)
72
77
 
73
78
  @validations.each do |validation, options|
74
79
  unless validation.valid?(values, key: @key, context: context, **options)
@@ -38,18 +38,20 @@ module Pakyow
38
38
  !@validation.nil?
39
39
  end
40
40
 
41
- def messages
41
+ def messages(type: :default)
42
42
  if validating?
43
- messages = @validation.messages
43
+ messages = @validation.messages(type: type)
44
44
  else
45
45
  messages = {}
46
46
 
47
47
  @errors.each_pair do |key, value|
48
- messages[key] = value
48
+ messages[key] = value.map { |each_value|
49
+ Verifier.formatted_message(each_value, type: type, key: key)
50
+ }
49
51
  end
50
52
 
51
53
  @nested.each_pair do |key, verifier|
52
- nested_messages = verifier.messages
54
+ nested_messages = verifier.messages(type: type)
53
55
 
54
56
  unless nested_messages.empty?
55
57
  messages[key] = nested_messages
@@ -61,6 +63,19 @@ module Pakyow
61
63
  end
62
64
  end
63
65
 
66
+ class << self
67
+ def formatted_message(message, type:, key:)
68
+ case type
69
+ when :full
70
+ "#{key} #{message}"
71
+ when :presentable
72
+ "#{Support.inflector.humanize(key)} #{message}"
73
+ else
74
+ message
75
+ end
76
+ end
77
+ end
78
+
64
79
  using Support::Refinements::Array::Ensurable
65
80
 
66
81
  extend Forwardable
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pakyow-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc3
4
+ version: 1.0.0.rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: commands
11
11
  cert_chain: []
12
- date: 2019-07-09 00:00:00.000000000 Z
12
+ date: 2019-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pakyow-support
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 1.0.0.rc3
20
+ version: 1.0.0.rc4
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '='
26
26
  - !ruby/object:Gem::Version
27
- version: 1.0.0.rc3
27
+ version: 1.0.0.rc4
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: async
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -210,7 +210,7 @@ files:
210
210
  - lib/pakyow/app/connection/behavior/session.rb
211
211
  - lib/pakyow/app/connection/behavior/values.rb
212
212
  - lib/pakyow/app/connection/behavior/verifier.rb
213
- - lib/pakyow/app/connection/session/abstract.rb
213
+ - lib/pakyow/app/connection/session/base.rb
214
214
  - lib/pakyow/app/connection/session/cookie.rb
215
215
  - lib/pakyow/behavior/aspects.rb
216
216
  - lib/pakyow/behavior/config.rb