jaso 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 +7 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +3 -0
- data/README.md +39 -0
- data/jaso.gemspec +35 -0
- data/lib/jaso/attributable.rb +48 -0
- data/lib/jaso/callable.rb +23 -0
- data/lib/jaso/core.rb +34 -0
- data/lib/jaso/finished.rb +10 -0
- data/lib/jaso/not_finished.rb +7 -0
- data/lib/jaso/result.rb +49 -0
- data/lib/jaso/version.rb +5 -0
- data/lib/jaso.rb +7 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f66e9060f14f954d9a7ba87020413c77410cc482168d33049e7051345fe7e0c8
|
4
|
+
data.tar.gz: e56d2636e7f8aa0af5afd32f353b0db0e9db521141ff1eb8bd1fc92b85483b0c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b5c239bf048ee5b0c21351bbd6f1f9cf84c501c89bd2aa3d2ab276768858039016309f7ed63af60eb470cd4c9bdd1fe1654533689f70cfa309667ebc9517e42e
|
7
|
+
data.tar.gz: 17a39ef08034700a1dc4ad7623dfad7e2a2107482d3f46656742a5bf29ab4e3624e63e82bda1a2ff01fbbcee3cb9e75a540ea20bb48f9cfbfc7c4d82ccae113b
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Jaso
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jaso`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/viniciusmeneses/jaso. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/viniciusmeneses/jaso/blob/master/CODE_OF_CONDUCT.md).
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
36
|
+
|
37
|
+
## Code of Conduct
|
38
|
+
|
39
|
+
Everyone interacting in the Jaso project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/viniciusmeneses/jaso/blob/master/CODE_OF_CONDUCT.md).
|
data/jaso.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative "lib/jaso/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "jaso"
|
5
|
+
spec.version = Jaso::VERSION
|
6
|
+
spec.authors = ["Vinicius Meneses"]
|
7
|
+
spec.email = ["vinicius.meneses04@gmail.com"]
|
8
|
+
spec.license = "MIT"
|
9
|
+
|
10
|
+
spec.summary = "Just Another Service Object"
|
11
|
+
spec.description = "Just Another Service Object"
|
12
|
+
spec.homepage = "https://github.com/viniciusmeneses/jaso"
|
13
|
+
|
14
|
+
spec.metadata = {
|
15
|
+
"homepage_uri" => "https://github.com/viniciusmeneses/jaso",
|
16
|
+
"documentation_uri" => "https://rubydoc.info/github/viniciusmeneses/jaso",
|
17
|
+
"changelog_uri" => "https://github.com/viniciusmeneses/jaso/blob/main/CHANGELOG.md",
|
18
|
+
"source_code_uri" => "https://github.com/viniciusmeneses/jaso",
|
19
|
+
"bug_tracker_uri" => "https://github.com/viniciusmeneses/jaso/issues"
|
20
|
+
}
|
21
|
+
|
22
|
+
spec.files = Dir["lib/**/*", "CHANGELOG.md", "README.md", "LICENSE", "Gemfile", "jaso.gemspec"]
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.platform = Gem::Platform::RUBY
|
26
|
+
spec.required_ruby_version = ">= 2.5.0"
|
27
|
+
|
28
|
+
spec.add_development_dependency "rspec", ">= 3.12"
|
29
|
+
spec.add_development_dependency "simplecov", ">= 0.22"
|
30
|
+
|
31
|
+
spec.add_development_dependency "standard", ">= 1.7"
|
32
|
+
spec.add_development_dependency "rubocop", ">= 1.25"
|
33
|
+
spec.add_development_dependency "rubocop-performance", ">= 1.13"
|
34
|
+
spec.add_development_dependency "rubocop-rspec", ">= 2.10"
|
35
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jaso::Attributable
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
base.prepend(PrependMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
private
|
11
|
+
|
12
|
+
def attributes
|
13
|
+
@attributes ||= {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def attribute(name, **options)
|
17
|
+
attributes[name] = options
|
18
|
+
private define_method(name) { attributes[name] }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module PrependMethods
|
23
|
+
def __call
|
24
|
+
assign_attributes
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def attributes
|
32
|
+
@attributes ||= {}
|
33
|
+
end
|
34
|
+
|
35
|
+
def assign_attributes
|
36
|
+
self.class.send(:attributes).each do |name, options|
|
37
|
+
input = @inputs[name]
|
38
|
+
default = options[:default]
|
39
|
+
transform = options[:transform]
|
40
|
+
|
41
|
+
attributes[name] = if @inputs.key?(name)
|
42
|
+
transform.is_a?(Proc) ? transform.call(input) : input
|
43
|
+
else
|
44
|
+
default.is_a?(Proc) ? default.call : default
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jaso::Callable
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
base.private_class_method :new
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def call(**inputs)
|
11
|
+
new(inputs).__call
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def __call
|
18
|
+
call
|
19
|
+
raise Jaso::NotFinished
|
20
|
+
rescue Jaso::Finished => wrapper
|
21
|
+
wrapper.result
|
22
|
+
end
|
23
|
+
end
|
data/lib/jaso/core.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "attributable"
|
4
|
+
require_relative "callable"
|
5
|
+
require_relative "finished"
|
6
|
+
require_relative "not_finished"
|
7
|
+
require_relative "result"
|
8
|
+
|
9
|
+
module Jaso::Core
|
10
|
+
def self.included(base)
|
11
|
+
base.include(Jaso::Attributable)
|
12
|
+
base.include(Jaso::Callable)
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(inputs = {})
|
16
|
+
@inputs = inputs
|
17
|
+
end
|
18
|
+
|
19
|
+
# Must be overwritten
|
20
|
+
def call
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def success!(**data)
|
26
|
+
result = Jaso::Result.new(Jaso::Result::SUCCESS, data)
|
27
|
+
raise Jaso::Finished, result
|
28
|
+
end
|
29
|
+
|
30
|
+
def failure!(**data)
|
31
|
+
result = Jaso::Result.new(Jaso::Result::FAILURE, data)
|
32
|
+
raise Jaso::Finished, result
|
33
|
+
end
|
34
|
+
end
|
data/lib/jaso/result.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Jaso::Result
|
4
|
+
attr_reader :data
|
5
|
+
|
6
|
+
SUCCESS = :success
|
7
|
+
FAILURE = :failure
|
8
|
+
|
9
|
+
def initialize(type, data = {})
|
10
|
+
@type = type
|
11
|
+
@data = data
|
12
|
+
end
|
13
|
+
|
14
|
+
def success?
|
15
|
+
@type == :success
|
16
|
+
end
|
17
|
+
|
18
|
+
def failure?
|
19
|
+
@type == :failure
|
20
|
+
end
|
21
|
+
|
22
|
+
def deconstruct
|
23
|
+
[@type, data]
|
24
|
+
end
|
25
|
+
|
26
|
+
def deconstruct_keys(keys)
|
27
|
+
{ type: @type, **data }
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def method_missing(name, *args, &block)
|
33
|
+
key = method_name_to_key(name)
|
34
|
+
super unless data.key?(key)
|
35
|
+
|
36
|
+
value = name.to_s.end_with?("?") ? !!data[key] : data[key]
|
37
|
+
define_singleton_method(name) { value }
|
38
|
+
send(name)
|
39
|
+
end
|
40
|
+
|
41
|
+
def respond_to_missing?(name, include_private = false)
|
42
|
+
key = method_name_to_key(name)
|
43
|
+
data.key?(key) || super
|
44
|
+
end
|
45
|
+
|
46
|
+
def method_name_to_key(name)
|
47
|
+
name.to_s.chomp("?").to_sym
|
48
|
+
end
|
49
|
+
end
|
data/lib/jaso/version.rb
ADDED
data/lib/jaso.rb
ADDED
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jaso
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vinicius Meneses
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-03-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: simplecov
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.22'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.22'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: standard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.25'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.25'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-performance
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.13'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.13'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.10'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.10'
|
97
|
+
description: Just Another Service Object
|
98
|
+
email:
|
99
|
+
- vinicius.meneses04@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- CHANGELOG.md
|
105
|
+
- Gemfile
|
106
|
+
- README.md
|
107
|
+
- jaso.gemspec
|
108
|
+
- lib/jaso.rb
|
109
|
+
- lib/jaso/attributable.rb
|
110
|
+
- lib/jaso/callable.rb
|
111
|
+
- lib/jaso/core.rb
|
112
|
+
- lib/jaso/finished.rb
|
113
|
+
- lib/jaso/not_finished.rb
|
114
|
+
- lib/jaso/result.rb
|
115
|
+
- lib/jaso/version.rb
|
116
|
+
homepage: https://github.com/viniciusmeneses/jaso
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata:
|
120
|
+
homepage_uri: https://github.com/viniciusmeneses/jaso
|
121
|
+
documentation_uri: https://rubydoc.info/github/viniciusmeneses/jaso
|
122
|
+
changelog_uri: https://github.com/viniciusmeneses/jaso/blob/main/CHANGELOG.md
|
123
|
+
source_code_uri: https://github.com/viniciusmeneses/jaso
|
124
|
+
bug_tracker_uri: https://github.com/viniciusmeneses/jaso/issues
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 2.5.0
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubygems_version: 3.2.3
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Just Another Service Object
|
144
|
+
test_files: []
|