activefunction-core 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a64c7260d306142ff9c0b5e48d0cd34c9258e65af3e19bbd7aa6b1121a8a3eff
4
+ data.tar.gz: 14514dbbad34d5f8b64fadd0b146c5a1f90a955578cbf5e51fe161af4d5939ad
5
+ SHA512:
6
+ metadata.gz: 13038598288b048965d93d6299bc7fe1feda28f28bcee220c87d5361f59060e43c07d44089279840da2c3877dd8a100aacad5b32216a692b9497f431ebab0cdc
7
+ data.tar.gz: 3522dd0d9db78ac518093fc9b7f4bf9be48da2593ef63fe0766e7a51b04ab729b63ef521fdc5a0f115fabac0f7207268d02cb586f3aabd50561408adabd47464
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## [0.1.0]
2
+
3
+ - Introduce ruby-next integration
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 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,154 @@
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
+ ## A Short Example
9
+
10
+ Here's a simple example of a function that uses ActiveFunction:
11
+
12
+ ```ruby
13
+ require 'active_function'
14
+
15
+ class AppFunction < ActiveFunction::Base
16
+ def index
17
+ render json: SomeTable.all
18
+ end
19
+ end
20
+ ```
21
+
22
+ Use `#process` method to proceed the request:
23
+
24
+ ```ruby
25
+ AppFunction.process(:index) # processes index action of AppFunction instance
26
+ ```
27
+ Also check extended [example](https://github.com/DanilMaximov/activefunction/tree/master/active_function_example)
28
+ ## Callbacks
29
+ ActiveFunction supports simple callbacks `:before` and `:after` which runs around provided action in `#process`.
30
+
31
+ ```ruby
32
+ class AppFunction < ActiveFunction::Base
33
+ before_action :set_user
34
+ after_action :log_response
35
+
36
+ # some action ...
37
+
38
+ private
39
+
40
+ def set_user
41
+ @user = User.first
42
+ end
43
+
44
+ def log_response
45
+ Logger.info @response
46
+ end
47
+ end
48
+ ```
49
+
50
+ Callbacks also can be user with `only: Array[Symbol]` and `if: Symbol` options.
51
+
52
+ ```ruby
53
+ class AppFunction < ActiveFunction::Base
54
+ before_action :set_user, only: %i[show update destroy], if: :request_valid?
55
+
56
+ # some actions ...
57
+
58
+ private def request_valid? = true
59
+ end
60
+ ```
61
+
62
+ Callbacks are inheritable so all callbacks calls will be inherited from base class
63
+ ```ruby
64
+ class BaseFunction < ActiveFunction::Base
65
+ before_action :set_current_user
66
+
67
+ def set_current_user
68
+ @current_user = User.first
69
+ end
70
+ end
71
+
72
+ class PostsFunction < BaseFunction
73
+ def index
74
+ render json: @current_user
75
+ end
76
+ end
77
+ ```
78
+ ## Strong Parameters
79
+ ActiveFunction supports strong parameters which can be accessed by `#params` instance method. Strong parameters hash can be passed in `#process` as second argument.
80
+
81
+ ```ruby
82
+ PostFunction.process(:index, data: { id: 1, name: "Pupa" })
83
+ ```
84
+
85
+ Simple usage:
86
+ ```ruby
87
+ class PostsFunction < ActiveFunction::Base
88
+ def index
89
+ render json: permitted_params
90
+ end
91
+
92
+ def permitted_params = params
93
+ .require(:data)
94
+ .permit(:id, :name)
95
+ .to_h
96
+ end
97
+ ```
98
+ Strong params supports nested attributes
99
+ ```ruby
100
+ params.permit(:id, :name, :address => [:city, :street])
101
+ ```
102
+
103
+ ## Rendering
104
+ ActiveFunction supports rendering of JSON. Rendering is obligatory for any function naction and can be done by `#render` method.
105
+ ```ruby
106
+ class PostsFunction < ActiveFunction::Base
107
+ def index
108
+ render json: { id: 1, name: "Pupa" }
109
+ end
110
+ end
111
+ ```
112
+ default status code is 200, but it can be changed by `:status` option
113
+ ```ruby
114
+ class PostsFunction < ActiveFunction::Base
115
+ def index
116
+ render json: { id: 1, name: "Pupa" }, status: 201
117
+ end
118
+ end
119
+ ```
120
+ Headers can be passed by `:headers` option. Default headers are `{"Content-Type" => "application/json"}`.
121
+ ```ruby
122
+ class PostsFunction < ActiveFunction::Base
123
+ def index
124
+ render json: { id: 1, name: "Pupa" }, headers: { "X-Request-Id" => "123" }
125
+ end
126
+ end
127
+ ```
128
+
129
+
130
+ ## Installation
131
+
132
+ Add this line to your application's Gemfile:
133
+
134
+ ```ruby
135
+ gem 'activefunction', git: "https://github.com/DanilMaximov/activefunction.git"
136
+ ```
137
+
138
+ ## Development
139
+
140
+ 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.
141
+
142
+ 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).
143
+
144
+ ## Contributing
145
+
146
+ 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).
147
+
148
+ ## License
149
+
150
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
151
+
152
+ ## Code of Conduct
153
+
154
+ 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).
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveFunctionCore
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ruby-next/language/setup"
4
+
5
+ RubyNext::Language.setup_gem_load_path(transpile: true)
6
+
7
+ module ActiveFunctionCore
8
+ class Error < StandardError; end
9
+
10
+ require "active_function_core/version"
11
+ end
@@ -0,0 +1,4 @@
1
+ module ActiveFunction
2
+ class Error < StandardError
3
+ end
4
+ end
data/sig/manifest.yml ADDED
@@ -0,0 +1,2 @@
1
+ dependencies:
2
+
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activefunction-core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nerbyk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-08-20 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.15'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.15.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.15'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.15.3
33
+ description: Provides core functionality, plugins and ruby-next integration for ActiveFunction
34
+ email:
35
+ - danil.maximov2000@gmail.com
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - CHANGELOG.md
41
+ - LICENSE.txt
42
+ - README.md
43
+ - lib/active_function_core.rb
44
+ - lib/active_function_core/version.rb
45
+ - sig/active_function_core.rbs
46
+ - sig/manifest.yml
47
+ homepage: https://github.com/DanilMaximov/activefunction
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ homepage_uri: https://github.com/DanilMaximov/activefunction-core
52
+ source_code_uri: https://github.com/DanilMaximov/activefunction-core
53
+ changelog_uri: https://github.com/DanilMaximov/activefunction-core/CHANGELOG.md
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '2.6'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.1.6
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: ActiveFunction core gem
73
+ test_files: []