func_e 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 54aa55b846ee0e8ada8a7e6c80695c1501c5808e241d0c4f70d012007caab118
4
+ data.tar.gz: eb92635652cacc884d217a98fdf168638f623d68dc4f67ae60167c209476cb8c
5
+ SHA512:
6
+ metadata.gz: 83d04746a06e134e3c7025e40934138720ba04dfd8668fd45a65b70c8a05729106b751cd4fd8aa603e7c03e0bf7b9b8a22e106437d75f2d219b632f8aec8b41e
7
+ data.tar.gz: 51e032b985be92c10b4b42a271b875f76a6c968d5f083a6244459f68a72c4ad9296a8b6f4f6fc17aee5e7a3e2a3166453ac711db92919ffa06a21ccece06529c
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'singleton'
4
+
5
+ # Path: func_e/lib/func_e/config.rb
6
+ module FuncE
7
+ # Singleton class for configuring FuncE.
8
+ class Config
9
+ include Singleton
10
+
11
+ attr_accessor :fn_dir_path
12
+
13
+ def self.configure
14
+ yield instance
15
+
16
+ @fn_dir_path = 'funcs' if @fn_dir_path.nil?
17
+ end
18
+
19
+ def self.config
20
+ instance
21
+ end
22
+
23
+ def self.get(key)
24
+ instance.send(key)
25
+ end
26
+
27
+ def self.install_path
28
+ defined?(Rails) ? Rails.root.join(@fn_dir_path) : Bundler.root.join(@fn_dir_path)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FuncE
4
+ # Represents a function that can be executed.
5
+ class Func
6
+ attr_reader :name, :result, :payload, :run_at, :run_time
7
+
8
+ def initialize(name)
9
+ @name = name
10
+ @path = path
11
+ end
12
+
13
+ def path
14
+ FuncE::Config.install_path.join("#{@name}.js")
15
+ end
16
+
17
+ def run(payload)
18
+ @payload = payload
19
+
20
+ benchmark do
21
+ @result = FuncE.exec(self)
22
+ end
23
+
24
+ @result
25
+ end
26
+
27
+ def serialize_payload
28
+ @payload.to_json
29
+ end
30
+
31
+ def exists?
32
+ File.exist?(@path)
33
+ end
34
+
35
+ private
36
+
37
+ def benchmark
38
+ @run_at = Time.current
39
+ yield
40
+ @run_time = Time.current - @run_at
41
+ end
42
+ end
43
+ end
data/lib/func_e.rb ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'terrapin'
4
+ require 'func_e/func'
5
+ require 'func_e/config'
6
+
7
+ # Path: lib/funcy.rb
8
+ module FuncE
9
+ require 'railtie' if defined?(Rails)
10
+
11
+ RUNNER_PATH = "#{File.expand_path(__dir__)}/func_e.js"
12
+
13
+ def self.exec(func)
14
+ JSON.parse line.run(path: func.path, payload: func.serialize_payload), symbolize_names: true
15
+ rescue Terrapin::CommandLineError => e
16
+ { error: 'An error occurred while executing the node function.', message: e.message }
17
+ end
18
+
19
+ def self.line
20
+ Terrapin::CommandLine.new("node #{RUNNER_PATH}", '--path=:path --payload=:payload', logger: Logger.new($stdout))
21
+ end
22
+ end
data/lib/railtie.rb ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # lib/railtie.rb
4
+ require 'func_e'
5
+ require 'rails'
6
+
7
+ module FuncE
8
+ # This class is used to load rake tasks for the gem
9
+ class Railtie < Rails::Railtie
10
+ railtie_name :func_e
11
+
12
+ rake_tasks do
13
+ path = File.expand_path(__dir__)
14
+ Dir.glob("#{path}/tasks/**/*.rake").each { |f| load f }
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: func_e
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sebastian Scholl
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-08-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: terrapin
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.6'
41
+ description: FuncE is a lightweight Ruby gem that allows developers to call JavaScript
42
+ functions from within Ruby applications. By providing a clean interface between
43
+ Node.js functions and Ruby, FuncE offers a Function-as-a-Service (FaaS)-like experience
44
+ without the overhead of managing and deploying endpoints. It supports asynchronous
45
+ functions and the use of required packages, making it a versatile tool for modern
46
+ web applications.
47
+ email:
48
+ - sebscholl@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/func_e.rb
54
+ - lib/func_e/config.rb
55
+ - lib/func_e/func.rb
56
+ - lib/railtie.rb
57
+ homepage: https://github.com/sebscholl/FuncE
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ rubygems_mfa_required: 'true'
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '2.5'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubygems_version: 3.5.5
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: FuncE provides an interface between Node.js functions and Ruby applications,
81
+ enabling easy integration without the need for deploying functions with endpoints.
82
+ test_files: []