spree_extension 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -3
- data/Gemfile +1 -0
- data/LICENSE.md +1 -1
- data/lib/spree_extension.rb +1 -0
- data/lib/spree_extension/service_module.rb +103 -0
- data/spree_extension.gemspec +2 -1
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5aa752901e907aa299af94f6d1443798304472eaeccd6851cd254b6dd3f05b59
|
4
|
+
data.tar.gz: 0b354e0bab793367ee06a867afdfc98763d1dc556726a8c2924c5952c1f2d788
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd05906a4525fdbcdc947c13d3bebf148ca3b2c4971e2371bc4de4de3484a3e892667532cabe5afc20cdf883d478f740f7dcc93d79ad4006103f716433d49e6e
|
7
|
+
data.tar.gz: bd05c213363d929dce0f865136ed93b790d4d796c8d82e994c4b11f3543c78977b6ba0937cc16a7522de5e4d5e3ffd26e3aefb1630a9eeecc7587ed581a10044
|
data/.gitignore
CHANGED
@@ -42,9 +42,9 @@ build-iPhoneSimulator/
|
|
42
42
|
|
43
43
|
# for a library or gem, you might want to ignore these files since the code is
|
44
44
|
# intended to run in multiple environments; otherwise, check them in:
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
Gemfile.lock
|
46
|
+
.ruby-version
|
47
|
+
.ruby-gemset
|
48
48
|
|
49
49
|
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
50
|
.rvmrc
|
data/Gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gemspec
|
data/LICENSE.md
CHANGED
data/lib/spree_extension.rb
CHANGED
@@ -0,0 +1,103 @@
|
|
1
|
+
# This is a backported ServiceModule introduced in Spree 3.7
|
2
|
+
# Older versions of Spree don't have this feature
|
3
|
+
# see: https://github.com/spree/spree/blob/master/core/lib/spree/service_module.rb
|
4
|
+
unless defined?(Spree::ServiceModule)
|
5
|
+
module Spree
|
6
|
+
module ServiceModule
|
7
|
+
module Callable
|
8
|
+
def call(*args)
|
9
|
+
new.call(*args).tap do |result|
|
10
|
+
return yield(result) if block_given?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class MethodNotImplemented < StandardError; end
|
16
|
+
class WrongDataPassed < StandardError; end
|
17
|
+
class NonCallablePassedToRun < StandardError; end
|
18
|
+
class IncompatibleParamsPassed < StandardError; end
|
19
|
+
|
20
|
+
Result = Struct.new(:success, :value, :error) do
|
21
|
+
def success?
|
22
|
+
success
|
23
|
+
end
|
24
|
+
|
25
|
+
def failure?
|
26
|
+
!success
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
ResultError = Struct.new(:value) do
|
31
|
+
def to_s
|
32
|
+
return value.full_messages.join(', ') if value&.respond_to?(:full_messages)
|
33
|
+
|
34
|
+
value.to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_h
|
38
|
+
return value.messages if value&.respond_to?(:messages)
|
39
|
+
|
40
|
+
{}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module Base
|
45
|
+
def self.prepended(base)
|
46
|
+
class << base
|
47
|
+
prepend Callable
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def call(input = nil)
|
52
|
+
input ||= {}
|
53
|
+
@_passed_input = Result.new(true, input)
|
54
|
+
result = super
|
55
|
+
@_passed_input = result if result.is_a? Result
|
56
|
+
enforce_data_format
|
57
|
+
@_passed_input
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def run(callable)
|
63
|
+
return unless @_passed_input.success?
|
64
|
+
|
65
|
+
if callable.instance_of? Symbol
|
66
|
+
unless respond_to?(callable, true)
|
67
|
+
raise MethodNotImplemented, "You didn't implement #{callable} method. Implement it before calling this class"
|
68
|
+
end
|
69
|
+
|
70
|
+
callable = method(callable)
|
71
|
+
end
|
72
|
+
|
73
|
+
unless callable.respond_to?(:call)
|
74
|
+
raise NonCallablePassedToRun, 'You can pass only symbol with method name or instance of callable class to run method'
|
75
|
+
end
|
76
|
+
|
77
|
+
begin
|
78
|
+
@_passed_input = callable.call(@_passed_input.value)
|
79
|
+
rescue ArgumentError => e
|
80
|
+
if e.message.include? 'missing'
|
81
|
+
raise IncompatibleParamsPassed, "You didn't pass #{e.message} to callable '#{callable.name}'"
|
82
|
+
else
|
83
|
+
raise IncompatibleParamsPassed, "You passed #{e.message} to callable '#{callable.name}'"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def success(value)
|
89
|
+
Result.new(true, value, nil)
|
90
|
+
end
|
91
|
+
|
92
|
+
def failure(value, error = nil)
|
93
|
+
error = value.errors if error.nil? && value.respond_to?(:errors)
|
94
|
+
Result.new(false, value, ResultError.new(error))
|
95
|
+
end
|
96
|
+
|
97
|
+
def enforce_data_format
|
98
|
+
raise WrongDataPassed, "You didn't use `success` or `failure` method to return value from method." unless @_passed_input.instance_of? Result
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/spree_extension.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'spree_extension'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.6'
|
4
4
|
s.summary = 'Common tools and helpers for Spree Extensions developers'
|
5
5
|
s.description = 'Common tools and helpers for Spree Extensions developers'
|
6
6
|
s.authors = ['Damian Legawiec']
|
@@ -14,4 +14,5 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.require_paths = ['lib']
|
15
15
|
|
16
16
|
s.add_dependency 'activerecord', '>= 4.2'
|
17
|
+
s.add_dependency 'spree_core', '>= 3.1'
|
17
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damian Legawiec
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: spree_core
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.1'
|
27
41
|
description: Common tools and helpers for Spree Extensions developers
|
28
42
|
email: damian@sparksolutions.co
|
29
43
|
executables: []
|
@@ -31,9 +45,11 @@ extensions: []
|
|
31
45
|
extra_rdoc_files: []
|
32
46
|
files:
|
33
47
|
- ".gitignore"
|
48
|
+
- Gemfile
|
34
49
|
- LICENSE.md
|
35
50
|
- lib/spree_extension.rb
|
36
51
|
- lib/spree_extension/migration.rb
|
52
|
+
- lib/spree_extension/service_module.rb
|
37
53
|
- spree_extension.gemspec
|
38
54
|
homepage: https://spreecommerce.org
|
39
55
|
licenses:
|
@@ -55,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
71
|
version: '0'
|
56
72
|
requirements: []
|
57
73
|
rubyforge_project:
|
58
|
-
rubygems_version: 2.
|
74
|
+
rubygems_version: 2.7.8
|
59
75
|
signing_key:
|
60
76
|
specification_version: 4
|
61
77
|
summary: Common tools and helpers for Spree Extensions developers
|