haku 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +12 -0
- data/.envrc +1 -0
- data/.pryrc +3 -0
- data/.rubocop.yml +33 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +105 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +69 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +16 -0
- data/lib/haku/controller.rb +22 -0
- data/lib/haku/core.rb +78 -0
- data/lib/haku/railtie.rb +22 -0
- data/lib/haku/resourceable.rb +40 -0
- data/lib/haku/result.rb +24 -0
- data/lib/haku/version.rb +20 -0
- data/lib/haku.rb +12 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b807f104854f0cd9619b5a3a5be55a5e9744e7eaef85ace5f775772395d9957b
|
4
|
+
data.tar.gz: fb389738d56e37d6f397ee32316c7ad249ef95ad1d39f790c083742a0e6fad83
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: baa9206fa09e7aec2212a226fc66a0dd4a4fcb88ca437c95032c1e7f9fb244fda6e2fa9b7869d38c736a3c88970fa808bc12234f72d93d0d3ba741f3107a68e1
|
7
|
+
data.tar.gz: 3fbcf48768c7125fb1e60c1b1b022cef94b34e6cfc1236ada836d559d2e4595776a12a441f6af2fe0fc7cd948675b43681479edeb66836bf436b3ea12e7e7294
|
data/.editorconfig
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file is for unifying the coding style for different editors and IDEs
|
2
|
+
# editorconfig.org
|
3
|
+
|
4
|
+
root = true
|
5
|
+
|
6
|
+
[*]
|
7
|
+
charset = utf-8
|
8
|
+
indent_size = 2
|
9
|
+
indent_style = space
|
10
|
+
insert_final_newline = true
|
11
|
+
max_line_length = 120
|
12
|
+
trim_trailing_whitespace = true
|
data/.envrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
PATH_add bin
|
data/.pryrc
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-minitest
|
3
|
+
- rubocop-rake
|
4
|
+
|
5
|
+
inherit_mode:
|
6
|
+
merge:
|
7
|
+
- Exclude
|
8
|
+
- Include
|
9
|
+
- Prefixes
|
10
|
+
|
11
|
+
AllCops:
|
12
|
+
DisplayCopNames: true
|
13
|
+
Exclude:
|
14
|
+
- "**/bin/**/*"
|
15
|
+
NewCops: enable
|
16
|
+
TargetRubyVersion: 2.6
|
17
|
+
|
18
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
19
|
+
EnforcedStyle: no_space
|
20
|
+
|
21
|
+
Style/Documentation:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Style/StringLiterals:
|
25
|
+
Enabled: true
|
26
|
+
EnforcedStyle: double_quotes
|
27
|
+
|
28
|
+
Style/StringLiteralsInInterpolation:
|
29
|
+
Enabled: true
|
30
|
+
EnforcedStyle: double_quotes
|
31
|
+
|
32
|
+
Layout/LineLength:
|
33
|
+
Max: 120
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for
|
6
|
+
everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity
|
7
|
+
and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion,
|
8
|
+
or sexual identity and orientation.
|
9
|
+
|
10
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
15
|
+
|
16
|
+
* Demonstrating empathy and kindness toward other people
|
17
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
18
|
+
* Giving and gracefully accepting constructive feedback
|
19
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
20
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
21
|
+
|
22
|
+
Examples of unacceptable behavior include:
|
23
|
+
|
24
|
+
* The use of sexualized language or imagery, and sexual attention or
|
25
|
+
advances of any kind
|
26
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
27
|
+
* Public or private harassment
|
28
|
+
* Publishing others' private information, such as a physical or email
|
29
|
+
address, without their explicit permission
|
30
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
31
|
+
professional setting
|
32
|
+
|
33
|
+
## Enforcement Responsibilities
|
34
|
+
|
35
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take
|
36
|
+
appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive,
|
37
|
+
or harmful.
|
38
|
+
|
39
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits,
|
40
|
+
issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for
|
41
|
+
moderation decisions when appropriate.
|
42
|
+
|
43
|
+
## Scope
|
44
|
+
|
45
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing
|
46
|
+
the community in public spaces. Examples of representing our community include using an official e-mail address, posting
|
47
|
+
via an official social media account, or acting as an appointed representative at an online or offline event.
|
48
|
+
|
49
|
+
## Enforcement
|
50
|
+
|
51
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible
|
52
|
+
for enforcement at javier.aranda.varo@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
53
|
+
|
54
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
55
|
+
|
56
|
+
## Enforcement Guidelines
|
57
|
+
|
58
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem
|
59
|
+
in violation of this Code of Conduct:
|
60
|
+
|
61
|
+
### 1. Correction
|
62
|
+
|
63
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the
|
64
|
+
community.
|
65
|
+
|
66
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation
|
67
|
+
and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
68
|
+
|
69
|
+
### 2. Warning
|
70
|
+
|
71
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
72
|
+
|
73
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including
|
74
|
+
unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding
|
75
|
+
interactions in community spaces as well as external channels like social media. Violating these terms may lead to a
|
76
|
+
temporary or permanent ban.
|
77
|
+
|
78
|
+
### 3. Temporary Ban
|
79
|
+
|
80
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
81
|
+
|
82
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified
|
83
|
+
period of time. No public or private interaction with the people involved, including unsolicited interaction with those
|
84
|
+
enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
85
|
+
|
86
|
+
### 4. Permanent Ban
|
87
|
+
|
88
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate
|
89
|
+
behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
90
|
+
|
91
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
92
|
+
|
93
|
+
## Attribution
|
94
|
+
|
95
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
96
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
97
|
+
|
98
|
+
Community Impact Guidelines were inspired by
|
99
|
+
[Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
100
|
+
|
101
|
+
[homepage]: https://www.contributor-covenant.org
|
102
|
+
|
103
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
104
|
+
https://www.contributor-covenant.org/faq. Translations are available at
|
105
|
+
https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
ruby "3.1.1"
|
6
|
+
|
7
|
+
gemspec
|
8
|
+
|
9
|
+
gem "minitest", "~> 5.0"
|
10
|
+
gem "pry", "~> 0.14"
|
11
|
+
gem "rake", "~> 13.0"
|
12
|
+
gem "rubocop", "~> 1.21"
|
13
|
+
gem "rubocop-minitest", "~> 0.19"
|
14
|
+
gem "rubocop-rake", "~> 0.6"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
haku (0.1.0)
|
5
|
+
activesupport (>= 6.0, < 8.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (7.0.2.3)
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
+
i18n (>= 1.6, < 2)
|
13
|
+
minitest (>= 5.1)
|
14
|
+
tzinfo (~> 2.0)
|
15
|
+
ast (2.4.2)
|
16
|
+
coderay (1.1.3)
|
17
|
+
concurrent-ruby (1.1.9)
|
18
|
+
i18n (1.10.0)
|
19
|
+
concurrent-ruby (~> 1.0)
|
20
|
+
method_source (1.0.0)
|
21
|
+
minitest (5.15.0)
|
22
|
+
parallel (1.22.1)
|
23
|
+
parser (3.1.1.0)
|
24
|
+
ast (~> 2.4.1)
|
25
|
+
pry (0.14.1)
|
26
|
+
coderay (~> 1.1)
|
27
|
+
method_source (~> 1.0)
|
28
|
+
rainbow (3.1.1)
|
29
|
+
rake (13.0.6)
|
30
|
+
regexp_parser (2.2.1)
|
31
|
+
rexml (3.2.5)
|
32
|
+
rubocop (1.26.1)
|
33
|
+
parallel (~> 1.10)
|
34
|
+
parser (>= 3.1.0.0)
|
35
|
+
rainbow (>= 2.2.2, < 4.0)
|
36
|
+
regexp_parser (>= 1.8, < 3.0)
|
37
|
+
rexml
|
38
|
+
rubocop-ast (>= 1.16.0, < 2.0)
|
39
|
+
ruby-progressbar (~> 1.7)
|
40
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
41
|
+
rubocop-ast (1.16.0)
|
42
|
+
parser (>= 3.1.1.0)
|
43
|
+
rubocop-minitest (0.19.0)
|
44
|
+
rubocop (>= 0.90, < 2.0)
|
45
|
+
rubocop-rake (0.6.0)
|
46
|
+
rubocop (~> 1.0)
|
47
|
+
ruby-progressbar (1.11.0)
|
48
|
+
tzinfo (2.0.4)
|
49
|
+
concurrent-ruby (~> 1.0)
|
50
|
+
unicode-display_width (2.1.0)
|
51
|
+
|
52
|
+
PLATFORMS
|
53
|
+
arm64-darwin-21
|
54
|
+
x86_64-linux
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
haku!
|
58
|
+
minitest (~> 5.0)
|
59
|
+
pry (~> 0.14)
|
60
|
+
rake (~> 13.0)
|
61
|
+
rubocop (~> 1.21)
|
62
|
+
rubocop-minitest (~> 0.19)
|
63
|
+
rubocop-rake (~> 0.6)
|
64
|
+
|
65
|
+
RUBY VERSION
|
66
|
+
ruby 3.1.1p18
|
67
|
+
|
68
|
+
BUNDLED WITH
|
69
|
+
2.3.7
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Javier Aranda
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Haku
|
2
|
+
|
3
|
+
![CI](https://github.com/javierav/haku/workflows/CI/badge.svg)
|
4
|
+
|
5
|
+
TODO: Write a better gem description.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'haku'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
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 test` to run the tests.
|
26
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
27
|
+
|
28
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
29
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
|
30
|
+
which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to
|
31
|
+
[rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/javierav/haku. This project is intended to be
|
36
|
+
a safe, welcoming space for collaboration, and contributors are expected to adhere to the
|
37
|
+
[code of conduct](https://github.com/javierav/haku/blob/development/CODE_OF_CONDUCT.md).
|
38
|
+
|
39
|
+
## Code of Conduct
|
40
|
+
|
41
|
+
Everyone interacting in the Haku project's codebases, issue trackers, chat rooms and mailing lists is expected to
|
42
|
+
follow the [code of conduct](https://github.com/javierav/haku/blob/development/CODE_OF_CONDUCT.md).
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "rubocop/rake_task"
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task default: %i[test rubocop]
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
require "active_support/core_ext/hash/reverse_merge"
|
5
|
+
|
6
|
+
module Haku
|
7
|
+
module Controller
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
attr_reader :execution
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute(action, params={})
|
15
|
+
@execution = action.call(params.reverse_merge(default_execute_params || {}))
|
16
|
+
end
|
17
|
+
|
18
|
+
def default_execute_params
|
19
|
+
{ current_user: current_user } if respond_to?(:current_user)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/haku/core.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
require "active_support/core_ext/class/attribute"
|
5
|
+
require_relative "result"
|
6
|
+
|
7
|
+
module Haku
|
8
|
+
module Core
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
attr_reader :params
|
13
|
+
|
14
|
+
class_attribute :haku_success_callbacks, default: []
|
15
|
+
class_attribute :haku_failure_callbacks, default: []
|
16
|
+
end
|
17
|
+
|
18
|
+
module ClassMethods
|
19
|
+
def call(params={})
|
20
|
+
new(params).run
|
21
|
+
end
|
22
|
+
|
23
|
+
def on_success(*methods)
|
24
|
+
self.haku_success_callbacks += methods
|
25
|
+
end
|
26
|
+
|
27
|
+
def on_failure(*methods)
|
28
|
+
self.haku_failure_callbacks += methods
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize(params={})
|
33
|
+
@params = params
|
34
|
+
|
35
|
+
@params.each_key do |key|
|
36
|
+
define_singleton_method(key) { @params[key] } unless respond_to?(key)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def run
|
41
|
+
result = call
|
42
|
+
|
43
|
+
Result.new(_haku_status, _haku_response.merge(result: result)).tap do
|
44
|
+
_haku_run_callbacks
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def success!(response={})
|
51
|
+
@_haku_status = :success
|
52
|
+
@_haku_response = _haku_normalize_response(response)
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
|
56
|
+
def failure!(response={})
|
57
|
+
@_haku_status = :failure
|
58
|
+
@_haku_response = _haku_normalize_response(response)
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def _haku_normalize_response(response)
|
63
|
+
response.is_a?(Hash) ? response : { data: response }
|
64
|
+
end
|
65
|
+
|
66
|
+
def _haku_status
|
67
|
+
@_haku_status || :success
|
68
|
+
end
|
69
|
+
|
70
|
+
def _haku_response
|
71
|
+
@_haku_response || {}
|
72
|
+
end
|
73
|
+
|
74
|
+
def _haku_run_callbacks
|
75
|
+
(self.class.send("haku_#{_haku_status}_callbacks") || []).each { |cb| send(cb) }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/haku/railtie.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/railtie"
|
4
|
+
require_relative "controller"
|
5
|
+
|
6
|
+
module Haku
|
7
|
+
class Railtie < ::Rails::Railtie
|
8
|
+
initializer "haku.action_controller_base" do
|
9
|
+
if Haku.enable_in_action_controller_base
|
10
|
+
ActiveSupport.on_load(:action_controller_base) do
|
11
|
+
ActionController::Base.include Haku::Controller
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
if Haku.enable_in_action_controller_api
|
16
|
+
ActiveSupport.on_load(:action_controller_api) do
|
17
|
+
ActionController::API.include Haku::Controller
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Haku
|
4
|
+
module Resourceable
|
5
|
+
def create_resource(parent, attributes, ivar=nil, singleton: nil)
|
6
|
+
parent.send(singleton ? "create_#{singleton}" : "create", attributes).tap do |resource|
|
7
|
+
instance_variable_set("@#{ivar}", resource) if ivar.present?
|
8
|
+
|
9
|
+
if resource.persisted?
|
10
|
+
yield resource if block_given?
|
11
|
+
success! resource: resource
|
12
|
+
else
|
13
|
+
failure! resource: resource, errors: resource.errors
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_resource(resource, attributes)
|
19
|
+
resource.tap do
|
20
|
+
if resource.update(attributes)
|
21
|
+
yield resource if block_given?
|
22
|
+
success! resource: resource
|
23
|
+
else
|
24
|
+
failure! resource: resource, errors: resource.errors
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def destroy_resource(resource)
|
30
|
+
resource.tap do
|
31
|
+
if resource.destroy
|
32
|
+
yield resource if block_given?
|
33
|
+
success! resource: resource
|
34
|
+
else
|
35
|
+
failure! resource: resource, errors: resource.errors
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/haku/result.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/string_inquirer"
|
4
|
+
|
5
|
+
module Haku
|
6
|
+
class Result
|
7
|
+
def initialize(status, response)
|
8
|
+
@status = ActiveSupport::StringInquirer.new(status.to_s)
|
9
|
+
@response = response
|
10
|
+
|
11
|
+
@response.each_key do |key|
|
12
|
+
define_singleton_method(key) { @response[key] }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def success?
|
17
|
+
@status.success?
|
18
|
+
end
|
19
|
+
|
20
|
+
def failure?
|
21
|
+
@status.failure?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/haku/version.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Haku
|
4
|
+
module VERSION
|
5
|
+
MAJOR = 1
|
6
|
+
MINOR = 0
|
7
|
+
TINY = 0
|
8
|
+
PRE = nil
|
9
|
+
|
10
|
+
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.version
|
14
|
+
VERSION::STRING
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.gem_version
|
18
|
+
Gem::Version.new VERSION::STRING
|
19
|
+
end
|
20
|
+
end
|
data/lib/haku.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/module/attribute_accessors"
|
4
|
+
require_relative "haku/core"
|
5
|
+
require_relative "haku/railtie" if defined?(Rails)
|
6
|
+
require_relative "haku/resourceable"
|
7
|
+
require_relative "haku/version"
|
8
|
+
|
9
|
+
module Haku
|
10
|
+
mattr_accessor :enable_in_action_controller_base, default: true
|
11
|
+
mattr_accessor :enable_in_action_controller_api, default: true
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: haku
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Javier Aranda
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-04-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '8.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '6.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '8.0'
|
33
|
+
description:
|
34
|
+
email:
|
35
|
+
- javier.aranda.varo@gmail.com
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files:
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
files:
|
42
|
+
- ".editorconfig"
|
43
|
+
- ".envrc"
|
44
|
+
- ".pryrc"
|
45
|
+
- ".rubocop.yml"
|
46
|
+
- CHANGELOG.md
|
47
|
+
- CODE_OF_CONDUCT.md
|
48
|
+
- Gemfile
|
49
|
+
- Gemfile.lock
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/haku.rb
|
54
|
+
- lib/haku/controller.rb
|
55
|
+
- lib/haku/core.rb
|
56
|
+
- lib/haku/railtie.rb
|
57
|
+
- lib/haku/resourceable.rb
|
58
|
+
- lib/haku/result.rb
|
59
|
+
- lib/haku/version.rb
|
60
|
+
homepage: https://github.com/javierav/haku
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata:
|
64
|
+
homepage_uri: https://github.com/javierav/haku
|
65
|
+
source_code_uri: https://github.com/javierav/haku/tree/v1.0.0
|
66
|
+
changelog_uri: https://github.com/javierav/haku/blob/v1.0.0/CHANGELOG.md
|
67
|
+
rubygems_mfa_required: 'true'
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- "--charset=UTF-8"
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.6.0
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubygems_version: 3.3.7
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: A library for build simple service objects
|
88
|
+
test_files: []
|