activefunction 0.3.3
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 +39 -0
- data/LICENSE.txt +21 -0
- data/README.md +155 -0
- data/bin/console +15 -0
- data/bin/rake +27 -0
- data/bin/setup +8 -0
- data/lib/active_function/base.rb +20 -0
- data/lib/active_function/functions/callbacks.rb +69 -0
- data/lib/active_function/functions/core.rb +49 -0
- data/lib/active_function/functions/rendering.rb +31 -0
- data/lib/active_function/functions/response.rb +30 -0
- data/lib/active_function/functions/strong_parameters.rb +104 -0
- data/lib/active_function/version.rb +5 -0
- data/lib/active_function.rb +13 -0
- data/sig/active_function.rbs +4 -0
- data/sig/manifest.yml +3 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ed2b67a8be1601c72b18a3be2f053a183be0a59b56b344176487ab4e628f6241
|
4
|
+
data.tar.gz: 48256c3c954462a328993f71897c4413bb9df5f738a48f27c221eabf9ce74b4e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f34764a21c44e461f65eaf467393316ba73119199b9c86f0d8936e8b42927858a2363528030f1e6dd420c56cc853b68f8f6a0ee7d6f2116c166aefb304890821
|
7
|
+
data.tar.gz: cd748cf2973a364d34000c696a638e230c333c88d4aab632544a047a5b4c339f80dd19d93142127c9d7e44528240435c249fe97c75633a268b2ddc00ebccd723
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
## [Unreleased]
|
2
|
+
|
3
|
+
## [0.1.0] - 2022-12-28
|
4
|
+
|
5
|
+
- Add `before_action` and `after_action` callbacks with `:only` and `:if` options
|
6
|
+
- Add `ActiveFunction::Base#params` with `require`, `permit`, `[]` and `to_h` public methods
|
7
|
+
- Add specs for `ActiveFunction::Base.params` module
|
8
|
+
- Add `ActiveFunction::Base#render` with `:status`, `:json` and `:head` options
|
9
|
+
- Add RBS signature
|
10
|
+
- Add RBS Aws Event Types
|
11
|
+
- Add public interface type `steep` checking
|
12
|
+
- Add `ruby-next` transpiler
|
13
|
+
|
14
|
+
## [0.2.0] - 2023-01-08
|
15
|
+
|
16
|
+
- Add unit tests
|
17
|
+
- Fix Steep pipeline & add better RBS type signatures
|
18
|
+
- Refactor `::Functions` module
|
19
|
+
- Add `Response` class
|
20
|
+
|
21
|
+
## [0.3.0] - 2023-01-12
|
22
|
+
|
23
|
+
- cleanup
|
24
|
+
- add ActiveFunction::Functions::Response#commit!
|
25
|
+
- extract action processing to separate method to handle ActiveFunction::Functions::Callbacks#process overriding
|
26
|
+
- add test for ActiveFunction::Base.process
|
27
|
+
|
28
|
+
|
29
|
+
# [0.3.1] - 2023-02-09
|
30
|
+
|
31
|
+
- Updated readme
|
32
|
+
- Make callbacks inheritable
|
33
|
+
- `include` -> `prepend` Core module
|
34
|
+
|
35
|
+
# [0.3.2] - 2023-02-10
|
36
|
+
|
37
|
+
- Finish readme
|
38
|
+
- Fix callbacks broken by `prepend` change
|
39
|
+
- Add more tests for `#process` public interface
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Nerbyk
|
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,155 @@
|
|
1
|
+
# ActiveFunction
|
2
|
+
|
3
|
+
rails/action_controller like gem which provides lightweight callbacks, strong parameters & rendering features. It's designed to be used with AWS Lambda functions, but can be also used with any Ruby application.
|
4
|
+
|
5
|
+
Implemented with some of ruby 3.x features, but also supports ruby 2.6.x thanks to [RubyNext](https://github.com/ruby-next/ruby-next) transpiler. Type safety achieved by RBS and [Steep](https://github.com/soutaro/steep).
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
## A Short Example
|
10
|
+
|
11
|
+
Here's a simple example of a function that uses ActiveFunction:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
require 'active_function'
|
15
|
+
|
16
|
+
class AppFunction < ActiveFunction::Base
|
17
|
+
def index
|
18
|
+
render json: SomeTable.all
|
19
|
+
end
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
Use `#process` method to proceed the request:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
AppFunction.process(:index) # processes index action of AppFunction instance
|
27
|
+
```
|
28
|
+
Also check extended [example](https://github.com/DanilMaximov/activefunction/tree/master/active_function_example)
|
29
|
+
## Callbacks
|
30
|
+
ActiveFunction supports simple callbacks `:before` and `:after` which runs around provided action in `#process`.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
class AppFunction < ActiveFunction::Base
|
34
|
+
before_action :set_user
|
35
|
+
after_action :log_response
|
36
|
+
|
37
|
+
# some action ...
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def set_user
|
42
|
+
@user = User.first
|
43
|
+
end
|
44
|
+
|
45
|
+
def log_response
|
46
|
+
Logger.info @response
|
47
|
+
end
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
Callbacks also can be user with `only: Array[Symbol]` and `if: Symbol` options.
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
class AppFunction < ActiveFunction::Base
|
55
|
+
before_action :set_user, only: %i[show update destroy], if: :request_valid?
|
56
|
+
|
57
|
+
# some actions ...
|
58
|
+
|
59
|
+
private def request_valid? = true
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
Callbacks are inheritable so all callbacks calls will be inherited from base class
|
64
|
+
```ruby
|
65
|
+
class BaseFunction < ActiveFunction::Base
|
66
|
+
before_action :set_current_user
|
67
|
+
|
68
|
+
def set_current_user
|
69
|
+
@current_user = User.first
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class PostsFunction < BaseFunction
|
74
|
+
def index
|
75
|
+
render json: @current_user
|
76
|
+
end
|
77
|
+
end
|
78
|
+
```
|
79
|
+
## Strong Parameters
|
80
|
+
ActiveFunction supports strong parameters which can be accessed by `#params` instance method. Strong parameters hash can be passed in `#process` as second argument.
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
PostFunction.process(:index, data: { id: 1, name: "Pupa" })
|
84
|
+
```
|
85
|
+
|
86
|
+
Simple usage:
|
87
|
+
```ruby
|
88
|
+
class PostsFunction < ActiveFunction::Base
|
89
|
+
def index
|
90
|
+
render json: permitted_params
|
91
|
+
end
|
92
|
+
|
93
|
+
def permitted_params = params
|
94
|
+
.require(:data)
|
95
|
+
.permit(:id, :name)
|
96
|
+
.to_h
|
97
|
+
end
|
98
|
+
```
|
99
|
+
Strong params supports nested attributes
|
100
|
+
```ruby
|
101
|
+
params.permit(:id, :name, :address => [:city, :street])
|
102
|
+
```
|
103
|
+
|
104
|
+
## Rendering
|
105
|
+
ActiveFunction supports rendering of JSON. Rendering is obligatory for any function naction and can be done by `#render` method.
|
106
|
+
```ruby
|
107
|
+
class PostsFunction < ActiveFunction::Base
|
108
|
+
def index
|
109
|
+
render json: { id: 1, name: "Pupa" }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
```
|
113
|
+
default status code is 200, but it can be changed by `:status` option
|
114
|
+
```ruby
|
115
|
+
class PostsFunction < ActiveFunction::Base
|
116
|
+
def index
|
117
|
+
render json: { id: 1, name: "Pupa" }, status: 201
|
118
|
+
end
|
119
|
+
end
|
120
|
+
```
|
121
|
+
Headers can be passed by `:headers` option. Default headers are `{"Content-Type" => "application/json"}`.
|
122
|
+
```ruby
|
123
|
+
class PostsFunction < ActiveFunction::Base
|
124
|
+
def index
|
125
|
+
render json: { id: 1, name: "Pupa" }, headers: { "X-Request-Id" => "123" }
|
126
|
+
end
|
127
|
+
end
|
128
|
+
```
|
129
|
+
|
130
|
+
|
131
|
+
## Installation
|
132
|
+
|
133
|
+
Add this line to your application's Gemfile:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
gem 'activefunction', git: "https://github.com/DanilMaximov/activefunction.git"
|
137
|
+
```
|
138
|
+
|
139
|
+
## Development
|
140
|
+
|
141
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rake test` to run the tests and `bin/rake steep` to run type checker.
|
142
|
+
|
143
|
+
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).
|
144
|
+
|
145
|
+
## Contributing
|
146
|
+
|
147
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/DanilMaximov/activefunction. 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/DanilMaximov/activefunction/blob/master/CODE_OF_CONDUCT.md).
|
148
|
+
|
149
|
+
## License
|
150
|
+
|
151
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
152
|
+
|
153
|
+
## Code of Conduct
|
154
|
+
|
155
|
+
Everyone interacting in the ActiveFunction::Functions project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/DanilMaximov/activefunction/blob/master/CODE_OF_CONDUCT.md).
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "active_function"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/rake
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rake' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
12
|
+
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
14
|
+
|
15
|
+
if File.file?(bundle_binstub)
|
16
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
17
|
+
load(bundle_binstub)
|
18
|
+
else
|
19
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
20
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require "rubygems"
|
25
|
+
require "bundler/setup"
|
26
|
+
|
27
|
+
load Gem.bin_path("rake", "rake")
|
data/bin/setup
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveFunction
|
4
|
+
class Base
|
5
|
+
require "active_function/functions/core"
|
6
|
+
require "active_function/functions/callbacks"
|
7
|
+
require "active_function/functions/strong_parameters"
|
8
|
+
require "active_function/functions/rendering"
|
9
|
+
require "active_function/functions/response"
|
10
|
+
|
11
|
+
include Functions::Core
|
12
|
+
include Functions::Callbacks
|
13
|
+
include Functions::Rendering
|
14
|
+
include Functions::StrongParameters
|
15
|
+
|
16
|
+
def self.process(action_name, request = {}, response = Functions::Response.new)
|
17
|
+
new.dispatch(action_name, request, response)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveFunction
|
4
|
+
class MissingCallbackContext < Error
|
5
|
+
MESSAGE_TEMPLATE = "Missing callback context: %s"
|
6
|
+
|
7
|
+
attr_reader :message
|
8
|
+
|
9
|
+
def initialize(context)
|
10
|
+
@message = MESSAGE_TEMPLATE % context
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module Functions
|
15
|
+
module Callbacks
|
16
|
+
def self.included(base)
|
17
|
+
base.extend(ClassMethods)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def process(*)
|
23
|
+
_run_callbacks :before
|
24
|
+
|
25
|
+
super
|
26
|
+
|
27
|
+
_run_callbacks :after
|
28
|
+
end
|
29
|
+
|
30
|
+
def _run_callbacks(type)
|
31
|
+
self.class.callbacks[type].each do |callback_method, options|
|
32
|
+
raise MissingCallbackContext, callback_method unless respond_to?(callback_method, true)
|
33
|
+
|
34
|
+
send(callback_method) if _executable?(options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def _executable?(options)
|
39
|
+
return false if options[:only] && !options[:only].include?(@action_name)
|
40
|
+
return false if options[:if] && !send(options[:if])
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
44
|
+
module ClassMethods
|
45
|
+
def inherited(subclass)
|
46
|
+
subclass.instance_variable_set(:@__callbacks, @__callbacks)
|
47
|
+
end
|
48
|
+
|
49
|
+
def before_action(method, options = {})
|
50
|
+
set_callback :before, method, options
|
51
|
+
end
|
52
|
+
|
53
|
+
def after_action(method, options = {})
|
54
|
+
set_callback :after, method, options
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_callback(type, method, options = {})
|
58
|
+
callbacks[type][method] = options
|
59
|
+
end
|
60
|
+
|
61
|
+
def callbacks
|
62
|
+
@__callbacks ||= {before: {}, after: {}}
|
63
|
+
|
64
|
+
@__callbacks
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveFunction
|
4
|
+
class MissingRouteMethod < Error
|
5
|
+
MESSAGE_TEMPLATE = "Missing function route: %s"
|
6
|
+
|
7
|
+
attr_reader :message
|
8
|
+
|
9
|
+
def initialize(context)
|
10
|
+
@message = MESSAGE_TEMPLATE % context
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class NotRenderedError < Error
|
15
|
+
MESSAGE_TEMPLATE = "render was not called: %s"
|
16
|
+
|
17
|
+
attr_reader :message
|
18
|
+
|
19
|
+
def initialize(context)
|
20
|
+
@message = MESSAGE_TEMPLATE % context
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module Functions
|
25
|
+
module Core
|
26
|
+
attr_reader :action_name, :request, :response
|
27
|
+
|
28
|
+
def dispatch(action_name, request, response)
|
29
|
+
@action_name = action_name
|
30
|
+
@request = request
|
31
|
+
@response = response
|
32
|
+
|
33
|
+
raise MissingRouteMethod, @action_name unless respond_to?(action_name)
|
34
|
+
|
35
|
+
process(@action_name)
|
36
|
+
|
37
|
+
raise NotRenderedError, @action_name unless performed?
|
38
|
+
|
39
|
+
@response.to_h
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def process(action) = public_send(action)
|
45
|
+
|
46
|
+
def performed? = @response.committed?
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module ActiveFunction
|
6
|
+
class DoubleRenderError < Error
|
7
|
+
MESSAGE_TEMPLATE = "#render was called multiple times in action: %s"
|
8
|
+
|
9
|
+
attr_reader :message
|
10
|
+
|
11
|
+
def initialize(context)
|
12
|
+
@message = MESSAGE_TEMPLATE % context
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module Functions
|
17
|
+
module Rendering
|
18
|
+
DEFAULT_HEADER = {"Content-Type" => "application/json"}.freeze
|
19
|
+
|
20
|
+
def render(status: 200, json: {}, head: {})
|
21
|
+
raise DoubleRenderError, @action_name if performed?
|
22
|
+
|
23
|
+
@response.status = status
|
24
|
+
@response.headers = head.merge(Hash[DEFAULT_HEADER])
|
25
|
+
@response.body = JSON.generate(json)
|
26
|
+
|
27
|
+
@response.commit!
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveFunction
|
4
|
+
module Functions
|
5
|
+
class Response
|
6
|
+
attr_accessor :status, :headers, :body
|
7
|
+
|
8
|
+
def initialize(status: 200, headers: {}, body: nil)
|
9
|
+
@status = status
|
10
|
+
@headers = headers
|
11
|
+
@body = body
|
12
|
+
@committed = false
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_h
|
16
|
+
{
|
17
|
+
statusCode: status,
|
18
|
+
headers: headers,
|
19
|
+
body: body
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def commit!
|
24
|
+
@committed = true
|
25
|
+
end
|
26
|
+
|
27
|
+
def committed? = @committed
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "forwardable"
|
4
|
+
|
5
|
+
module ActiveFunction
|
6
|
+
class ParameterMissingError < Error
|
7
|
+
MESSAGE_TEMPLATE = "Missing parameter: %s"
|
8
|
+
|
9
|
+
attr_reader :message
|
10
|
+
|
11
|
+
def initialize(param)
|
12
|
+
MESSAGE_TEMPLATE % param
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class UnpermittedParameterError < Error
|
17
|
+
MESSAGE_TEMPLATE = "Unpermitted parameter: %s"
|
18
|
+
|
19
|
+
attr_reader :message
|
20
|
+
|
21
|
+
def initialize(param)
|
22
|
+
MESSAGE_TEMPLATE % param
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Functions
|
27
|
+
module StrongParameters
|
28
|
+
def params
|
29
|
+
@_params ||= Parameters.new(@request)
|
30
|
+
end
|
31
|
+
|
32
|
+
class Parameters
|
33
|
+
extend Forwardable
|
34
|
+
def_delegators :@parameters, :each, :map
|
35
|
+
include Enumerable
|
36
|
+
|
37
|
+
def initialize(parameters, permitted: false)
|
38
|
+
@parameters = parameters
|
39
|
+
@permitted = permitted
|
40
|
+
end
|
41
|
+
|
42
|
+
def [](attribute)
|
43
|
+
nested_attribute(parameters[attribute])
|
44
|
+
end
|
45
|
+
|
46
|
+
def require(attribute)
|
47
|
+
value = self[attribute]
|
48
|
+
|
49
|
+
raise ParameterMissingError, attribute if value.nil?
|
50
|
+
|
51
|
+
value
|
52
|
+
end
|
53
|
+
|
54
|
+
def permit(*attributes)
|
55
|
+
pparams = {}
|
56
|
+
|
57
|
+
attributes.each do |attribute|
|
58
|
+
if attribute.is_a? Hash
|
59
|
+
attribute.each do |k, v|
|
60
|
+
pparams[k] = process_nested(self[k], :permit, v)
|
61
|
+
end
|
62
|
+
else
|
63
|
+
next unless parameters.key?(attribute)
|
64
|
+
|
65
|
+
pparams[attribute] = self[attribute]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
Parameters.new(pparams, permitted: true)
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_h
|
73
|
+
raise UnpermittedParameterError, parameters.keys unless @permitted
|
74
|
+
|
75
|
+
parameters.transform_values { process_nested(_1, :to_h) }
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def nested_attribute(attribute)
|
81
|
+
if attribute.is_a? Hash
|
82
|
+
Parameters.new(attribute)
|
83
|
+
elsif attribute.is_a?(Array) && attribute[0].is_a?(Hash)
|
84
|
+
attribute.map { Parameters.new(_1) }
|
85
|
+
else
|
86
|
+
attribute
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def process_nested(attribute, method, options = [])
|
91
|
+
if attribute.is_a? Parameters
|
92
|
+
attribute.send(method, *options)
|
93
|
+
elsif attribute.is_a?(Array) && attribute[0].is_a?(Parameters)
|
94
|
+
attribute.map { _1.send(method, *options) }
|
95
|
+
else
|
96
|
+
attribute
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
attr_reader :parameters
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ruby-next"
|
4
|
+
require "ruby-next/language/setup"
|
5
|
+
|
6
|
+
RubyNext::Language.setup_gem_load_path(transpile: true)
|
7
|
+
|
8
|
+
module ActiveFunction
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
require "active_function/version"
|
12
|
+
require "active_function/base"
|
13
|
+
end
|
data/sig/manifest.yml
ADDED
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activefunction
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nerbyk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-02-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby-next-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.14.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.14.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby-next
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.14.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.14.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '13.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '13.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 5.15.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 5.15.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-reporters
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.4.3
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.4.3
|
83
|
+
description: "\n rails/action_controller like gem which provides lightweight callbacks,\n
|
84
|
+
\ strong parameters & rendering features. It's designed to be used with\n AWS
|
85
|
+
Lambda functions, but can be also used with any Ruby application.\n\n Implemented
|
86
|
+
with some of ruby 3.x features, but also supports\n ruby 2.6.x thanks to RubyNext
|
87
|
+
transpiler. Type safety achieved\n by RBS and Steep.\n "
|
88
|
+
email:
|
89
|
+
- danil.maximov2000@gmail.com
|
90
|
+
executables: []
|
91
|
+
extensions: []
|
92
|
+
extra_rdoc_files: []
|
93
|
+
files:
|
94
|
+
- CHANGELOG.md
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- bin/console
|
98
|
+
- bin/rake
|
99
|
+
- bin/setup
|
100
|
+
- lib/active_function.rb
|
101
|
+
- lib/active_function/base.rb
|
102
|
+
- lib/active_function/functions/callbacks.rb
|
103
|
+
- lib/active_function/functions/core.rb
|
104
|
+
- lib/active_function/functions/rendering.rb
|
105
|
+
- lib/active_function/functions/response.rb
|
106
|
+
- lib/active_function/functions/strong_parameters.rb
|
107
|
+
- lib/active_function/version.rb
|
108
|
+
- sig/active_function.rbs
|
109
|
+
- sig/manifest.yml
|
110
|
+
homepage: https://github.com/DanilMaximov/acitvefunction
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata:
|
114
|
+
homepage_uri: https://github.com/DanilMaximov/activefunction
|
115
|
+
source_code_uri: https://github.com/DanilMaximov/activefunction
|
116
|
+
changelog_uri: https://github.com/DanilMaximov/activefunction/CHANGELOG.md
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '2.6'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubygems_version: 3.3.26
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: rails/action_controller like gem which provides callbacks, strong parameters
|
136
|
+
& rendering features.
|
137
|
+
test_files: []
|