activefunction 0.3.3 → 0.3.5
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 +4 -4
- data/CHANGELOG.md +10 -0
- data/bin/rubocop +27 -0
- data/bin/ruby-next +16 -0
- data/lib/.rbnext/2.7/active_function/functions/strong_parameters.rb +104 -0
- data/lib/.rbnext/3.0/active_function/functions/core.rb +49 -0
- data/lib/.rbnext/3.0/active_function/functions/response.rb +30 -0
- data/lib/active_function/version.rb +1 -1
- data/lib/active_function.rb +1 -2
- metadata +11 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 291381221a57e279bfad4dddf88cbeb3695a83e2b4882960b1255304e01a78db
|
4
|
+
data.tar.gz: 8a2a8d432700fff63717b76198bc032986bc2c6656e7eb9dbf034f78552bcb29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70f3d994a4703b373f91a4df21e0b02a424f0a049a391caf04558ffbcebd80546a3f6683fce5c5a66111336d0827aaa2049ce4b5fbafa64fa7720e13278cf2b7
|
7
|
+
data.tar.gz: fc0bd5b0c69e64147e7d1729c179c5ef44a931733b9b71b3adec4aa623a7f01f50d70553c7bd58ade6080c2f4e8dab52d2716ebea0b042556296a17d61276e0c
|
data/CHANGELOG.md
CHANGED
@@ -37,3 +37,13 @@
|
|
37
37
|
- Finish readme
|
38
38
|
- Fix callbacks broken by `prepend` change
|
39
39
|
- Add more tests for `#process` public interface
|
40
|
+
|
41
|
+
# [0.3.4] - 2023-05-02
|
42
|
+
|
43
|
+
- Fix RubyNext runtime integration
|
44
|
+
|
45
|
+
# [0.3.5] - 2023-08-20
|
46
|
+
|
47
|
+
- Start gem restructuring for modularizaition
|
48
|
+
- Introduce `activefunction-core` gem with RubyNext integration
|
49
|
+
|
data/bin/rubocop
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 'rubocop' 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).include?("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("rubocop", "rubocop")
|
data/bin/ruby-next
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib_path = File.expand_path("../lib", __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
|
5
|
+
|
6
|
+
require "ruby-next/cli"
|
7
|
+
|
8
|
+
begin
|
9
|
+
cli = RubyNext::CLI.new
|
10
|
+
cli.run(ARGV)
|
11
|
+
rescue => e
|
12
|
+
raise e if $DEBUG
|
13
|
+
STDERR.puts e.message
|
14
|
+
STDERR.puts e.backtrace.join("\n") if ENV["RUBY_NEXT_DEBUG"] == "1"
|
15
|
+
exit 1
|
16
|
+
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 { |_1| 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 { |_1| 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| _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,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); end
|
45
|
+
|
46
|
+
def performed? ; @response.committed?; end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
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; end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/active_function.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activefunction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nerbyk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activefunction-core
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.0.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 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
|
26
|
+
version: 0.0.1
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rake
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,7 +82,12 @@ files:
|
|
96
82
|
- README.md
|
97
83
|
- bin/console
|
98
84
|
- bin/rake
|
85
|
+
- bin/rubocop
|
86
|
+
- bin/ruby-next
|
99
87
|
- bin/setup
|
88
|
+
- lib/.rbnext/2.7/active_function/functions/strong_parameters.rb
|
89
|
+
- lib/.rbnext/3.0/active_function/functions/core.rb
|
90
|
+
- lib/.rbnext/3.0/active_function/functions/response.rb
|
100
91
|
- lib/active_function.rb
|
101
92
|
- lib/active_function/base.rb
|
102
93
|
- lib/active_function/functions/callbacks.rb
|
@@ -129,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
120
|
- !ruby/object:Gem::Version
|
130
121
|
version: '0'
|
131
122
|
requirements: []
|
132
|
-
rubygems_version: 3.
|
123
|
+
rubygems_version: 3.4.10
|
133
124
|
signing_key:
|
134
125
|
specification_version: 4
|
135
126
|
summary: rails/action_controller like gem which provides callbacks, strong parameters
|