polist 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d15ac52b24c1883fb0451e9fbe6f9b2d39ae90b
4
- data.tar.gz: 7f25436cea33059f9eb79f81dc54e34ddade7631
3
+ metadata.gz: 553f882315c30d976b80ff25c0b94b3375cf09b2
4
+ data.tar.gz: 93d2e330621e78e12d6c3e9f795ed4f96f974ce7
5
5
  SHA512:
6
- metadata.gz: d6d28e8018957ebdab190abba767b3cd08872478337a5a839190335be2f1eb89c9ac8c4e8f6b11d06f292710b5901e21acd294a51167ccf00364484a03824c00
7
- data.tar.gz: 122c0fe7ac27d0c2153f4a74dcf5f191b9b545534c25dfad6b45910bd17a4f69ee1b003cebbdd6ea4bf72489b37cf5c52d0823dff66094e806692624d652f4a0
6
+ metadata.gz: 68ae4882f299838b62632e67f4b66048689c99c65e871fa77ae74dacb4c5690c079ac8e15a01d836393435d91a43e20cf53c918158b9de313861874a8ebb0f93
7
+ data.tar.gz: 6128535be8447deb5c5d1cb36deac5a9b3731bd1f1649a513050b5579c65a0c8a33362d372abb09946da5f525ffa99a6d4d94bfaeffe80bed310a15dc6b3e2fa
@@ -4,85 +4,87 @@ require "active_model/validations"
4
4
  require "plissken"
5
5
  require "tainbox"
6
6
 
7
- class Polist::Service
8
- class Failure < StandardError
9
- attr_accessor :response
10
-
11
- def initialize(response)
12
- self.response = response
13
- super
7
+ module Polist
8
+ class Service
9
+ class Failure < StandardError
10
+ attr_accessor :response
11
+
12
+ def initialize(response)
13
+ self.response = response
14
+ super
15
+ end
14
16
  end
15
- end
16
17
 
17
- class Form
18
- include Tainbox
19
- include ActiveModel::Validations
20
- end
18
+ class Form
19
+ include Tainbox
20
+ include ActiveModel::Validations
21
+ end
21
22
 
22
- attr_accessor :params
23
+ attr_accessor :params
23
24
 
24
- def self.call(*args)
25
- build(*args).tap(&:call)
26
- end
25
+ def self.call(*args)
26
+ build(*args).tap(&:call)
27
+ end
27
28
 
28
- def self.run(*args)
29
- build(*args).tap(&:run)
30
- end
29
+ def self.run(*args)
30
+ build(*args).tap(&:run)
31
+ end
31
32
 
32
- def self.param(*names)
33
- names.each do |name|
34
- define_method(name) { params.fetch(name) }
33
+ def self.param(*names)
34
+ names.each do |name|
35
+ define_method(name) { params.fetch(name) }
36
+ end
35
37
  end
36
- end
37
38
 
38
- def initialize(params)
39
- self.params = params
40
- end
39
+ def initialize(params)
40
+ self.params = params
41
+ end
41
42
 
42
- def call; end # Should be implemented in subclasses
43
+ def call; end # Should be implemented in subclasses
43
44
 
44
- def run
45
- call
46
- rescue Failure => error
47
- @response = error.response
48
- @failure = true
49
- end
45
+ def run
46
+ call
47
+ rescue Failure => error
48
+ @response = error.response
49
+ @failure = true
50
+ end
50
51
 
51
- def response
52
- @response ||= {}
53
- end
52
+ def response
53
+ @response ||= {}
54
+ end
54
55
 
55
- def failure?
56
- !!@failure
57
- end
56
+ def failure?
57
+ !!@failure
58
+ end
58
59
 
59
- def success?
60
- !failure?
61
- end
60
+ def success?
61
+ !failure?
62
+ end
62
63
 
63
- def validate!
64
- error!(form.errors.to_h.values.first) unless form.valid?
65
- end
64
+ def validate!
65
+ error!(form.errors.to_h.values.first) unless form.valid?
66
+ end
66
67
 
67
- private
68
+ private
68
69
 
69
- def form
70
- @form ||= self.class::Form.new(form_attributes.to_snake_keys)
71
- end
70
+ def form
71
+ @form ||= self.class::Form.new(form_attributes.to_snake_keys)
72
+ end
72
73
 
73
- def form_attributes
74
- params
75
- end
74
+ def form_attributes
75
+ params
76
+ end
76
77
 
77
- def fail!(response = {})
78
- raise self.class::Failure.new(response)
79
- end
78
+ def fail!(response = {})
79
+ raise self.class::Failure.new(response)
80
+ end
80
81
 
81
- def error!(message = "")
82
- fail!(error: message)
83
- end
82
+ def error!(message = "")
83
+ fail!(error: message)
84
+ end
84
85
 
85
- def success!(response = {})
86
- @response = response
86
+ def success!(response = {})
87
+ @response = response
88
+ end
87
89
  end
88
90
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polist
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Smirnov