+
+
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
deleted file mode 100644
index 4dc68c6f..00000000
--- a/CHANGELOG.md
+++ /dev/null
@@ -1,2 +0,0 @@
-# Changelog
-
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
deleted file mode 100644
index 57a8ac3c..00000000
--- a/CONTRIBUTING.md
+++ /dev/null
@@ -1,32 +0,0 @@
-# Contributing
-
-Want to contribute? Great! First, read this page (including the small print at the end).
-
-### Before you contribute
-
-Before we can use your code, you must sign the
-[Google Individual Contributor License Agreement]
-(https://cla.developers.google.com/about/google-individual)
-(CLA), which you can do online. The CLA is necessary mainly because you own the
-copyright to your changes, even after your contribution becomes part of our
-codebase, so we need your permission to use and distribute your code. We also
-need to be sure of various other things—for instance that you'll tell us if you
-know that your code infringes on other people's patents. You don't have to sign
-the CLA until after you've submitted your code for review and a member has
-approved it, but you must do it before we can put your code into our codebase.
-Before you start working on a larger contribution, you should get in touch with
-us first through the issue tracker with your idea so that we can help out and
-possibly guide you. Coordinating up front makes it much easier to avoid
-frustration later on.
-
-### Code reviews
-
-All submissions, including submissions by project members, require review. We
-use Github pull requests for this purpose.
-
-### The small print
-
-Contributions made by corporations are covered by a different agreement than
-the one above, the
-[Software Grant and Corporate Contributor License Agreement]
-(https://cla.developers.google.com/about/google-corporate).
diff --git a/Gemfile b/Gemfile
deleted file mode 100644
index fdadff04..00000000
--- a/Gemfile
+++ /dev/null
@@ -1,17 +0,0 @@
-# Copyright 2020 Google LLC
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-source "https://rubygems.org"
-
-gemspec
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index 7f8889ba..00000000
--- a/LICENSE
+++ /dev/null
@@ -1,201 +0,0 @@
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "{}"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright {yyyy} {name of copyright owner}
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
\ No newline at end of file
diff --git a/README.md b/README.md
deleted file mode 100644
index 46f633ce..00000000
--- a/README.md
+++ /dev/null
@@ -1,18 +0,0 @@
-# Functions Framework
-
-## Installation
-
-```
-$ gem install functions_framework
-```
-
-## Supported Ruby Versions
-
-This library is supported on Ruby 2.4+.
-
-Google provides official support for Ruby versions that are actively supported
-by Ruby Core—that is, Ruby versions that are either in normal maintenance or
-in security maintenance, and not end of life. Currently, this means Ruby 2.4
-and later. Older versions of Ruby _may_ still work, but are unsupported and not
-recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
-about the Ruby support schedule.
diff --git a/functions_framework.gemspec b/functions_framework.gemspec
deleted file mode 100644
index 5ae72070..00000000
--- a/functions_framework.gemspec
+++ /dev/null
@@ -1,49 +0,0 @@
-# frozen_string_literal: true
-
-# Copyright 2020 Google LLC
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-lib = File.expand_path "lib", __dir__
-$LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
-require "functions_framework/version"
-
-::Gem::Specification.new do |spec|
- spec.name = "functions_framework"
- spec.version = ::FunctionsFramework::VERSION
- spec.authors = ["Daniel Azuma"]
- spec.email = ["dazuma@google.com"]
-
- spec.summary = "Functions Framework for Ruby"
- spec.description =
- "The Functions Framework implementation for Ruby."
- spec.license = "Apache-2.0"
- spec.homepage = "https://github.com/GoogleCloudPlatform/functions-framework-ruby"
-
- spec.files = ::Dir.glob("lib/**/*.rb") +
- ::Dir.glob("*.md") +
- ["LICENSE", ".yardopts"]
- spec.required_ruby_version = ">= 2.4.0"
- spec.require_paths = ["lib"]
-
- spec.add_dependency "puma", "~> 4.3"
- spec.add_dependency "rack", "~> 2.1"
-
- spec.add_development_dependency "google-style", "~> 1.24.0"
- spec.add_development_dependency "minitest", "~> 5.13"
- spec.add_development_dependency "minitest-focus", "~> 1.1"
- spec.add_development_dependency "minitest-rg", "~> 5.2"
- spec.add_development_dependency "redcarpet", "~> 3.5"
- spec.add_development_dependency "toys", "~> 0.9.3"
- spec.add_development_dependency "yard", "~> 0.9.24"
-end
diff --git a/index.html b/index.html
new file mode 100644
index 00000000..dc155b1f
--- /dev/null
+++ b/index.html
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/functions_framework.rb b/lib/functions_framework.rb
deleted file mode 100644
index b2d0abf8..00000000
--- a/lib/functions_framework.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright 2020 Google LLC
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# https://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-require "functions_framework/version"
-
-##
-# The Functions Framework for Ruby
-#
-module FunctionsFramework
-end
diff --git a/lib/functions_framework/version.rb b/lib/functions_framework/version.rb
deleted file mode 100644
index 78569202..00000000
--- a/lib/functions_framework/version.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright 2020 Google LLC
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# https://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-module FunctionsFramework
- ##
- # Version of the Ruby Functions Framework
- # @return [String]
- #
- VERSION = "0.0.0".freeze
-end
diff --git a/test/helper.rb b/test/helper.rb
deleted file mode 100644
index 85eebdf5..00000000
--- a/test/helper.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# Copyright 2020 Google LLC
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# https://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-require "minitest/autorun"
-require "minitest/focus"
-require "minitest/rg"
-
-require "functions_framework"
diff --git a/test/test_version.rb b/test/test_version.rb
deleted file mode 100644
index bd1435f2..00000000
--- a/test/test_version.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# Copyright 2020 Google LLC
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# https://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-require "helper"
-
-describe FunctionsFramework::VERSION do
- let(:version) { FunctionsFramework::VERSION }
- it "is a legal version" do
- assert_instance_of String, version
- assert version.frozen?
- Gem::Version.new version
- end
-end
From f7ca861deeefa57ba02df3f4be86ceffaea56fb1 Mon Sep 17 00:00:00 2001
From: Daniel Azuma
Date: Fri, 17 Jul 2020 13:53:24 -0700
Subject: [PATCH 02/22] Add version 0.5.0 docs
---
404.html | 2 +-
v0.5.0/FunctionsFramework.html | 993 +++++++++++++
v0.5.0/FunctionsFramework/CLI.html | 545 +++++++
v0.5.0/FunctionsFramework/Function.html | 637 ++++++++
.../FunctionsFramework/Function/CallBase.html | 334 +++++
.../LegacyEventConverter.html | 272 ++++
v0.5.0/FunctionsFramework/Registry.html | 671 +++++++++
v0.5.0/FunctionsFramework/Server.html | 1004 +++++++++++++
v0.5.0/FunctionsFramework/Server/Config.html | 1322 +++++++++++++++++
v0.5.0/FunctionsFramework/Testing.html | 1199 +++++++++++++++
v0.5.0/_index.html | 218 +++
v0.5.0/class_list.html | 51 +
v0.5.0/css/common.css | 1 +
v0.5.0/css/full_list.css | 58 +
v0.5.0/css/style.css | 496 +++++++
v0.5.0/file.CHANGELOG.html | 155 ++
v0.5.0/file.deploying-functions.html | 251 ++++
v0.5.0/file.overview.html | 208 +++
v0.5.0/file.running-a-functions-server.html | 232 +++
v0.5.0/file.testing-functions.html | 229 +++
v0.5.0/file.writing-functions.html | 332 +++++
v0.5.0/file_list.html | 81 +
v0.5.0/frames.html | 17 +
v0.5.0/index.html | 208 +++
v0.5.0/js/app.js | 314 ++++
v0.5.0/js/full_list.js | 216 +++
v0.5.0/js/jquery.js | 4 +
v0.5.0/method_list.html | 459 ++++++
v0.5.0/top-level-namespace.html | 110 ++
29 files changed, 10618 insertions(+), 1 deletion(-)
create mode 100644 v0.5.0/FunctionsFramework.html
create mode 100644 v0.5.0/FunctionsFramework/CLI.html
create mode 100644 v0.5.0/FunctionsFramework/Function.html
create mode 100644 v0.5.0/FunctionsFramework/Function/CallBase.html
create mode 100644 v0.5.0/FunctionsFramework/LegacyEventConverter.html
create mode 100644 v0.5.0/FunctionsFramework/Registry.html
create mode 100644 v0.5.0/FunctionsFramework/Server.html
create mode 100644 v0.5.0/FunctionsFramework/Server/Config.html
create mode 100644 v0.5.0/FunctionsFramework/Testing.html
create mode 100644 v0.5.0/_index.html
create mode 100644 v0.5.0/class_list.html
create mode 100644 v0.5.0/css/common.css
create mode 100644 v0.5.0/css/full_list.css
create mode 100644 v0.5.0/css/style.css
create mode 100644 v0.5.0/file.CHANGELOG.html
create mode 100644 v0.5.0/file.deploying-functions.html
create mode 100644 v0.5.0/file.overview.html
create mode 100644 v0.5.0/file.running-a-functions-server.html
create mode 100644 v0.5.0/file.testing-functions.html
create mode 100644 v0.5.0/file.writing-functions.html
create mode 100644 v0.5.0/file_list.html
create mode 100644 v0.5.0/frames.html
create mode 100644 v0.5.0/index.html
create mode 100644 v0.5.0/js/app.js
create mode 100644 v0.5.0/js/full_list.js
create mode 100644 v0.5.0/js/jquery.js
create mode 100644 v0.5.0/method_list.html
create mode 100644 v0.5.0/top-level-namespace.html
diff --git a/404.html b/404.html
index 57744581..239f0e34 100644
--- a/404.html
+++ b/404.html
@@ -13,7 +13,7 @@
if (window.location.href.includes("//googlecloudplatform.github.io/functions-framework-ruby/latest")) {
var loc = window.location.href.replace(
"//googlecloudplatform.github.io/functions-framework-ruby/latest",
- "//googlecloudplatform.github.io/functions-framework-ruby/v" + version);
+ "//googlecloudplatform.github.io/functions-framework-ruby/v" + version + "/file.overview.html");
window.location.replace(loc);
} else {
window.location.replace("https://googlecloudplatform.github.io/functions-framework-ruby/latest");
diff --git a/v0.5.0/FunctionsFramework.html b/v0.5.0/FunctionsFramework.html
new file mode 100644
index 00000000..a66d0056
--- /dev/null
+++ b/v0.5.0/FunctionsFramework.html
@@ -0,0 +1,993 @@
+
+
+
+
+
+Codestin Search App
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Here is a roadmap to the internal modules in the Ruby functions framework.
+
+
+
CLI is the implementation of the
+functions-framework-ruby executable. Most apps will not need to interact
+with this class directly.
+
Function is the internal representation of a
+function, indicating the type of function (http or cloud event), the
+name of the function, and the block of code implementing it. Most apps
+do not need to interact with this class directly.
+
Registry looks up functions by name. When you
+define a set of named functions, they are added to a registry, and when
+you start a server and specify the target function by name, it is looked
+up from the registry. Most apps do not need to interact with this class
+directly.
+
Server is a web server that makes a function
+available via HTTP. It wraps the Puma web server and runs a specific
+Function. Many apps can simply run the
+functions-framework-ruby executable to spin up a server. However, if you
+need closer control over your execution environment, you can use the
+Server class to run a server. Note that, in most
+cases, it is easier to use the FunctionsFramework.start or
+FunctionsFramework.run wrapper methods rather than instantiate a
+Server class directly.
+
Testing provides helpers that are useful when
+writing unit tests for functions.
The default target function name. If you define a function without
+specifying a name, or run the framework without giving a target, this name
+is used.
+
+
+
+
+
+
+
Returns:
+
+
+
+
+
+ (String)
+
+
+
+
+
+
+
+
+
+
"function".freeze
+
+
DEFAULT_SOURCE =
+
+
+
The default source file path. The CLI loads functions from this file if no
+source file is given explicitly.
+
+
+
+
+
+
+
Returns:
+
+
+
+
+
+ (String)
+
+
+
+
+
+
+
+
+
+
"./app.rb".freeze
+
+
CloudEvents =
+
+
+
The CloudEvents implementation was extracted to become the official
+CloudEvents SDK. This alias is left here for backward compatibility.
You must provide a name for the function, and a block that implemets the
+function. The block should take one argument: the event object of type
+CloudEvents::Event.
+Any return value is ignored.
You must provide a name for the function, and a block that implemets the
+function. The block should take a single Rack::Request argument. It
+should return one of the following:
# File 'lib/functions_framework/cli.rb', line 54
+
+defparse_argsargv# rubocop:disable Metrics/MethodLength
+option_parser=::OptionParser.newdo|op|# rubocop:disable Metrics/BlockLength
+op.on"-t","--target TARGET",
+ "Set the name of the function to execute (defaults to #{DEFAULT_TARGET})"do|val|
+ @target=val
+ end
+ op.on"-s","--source SOURCE",
+ "Set the source file to load (defaults to #{DEFAULT_SOURCE})"do|val|
+ @source=val
+ end
+ op.on"--signature-type TYPE",
+ "Asserts that the function has the given signature type." \
+ " Supported values are 'http' and 'cloudevent'."do|val|
+ @signature_type=val
+ end
+ op.on"-p","--port PORT","Set the port to listen to (defaults to 8080)"do|val|
+ @port=val.to_i
+ end
+ op.on"-b","--bind BIND","Set the address to bind to (defaults to 0.0.0.0)"do|val|
+ @bind=val
+ end
+ op.on"-e","--environment ENV","Set the Rack environment"do|val|
+ @env=val
+ end
+ op.on"--min-threads NUM","Set the minimum threead pool size"do|val|
+ @min_threads=val
+ end
+ op.on"--max-threads NUM","Set the maximum threead pool size"do|val|
+ @max_threads=val
+ end
+ op.on"--[no-]detailed-errors","Set whether to show error details"do|val|
+ @detailed_errors=val
+ end
+ op.on"-v","--verbose","Increase log verbosity"do
+ @logging_level-=1
+ end
+ op.on"-q","--quiet","Decrease log verbosity"do
+ @logging_level+=1
+ end
+ op.on"--help","Display help"do
+ putsop
+ exit
+ end
+ end
+ option_parser.parse!argv
+ error"Unrecognized arguments: #{argv}\n#{op}"unlessargv.empty?
+ self
+end
+
+
+
+
+
+
+
+
+ #run ⇒ self
+
+
+
+
+
+
+
+
Run the configured server, and block until it stops.
+If a validation error occurs, print a message and exit.
+
+
+
+
+
+
+
Returns:
+
+
+
+
+
+ (self)
+
+
+
+
+
+
+
+
+
+
+
+
+
+109
+110
+111
+112
+113
+114
+115
+116
+117
+
+
+
# File 'lib/functions_framework/cli.rb', line 109
+
+defrun
+ begin
+ server=start_server
+ rescue::StandardError=>e
+ errore.message
+ end
+ server.wait_until_stopped
+ self
+end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/v0.5.0/FunctionsFramework/Function.html b/v0.5.0/FunctionsFramework/Function.html
new file mode 100644
index 00000000..35ddff4a
--- /dev/null
+++ b/v0.5.0/FunctionsFramework/Function.html
@@ -0,0 +1,637 @@
+
+
+
+
+
+Codestin Search App
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
A function has a name, a type, and an implementation.
+
+
The implementation in general is an object that responds to the call
+method. For a function of type :http, the call method takes a single
+Rack::Request argument and returns one of various HTTP response types.
+See Registry.add_http. For a function of type
+:cloud_event, the call method takes a single
+CloudEvent
+argument, and does not return a value.
+See Registry.add_cloud_event.
+
+
If a callable object is provided directly, its call method is invoked for
+every function execution. Note that this means it may be called multiple
+times concurrently in separate threads.
+
+
Alternately, the implementation may be provided as a class that should be
+instantiated to produce a callable object. If a class is provided, it should
+either subclass CallBase or respond to the
+same constructor interface, i.e. accepting arbitrary keyword arguments. A
+separate callable object will be instantiated from this class for every
+function invocation, so each instance will be used for only one invocation.
+
+
Finally, an implementation can be provided as a block. If a block is
+provided, it will be recast as a call method in an anonymous subclass of
+CallBase. Thus, providing a block is really
+just syntactic sugar for providing a class. (This means, for example, that
+the return keyword will work within the block because it is treated as a
+method.)
# File 'lib/functions_framework/function.rb', line 58
+
+definitializename,type,callable=nil,&block
+ @name=name
+ @type=type
+ @callable=@callable_class=nil
+ ifcallable.respond_to?:call
+ @callable=callable
+ elsifcallable.is_a?::Class
+ @callable_class=callable
+ elsifblock_given?
+ @callable_class=::Class.newCallBasedo
+ define_method:call,&block
+ end
+ else
+ raise::ArgumentError,"No callable given for function"
+ end
+end
+
+
+
+
+
+
+
+
+
Instance Attribute Details
+
+
+
+
+
+
+ #name ⇒ String(readonly)
+
+
+
+
+
+
+
+
Returns The function name.
+
+
+
+
+
+
+
Returns:
+
+
+
+
+
+ (String)
+
+
+
+ —
+
The function name
+
+
+
+
+
+
+
+
+
+
+
+
+78
+79
+80
+
+
+
# File 'lib/functions_framework/function.rb', line 78
+
+defname
+ @name
+end
+
+
+
+
+
+
+
+
+
+
+ #type ⇒ Symbol(readonly)
+
+
+
+
+
+
+
+
Returns The function type.
+
+
+
+
+
+
+
Returns:
+
+
+
+
+
+ (Symbol)
+
+
+
+ —
+
The function type
+
+
+
+
+
+
+
+
+
+
+
+
+83
+84
+85
+
+
+
# File 'lib/functions_framework/function.rb', line 83
+
+deftype
+ @type
+end
+
+
+
+
+
+
+
+
+
+
Instance Method Details
+
+
+
+
+
+ #new_call(logger: nil) ⇒ #call
+
+
+
+
+
+
+
+
Get a callable for performing a function invocation. This will either
+return the singleton callable object, or instantiate a new callable from
+the configured class.
A set of context arguments. See #context for
+a list of keys that will generally be passed in. However,
+implementations should be prepared to accept any abritrary keys.
+
+
+
+
+
+
+
+
+
+
+
+
+
+113
+114
+115
+
+
+
# File 'lib/functions_framework/function.rb', line 113
+
+definitialize**context
+ @context=context
+end
+
+
+
+
+
+
+
+
+
Instance Attribute Details
+
+
+
+
+
+
+ #context ⇒ Hash(readonly)
+
+
+
+
+
+
+
+
A keyed hash of context information. Common context keys include:
+
+
+
:logger (Logger) A logger for use by this function call.
+
:function_name (String) The name of the running function.
+
:function_type (Symbol) The type of the running function,
+either :http or :cloud_event.
+
+
+
+
+
+
+
+
Returns:
+
+
+
+
+
+ (Hash)
+
+
+
+
+
+
+
+
+
+
+
+
+
+127
+128
+129
+
+
+
# File 'lib/functions_framework/function.rb', line 127
+
+defcontext
+ @context
+end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/v0.5.0/FunctionsFramework/LegacyEventConverter.html b/v0.5.0/FunctionsFramework/LegacyEventConverter.html
new file mode 100644
index 00000000..a7c4226c
--- /dev/null
+++ b/v0.5.0/FunctionsFramework/LegacyEventConverter.html
@@ -0,0 +1,272 @@
+
+
+
+
+
+Codestin Search App
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
You must provide a name for the function, and a block that implemets the
+function. The block should take one argument: the event object of type
+CloudEvents::Event.
+Any return value is ignored.
You must provide a name for the function, and a block that implemets the
+function. The block should take a single Rack::Request argument. It
+should return one of the following:
Create a new web server given a function. Yields a
+Config object that you can use to set
+server configuration parameters. This block is the only opportunity to
+set configuration; once the server is initialized, configuration is
+frozen.
# File 'lib/functions_framework/server.rb', line 143
+
+defrespond_to_signals
+ synchronizedo
+ returnselfif@signals_installed
+ ::Signal.trap"SIGTERM"do
+ Server.signal_enqueue"SIGTERM",@config.logger,@server
+ end
+ ::Signal.trap"SIGINT"do
+ Server.signal_enqueue"SIGINT",@config.logger,@server
+ end
+ begin
+ ::Signal.trap"SIGHUP"do
+ Server.signal_enqueue"SIGHUP",@config.logger,@server
+ end
+ rescue::ArgumentError# rubocop:disable Lint/HandleExceptions
+# Not available on all systems
+end
+ @signals_installed=true
+ end
+ self
+end
+
+
+
+
+
+
+
+
+ #running? ⇒ Boolean
+
+
+
+
+
+
+
+
Determine if the web server is currently running
+
+
+
+
+
+
+
Returns:
+
+
+
+
+
+ (Boolean)
+
+
+
+
+
+
+
+
+
+
+
+
+
+133
+134
+135
+
+
+
# File 'lib/functions_framework/server.rb', line 133
+
+defrunning?
+ @server&.thread&.alive?
+end
+
+
+
+
+
+
+
+
+ #start ⇒ self
+
+
+
+
+
+
+
+
Start the web server in the background. Does nothing if the web server
+is already running.
The web server configuration. This object is yielded from the
+FunctionsFramework::Server constructor and can be modified at that
+point. Afterward, it is available from #config
+but it is frozen.
The following is a test that could be run against that app:
+
+
# test_app.rb
+
+require"minitest/autorun"
+require"functions_framework/testing"
+
+classMyTest<Minitest::Test
+ # Make the testing methods available.
+includeFunctionsFramework::Testing
+
+ deftest_my_function
+ # Load app.rb and apply its functions within this block
+load_temporary"app.rb"do
+ # Create a mock http (rack) request
+request=make_get_request"http://example.com"
+
+ # Call the function and get a rack response
+response=call_http"my-function",request
+
+ # Assert against the response
+assert_equal"Hello, world!",response.body.join
+ end
+ end
+end
+
Call the given HTTP function for testing. The underlying function must
+be of type :http.
+
+
+
+
+
+
Parameters:
+
+
+
+
+ name
+
+
+ (String)
+
+
+
+ —
+
The name of the function to call
+
+
+
+
+
+
+ request
+
+
+ (Rack::Request)
+
+
+
+ —
+
The Rack request to send
+
+
+
+
+
+
+
Returns:
+
+
+
+
+
+ (Rack::Response)
+
+
+
+
+
+
+
+
+
+
+
+
+
+86
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+
+
+
# File 'lib/functions_framework/testing.rb', line 86
+
+defcall_httpname,request
+ function=::FunctionsFramework.global_registry[name]
+ casefunction&.type
+ when:http
+ Testing.interpret_response{function.new_call.callrequest}
+ whennil
+ raise"Unknown function name #{name}"
+ else
+ raise"Function #{name} is not an HTTP function"
+ end
+end
Make a simple CloudEvent, for passing to a function test. The event data
+is required, but all other parameters are optional (i.e. a reasonable or
+random value will be generated if not provided).
+
+
+
+
+
+
Parameters:
+
+
+
+
+ data
+
+
+ (Object)
+
+
+
+ —
+
The data
+
+
+
+
+
+
+ id
+
+
+ (String)
+
+
+ (defaults to: nil)
+
+
+ —
+
HTTP headers. May be given as a hash (of
+header names mapped to values), an array of strings (where each
+string is of the form Header-Name: Header value), or an array of
+two-element string arrays.
+
+
+
+
+
+
+
Returns:
+
+
+
+
+
+ (Rack::Request)
+
+
+
+
+
+
+
+
+
+
+
+
+
+148
+149
+150
+
+
+
# File 'lib/functions_framework/testing.rb', line 148
+
+defmake_get_requesturl,headers=[]
+ make_requesturl,headers:headers
+end
HTTP headers. May be given as a hash (of
+header names mapped to values), an array of strings (where each
+string is of the form Header-Name: Header value), or an array of
+two-element string arrays.
+
+
+
+
+
+
+
Returns:
+
+
+
+
+
+ (Rack::Request)
+
+
+
+
+
+
+
+
+
+
+
+
+
+163
+164
+165
+
+
+
# File 'lib/functions_framework/testing.rb', line 163
+
+defmake_post_requesturl,body,headers=[]
+ make_requesturl,method:::Rack::POST,body:body,headers:headers
+end
HTTP headers. May be given as a hash (of
+header names mapped to values), an array of strings (where each
+string is of the form Header-Name: Header value), or an array of
+two-element string arrays.
Removed embedded CloudEvents classes and added the official CloudEvents SDK as a dependency. A FunctionsFramework::CloudEvents alias provides backward compatibility.
+
+
+
v0.4.1 / 2020-07-08
+
+
+
Fixed unsupported signal error on Windows.
+
Fixed several edge case errors in legacy event conversion.
+
Generated Content-Type headers now properly quote param values if needed.
+
Minor documentation updates.
+
+
+
v0.4.0 / 2020-06-29
+
+
+
Dropped the legacy and largely unsupported :event function type. All event functions should be of type :cloud_event.
+
Define the object context for function execution, and include an extensible context helper.
+
Support for CloudEvents with specversion 0.3.
+
CloudEvents now correct percent-encodes/decodes binary headers.
+
CloudEvents now includes more robust RFC 2045 parsing of the Content-Type header.
+
The CloudEventsError class now properly subclasses StandardError instead of RuntimeError.
+
Removed redundant _string accessors from event classes since raw forms are already available via [].
+
A variety of corrections to event-related class documentation.
+
+
+
v0.3.1 / 2020-06-27
+
+
+
Fixed crash when using "return" directly in a function block.
+
Added a more flexible request generation helper in the testing module.
+
Fixed several typos in the documentation.
+
+
+
v0.3.0 / 2020-06-26
+
+
+
Updated the CloudEvent data format for converted pubsub events to conform to Cloud Run's conversion.
+
+
+
v0.2.1 / 2020-06-25
+
+
+
The --signature-type check recognizes the legacy event type for :cloud_event functions.
+
+
+
v0.2.0 / 2020-06-24
+
+
Significant changes:
+
+
+
Converts legacy GCF events and passes them to functions as CloudEvents.
+
The executable is now named functions-framework-ruby to avoid collisions with functions frameworks for other languages.
+
Deprecated the event function type. Use cloud_event.
+
The CloudEvents implementation is now fully-featured and can encode as well as decode events.
+
Wrote an expanded set of getting-started documentation.
+
+
+
Minor changes:
+
+
+
Testing.load_temporary now caches loaded functions so they don't have to be reloaded for subsequent tests.
+
The executable recognizes the --signature-type flag, and verifies that the type is correct.
+
Error reporting is expanded and improved.
+
Fixed a crash when a batch CloudEvent was received. (These are still not supported, and now result in a 400.)
+
Renamed a few undocumented environment variables, and added support for a logging level environment variable. All CLI flags now have associated environment variables.
+
Several fixes to the example code, and added a new Sinatra example.
+
+
+
v0.1.1 / 2020-02-27
+
+
+
Server returns 404 when receiving a /favicon.ico or /robots.txt request.
+
Correct a rack constant name in Testing#make_post_request
+
+
+
v0.1.0 / 2020-01-30
+
+
+
Initial release
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/v0.5.0/file.deploying-functions.html b/v0.5.0/file.deploying-functions.html
new file mode 100644
index 00000000..711a64be
--- /dev/null
+++ b/v0.5.0/file.deploying-functions.html
@@ -0,0 +1,251 @@
+
+
+
+
+
+Codestin Search App
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This guide covers how to deploy your Ruby functions written with the Functions
+Framework. Functions can be deployed to
+Google Cloud Functions, Google's
+Functions-as-a-service (FaaS) product, to
+Google Cloud Run. Google's container-based
+serverless environment, or to any KNative-based environment.
+For more information about the Framework as a whole, see the
+Overview Guide.
+
+
Before you begin
+
+
To deploy to Google Cloud, whether to Cloud Functions or Cloud Run, you'll need
+a Google Cloud project with billing enabled. Go to the
+Google Cloud console, create a project (or
+select an existing project), and ensure billing is enabled.
+
+
Additionally, install the Google Cloud SDK if
+you haven't done so previously.
+
+
Deploying to Cloud Functions
+
+
Google Cloud Functions is Google's scalable pay-as-you-go Functions-as-a-Service
+(FaaS) environment that can run your function with zero server management. The
+Functions Framework is designed especially for functions that can be hosted on
+Cloud Functions.
+
+
You can run Ruby functions on Google Cloud Functions by selecting the ruby26
+runtime. This runtime uses a recent release of Ruby 2.6. Support for other
+versions of Ruby may be added in the future.
+
+
+
Note: Ruby support on Cloud Functions is currently in limited preview.
+It is not yet suitable for production workloads, and support is best-effort
+only. Access is currently limited to selected early-access users.
+
+
+
Deploying and updating your function
+
+
Before you can deploy to Cloud Functions, make sure your bundle, and in
+particular your Gemfile.lock file, is up to date. The easiest way to do this
+is to bundle install or bundle update and run your local tests prior to
+deploying. Cloud Functions will not accept your function unless an up-to-date
+Gemfile.lock is present.
+
+
Choose a name for your function. This function name is how it will appear in the
+cloud console, and will also be part of the function's URL. (It's different from
+the name you provide when writing your function; Cloud Functions calls that name
+the "function target".)
The source file defaults to ./app.rb and the function target defaults to
+function, so those flags can be omitted if you're using the defaults. The
+project flag can also be omitted if you've set it as the default with
+gcloud config set project.
+
+
If your function handles events rather than HTTP requests, you'll need to
+replace --trigger-http with a different trigger. For details, see the
+reference documentation
+for gcloud functions deploy.
+
+
To update your deployment, just redeploy using the same function name.
+
+
Configuring Cloud Functions deployments
+
+
The Functions Framework provides various configuration parameters, described in
+Running a Functions Server.
+If you want to set any of these parameters beyond the source file and target,
+you must set environment variables. For example, to limit logging to WARN level
+and above, set FUNCTION_LOGGING_LEVEL to WARN when deploying:
Consult the table in
+Running a Functions Server
+for a list of the environment variables that can be set.
+
+
Deploying to Cloud Run
+
+
Google Cloud Run is Google's managed compute platform for deploying and scaling
+containerized applications quickly and securely. It can run any container-based
+workload, including a containerized function.
+
+
Cloud Run has a hosted fully-managed option that runs on Google's infrastructure
+and monitors and scales your application automatically, and a self-managed or
+on-prem option called Cloud Run for Anthos that runs atop Kubernetes. Both
+flavors use the same general interface and can run functions in the same way.
+This tutorial is written for the managed option, but it should not be difficult
+to adapt it if you have an Anthos installation.
+
+
Building an image for your function
+
+
Before you can deploy to Cloud Run, make sure your bundle, and in
+particular your Gemfile.lock file, is up to date. The easiest way to do this
+is to bundle install or bundle update and run your local tests prior to
+deploying. The configuration used in the Dockerfile below will not accept your
+function unless an up-to-date Gemfile.lock is present.
+
+
First, build a Docker image containing your function. Following is a simple
+Dockerfile that you can use as a starting point. Feel free to adjust it to the
+needs of your project:
You must use your project ID, but you can choose an app name and build ID. The
+command may ask you for permission to enable the Cloud Build API for the project
+if it isn't already enabled.
+
+
Because you provide your own Docker image when deploying to Cloud Run, you can
+use any version of Ruby supported by the Functions Framework, from 2.4 through
+2.7.
+
+
Deploying an image to Cloud Run
+
+
To deploy to Cloud Run, specify the same image URL that you built above. For
+example:
You can omit the --project flag if you've already set it as the default with
+gcloud config set project.
+
+
The command may ask you for permission to enable the Cloud Run API for the
+project, if it isn't already enabled.
+
+
At the end of the deployment process, the command will display the hostname for
+the Cloud Run service. You can use that hostname to send test requests to your
+deployed function.
+
+
Configuring Cloud Run deployments
+
+
Note that our Dockerfile's entrypoint did not pass any source file or target
+name to the Functions Framework. If these are not specified, the Framework will
+use the source ./app.rb and the target function by default. To use different
+values, you need to set the appropriate environment variables when deploying, as
+illustrated above with the FUNCTION_SOURCE and FUNCTION_TARGET variables.
+
+
Source and target are not the only configuration parameters available. The
+various parameters, along with their environment variables, are described in
+Running a Functions Server.
+Any of these can be specified in the --set-env-vars flag when you deploy to
+Google Cloud Run.
+
+
It is also possible to "hard-code" configuration into the Dockerfile, by setting
+environment variables in the Dockerfile, or adding flags to the entrypoint.
+However, it is often better practice to keep your Dockerfile "generic", and set
+configuration environment variables during deployment, so that you do not need
+to rebuild your Docker image every time you want to change configuration.
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/v0.5.0/file.overview.html b/v0.5.0/file.overview.html
new file mode 100644
index 00000000..cbb6a876
--- /dev/null
+++ b/v0.5.0/file.overview.html
@@ -0,0 +1,208 @@
+
+
+
+
+
+Codestin Search App
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The Functions Framework is an open source framework for writing lightweight,
+portable Ruby functions that run in a serverless environment. Functions written
+to this Framework will run in many different environments, including:
Running on a fully-managed or self-managed serverless environment, without
+requiring an HTTP server or complicated request handling logic.
+
+
Features
+
+
+
Define named functions using normal Ruby constructs.
+
Invoke functions in response to requests.
+
Automatically unmarshal events conforming to the
+CloudEvents spec.
+
Automatically convert most legacy events from Google Cloud services such
+as Cloud Pub/Sub and Cloud Storage, to CloudEvents.
+
Spin up a local development server for quick testing.
+
Integrate with standard Ruby libraries such as Rack and Minitest.
+
Portable between serverless platforms.
+
Supports all non-end-of-life versions of Ruby.
+
+
+
Supported Ruby versions
+
+
This library is supported on Ruby 2.4+.
+
+
Google provides official support for Ruby versions that are actively supported
+by Ruby Core—that is, Ruby versions that are either in normal maintenance or
+in security maintenance, and not end of life. Currently, this means Ruby 2.4
+and later. Older versions of Ruby may still work, but are unsupported and not
+recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
+about the Ruby support schedule.
+
+
Quickstart
+
+
Here is how to run a Hello World function on your local machine.
+
+
Create a Gemfile listing the Functions Framework as a dependency:
Install the bundle, and start the framework. This spins up a local web server
+running your "hello" function:
+
+
bundle install
+# ...installs the functions_framework gem and other dependencies
+bundle exec functions-framework-ruby --target hello
+# ...starts the functions server in the foreground
+
+
+
In a separate shell, you can send requests to this function using curl:
These guides provide additional getting-started information.
+
+
+
Writing Functions :
+How to write functions that respond to HTTP requests, industry-standard
+CloudEvents, as well as events sent from Google
+Cloud services such as Pub/Sub and
+Storage.
+
Testing Functions :
+How to use the testing features of the Functions Framework to write local
+unit tests for your functions using standard Ruby testing frameworks such
+as Minitest and
+RSpec.
+
Running a Functions Server :
+How to use the functions-framework-ruby executable to run a local
+functions server.
This guide covers how to use the functions-framework-ruby executable to launch
+a functions server hosting Ruby functions written for the Functions Framework.
+For more information about the Framework as a whole, see the
+Overview Guide.
+
+
Running functions locally
+
+
The functions-framework-ruby command-line executable is used to run a
+functions server. This executable is installed with the functions_framework
+gem, and can be run with bundle exec. It wraps your function in a web server
+request handler, and runs it in the Puma web server.
+
+
Pass the name of the function to run in the --target option. By default,
+functions-framework-ruby will load functions from the file app.rb in the
+current directory. If you want to load functions from a different file, use the
+--source option.
The executable will write logs to the standard error stream while it is running.
+To stop the server, hit CTRL+C or otherwise send it an appropriate signal.
+The executable has no "background" or "daemon" mode. To run it in the background
+from a shell, use the shell's background syntax (such as appending & to the
+command).
+
+
By default, the executable will listen on the port specified by the $PORT
+environment variable, or port 8080 if the variable is not set. You can also
+override this by passing the --port option. A number of other options are
+also available. See the section below on configuring the server, or pass
+--help to the executable to display online help.
+
+
Running functions in Docker
+
+
The functions-framework-ruby executable is designed to be run in a Docker
+container. This is how it is run in some container-based hosting services such
+as Google Cloud Run, but you can also run it in Docker locally.
+
+
First, write a Dockerfile for your project. Following is a simple starting
+point; feel free to adjust it to the needs of your project:
Build an image for your project using the Dockerfile.
+
+
docker build --tag my-image .
+
+
+
Then, you can run the Docker container locally as follows:
+
+
docker run --rm -it -p 8080:8080 my-image --source=foo.rb --target=hello
+
+
+
The arguments after the image name (e.g. --source and --target in the above
+example) are passed to the functions-framework-ruby executable.
+
+
Because the docker container above maps port 8080 internally to port 8080
+externally, you can use that port to send requests to your function. e.g.
+
+
curl http://localhost:8080/
+
+
+
You can stop the running Docker container with CTRL+C or by sending an
+appropriate signal.
+
+
Configuring the server
+
+
The Ruby Functions Framework recognizes the following command line arguments to
+the functions-framework-ruby executable. Each argument also corresponds to an
+environment variable. If you specify both, the flag takes precedence.
+
+
+
+
Command-line flag
+
Environment variable
+
Description
+
+
+
+
--port
+
PORT
+
The port on which the Functions Framework listens for requests. Default: 8080.
+
+
+
--target
+
FUNCTION_TARGET
+
The name of the exported function to be invoked in response to requests. Default: function.
+
+
+
--source
+
FUNCTION_SOURCE
+
The path to the file containing your function. Default: app.rb (in the current working directory).
+
+
+
--signature-type
+
FUNCTION_SIGNATURE_TYPE
+
Verifies that the function has the expected signature. Allowed values: http, event, or cloudevent.
+
+
+
--environment
+
RACK_ENV
+
Sets the Rack environment.
+
+
+
--bind
+
FUNCTION_BIND_ADDR
+
Binds to the given address. Default: 0.0.0.0.
+
+
+
--min-threads
+
FUNCTION_MIN_THREADS
+
Sets the minimum thread pool size, overriding Puma's default.
+
+
+
--max-threads
+
FUNCTION_MAX_THREADS
+
Sets the maximum thread pool size, overriding Puma's default.
+
+
+
--detailed-errors
+
FUNCTION_DETAILED_ERRORS
+
No value. If present, shows exception details in exception responses. Defaults to false.
+
+
+
--verbose
+
FUNCTION_LOGGING_LEVEL
+
No value. Increases log verbosity (e.g. from INFO to DEBUG). Can be given more than once.
+
+
+
--quiet
+
FUNCTION_LOGGING_LEVEL
+
No value. Decreases log verbosity (e.g. from INFO to WARN). Can be given more than once.
+
+
+
+
Detailed errors are enabled by default if the FUNCTION_DETAILED_ERRORS
+environment variable is set to a non-empty string. The exact value does not
+matter. Detailed errors are disabled if the variable is unset or empty.
+
+
The logging level defaults to the value of the FUNCTION_LOGGING_LEVEL
+environment variable, which can be one of the following values: DEBUG, INFO,
+WARN, ERROR, FATAL, or UNKNOWN, corresponding to Ruby's
+Logger::Severity
+constants. If FUNCTION_LOGGING_LEVEL is not set to one of those values, it
+defaults to INFO.
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/v0.5.0/file.testing-functions.html b/v0.5.0/file.testing-functions.html
new file mode 100644
index 00000000..8e70ffa0
--- /dev/null
+++ b/v0.5.0/file.testing-functions.html
@@ -0,0 +1,229 @@
+
+
+
+
+
+Codestin Search App
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This guide covers writing unit tests for functions using the Functions Framework
+for Ruby. For more information about the Framework, see the
+Overview Guide.
+
+
Overview of function testing
+
+
One of the benefits of the functions-as-a-service paradigm is that functions are
+easy to test. In many cases, you can simply call a function with input, and test
+the output. You do not need to set up (or mock) an actual server.
+
+
The Functions Framework provides utility methods that streamline the process of
+setting up functions and the environment for testing, constructing input
+parameters, and interpreting results. These are available in the
+Testing module.
+Generally, you can include this module in your Minitest test class or RSpec
+describe block.
To test a function, you'll need to load the Ruby file that defines the function,
+and run the function to test its results. The Testing module provides a method
+load_temporary,
+which loads a Ruby file, defining functions but only for the scope of your test.
+This allows your test to coexist with tests for other functions, even functions
+with the same name from a different Ruby file.
+
+
require"minitest/autorun"
+require"functions_framework/testing"
+
+classMyTest<Minitest::Test
+ includeFunctionsFramework::Testing
+
+ deftest_a_function
+ load_temporary"foo.rb"do
+ # Test a function defined in foo.rb
+end
+ end
+
+ deftest_another_function
+ load_temporary"bar.rb"do
+ # Test a function defined in bar.rb
+end
+ end
+end
+
+
+
When running a test suite, you'll typically need to load all the Ruby files
+that define your functions. While load_temporary can ensure that the function
+definitions do not conflict, it cannot do the same for classes, methods, and
+other Ruby constructs. So, for testability, it is generally good practice to
+include only functions in one of these files. If you need to write supporting
+helper methods, classes, constants, or other code, include them in separate
+ruby files that you require.
+
+
Testing HTTP functions
+
+
Testing an HTTP function is generally as simple as generating a request, calling
+the function, and asserting against the response.
+
+
The input to an HTTP function is a
+Rack::Request object. It is
+usually not hard to construct one of these objects, but the Testing module
+includes helper methods that you can use to create simple requests for many
+basic cases.
+
+
When you have constructed an input request, use
+call_http
+to call a named function, passing the request object. This method returns a
+Rack::Response that you can
+assert against.
If the function raises an exception, the exception will be converted to a 500
+response object. So if you are testing an error case, you should still check the
+response object rather than looking for a raised exception.
Testing a CloudEvent function works similarly. The Testing module provides
+methods to help construct example CloudEvent objects, which can then be passed
+to the method
+call_event.
+
+
Unlike HTTP functions, event functions do not have a return value. Instead, you
+will need to test side effects. A common approach is to test logs by capturing
+the standard error output.
+
+
require"minitest/autorun"
+require"functions_framework/testing"
+
+classMyTest<Minitest::Test
+ includeFunctionsFramework::Testing
+
+ deftest_event_function
+ load_temporary"app.rb"do
+ event=make_cloud_event"Hello, world!",type:"my-type"
+ _out,err=capture_subprocess_iodo
+ call_event"my_function",event
+ end
+ assert_match(/Received: "Hello, world!"/,err)
+ end
+ end
+end
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/v0.5.0/file.writing-functions.html b/v0.5.0/file.writing-functions.html
new file mode 100644
index 00000000..9c361f5b
--- /dev/null
+++ b/v0.5.0/file.writing-functions.html
@@ -0,0 +1,332 @@
+
+
+
+
+
+Codestin Search App
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This guide covers writing functions using the Functions Framework for Ruby. For
+more information about the Framework, see the
+Overview Guide.
+
+
About functions
+
+
Functions are Ruby blocks that are run when an input is received. Those inputs
+can be HTTP requests or events in a recognized format. Functions that receive
+HTTP requests return an HTTP response, but event functions have no return value.
+
+
When you define a function, you must provide an identifying name. The Functions
+Framework allows you to use any string as a function name; however, many
+deployment environments restrict the characters that can be used in a name. For
+maximum portability, it is recommended that you use names that are allowed for
+Ruby methods, i.e. beginning with a letter, and containing only letters,
+numbers, and underscores.
+
+
Defining an HTTP function
+
+
An HTTP function is a simple web service that takes an HTTP request and returns
+an HTTP response. The following example defines an HTTP function named "hello"
+that returns a simple message in the HTTP response body:
HTTP functions take a Rack Request object and return an HTTP response. We'll
+now cover these in a bit more detail.
+
+
Using the Request object
+
+
An HTTP function is passed a request, which is an object of type
+Rack::Request. This object
+provides methods for obtaining request information such as the method,
+path, query parameters, body content, and headers. You can also obtain the raw
+Rack environment using the env method. The following example includes some
+request information in the response:
+
+
require"functions_framework"
+
+FunctionsFramework.http"request_info_example"do|request|
+ # Include some request info in the response body.
+"Received #{request.method} from #{request.url}!\n"
+end
+
+
+
The Functions Framework sets up a logger in the Rack environment, so you can
+use the logger method on the request object if you want to emit logs. These
+logs will be written to the standard error stream, and will appear in the
+Google Cloud Logs if your function is running on a Google Cloud serverless
+hosting environment.
+
+
require"functions_framework"
+
+FunctionsFramework.http"logging_example"do|request|
+ # Log some request info.
+request.logger.info"I received #{request.method} from #{request.url}!"
+ # A simple response body.
+"ok"
+end
+
+
+
Response types
+
+
The above examples return simple strings as the response body. Often, however,
+you will need to return more complex responses such as JSON, binary data, or
+even rendered HTML. The Functions Framework recognizes a variety of return
+types from an HTTP function:
+
+
+
String : If you return a string, the framework will use it as the
+response body in with a 200 (success) HTTP status code. It will set the
+Content-Type header to text/plain.
+
Array : If you return an array, the framework will assume it is a
+standard three-element Rack response array, as defined in the
+Rack spec.
+
Rack::Response : You can return a
+Rack::Response object. The
+Framework will call #finish on this object and retrieve the contents.
+
Hash : If you return a Hash, the Framework will attempt to encode it as
+JSON, and return it in the response body with a 200 (success) HTTP status
+code. The Content-Type will be set to application/json.
+
StandardError : If you return an exception object, the Framework will
+return a 500 (server error) response. See the section below on
+Error Handling.
+
+
+
Using Sinatra
+
+
The Functions Framework, and the functions-as-a-service (FaaS) solutions it
+targets, are optimized for relatively simple HTTP requests such as webhooks and
+simple APIs. If you want to deploy a large application or use a monolithic
+framework such as Ruby on Rails, you may want to consider a solution such as
+Google Cloud Run that is tailored to larger applications. However, a lightweight
+framework such as Sinatra is sometimes useful when writing HTTP functions.
+
+
It is easy to connect an HTTP function to a Sinatra app. First, declare the
+dependency on Sinatra in your Gemfile:
Write the Sinatra app using the "modular" Sinatra interface (i.e. subclass
+Sinatra::Base), and then run the Sinatra app directly as a Rack handler from
+the function. Here is a basic example:
This technique gives you access to pretty much any feature of the Sinatra web
+framework, including routes, templates, and even custom middleware.
+
+
Defining an Event function
+
+
An event function is a handler for a standard cloud event. It can receive
+industry-standard CloudEvents, as well as events sent
+by Google Cloud services such as Pub/Sub and
+Storage. Event functions do not have a
+return value.
+
+
The following is a simple event handler that receives an event and logs some
+information about it:
Some Google Cloud services send events in a legacy event format that was defined
+prior to CloudEvents. The Functions Framework will convert these legacy events
+to an equivalent CloudEvents V1 type, so your function will always receive a
+CloudEvent object when it is sent an event from Google Cloud. The precise
+mapping between legacy events and CloudEvents is not specified in detail here,
+but in general, the data from the legacy event will be mapped to the data
+field in the CloudEvent, and the context from the legacy event will be mapped
+to equivalent CloudEvent attributes.
+
+
Error handling
+
+
If your function encounters an error, it can raise an exception. The Functions
+Framework will catch StandardError exceptions and handle them appropriately.
+
+
If you raise an exception in an HTTP function, the Functions Framework will
+return a 500 (server error) response. You can control whether the exception
+details (e.g. exception type, message, and backtrace) are sent with the
+response by setting the detailed-errors configuration in the server. The
+Framework will also log the error for you.
+
+
If you need more control over the error response, you can also construct the
+HTTP response yourself. For example:
+
+
require"functions_framework"
+
+FunctionsFramework.http"error_reporter"do|request|
+ begin
+ raise"whoops!"
+ rescueRuntimeError=>e
+ [500,{},["Uh, oh, got an error message: #{e.message}."]]
+ end
+end
+
+
+
Structuring a project
+
+
A Functions Framework based "project" or "application" is a typical Ruby
+application. It should include a Gemfile that specifies the gem dependencies
+(including the functions_framework gem itself), and any other dependencies
+needed by the function. It must include at least one Ruby source file that
+defines functions, and can also include additional Ruby files defining classes
+and methods that assist in the function implementation.
+
+
The "entrypoint" to the project, also called the "source", is a Ruby file. It
+can define any number of functions (with distinct names), although it is often
+good practice to create a separate Ruby file per function.
+
+
By convention, the source file is often called app.rb, but you can give it
+any name. Projects can also have multiple source files that apply to different
+cases.
The Functions Framework is an open source framework for writing lightweight,
+portable Ruby functions that run in a serverless environment. Functions written
+to this Framework will run in many different environments, including:
Running on a fully-managed or self-managed serverless environment, without
+requiring an HTTP server or complicated request handling logic.
+
+
Features
+
+
+
Define named functions using normal Ruby constructs.
+
Invoke functions in response to requests.
+
Automatically unmarshal events conforming to the
+CloudEvents spec.
+
Automatically convert most legacy events from Google Cloud services such
+as Cloud Pub/Sub and Cloud Storage, to CloudEvents.
+
Spin up a local development server for quick testing.
+
Integrate with standard Ruby libraries such as Rack and Minitest.
+
Portable between serverless platforms.
+
Supports all non-end-of-life versions of Ruby.
+
+
+
Supported Ruby versions
+
+
This library is supported on Ruby 2.4+.
+
+
Google provides official support for Ruby versions that are actively supported
+by Ruby Core—that is, Ruby versions that are either in normal maintenance or
+in security maintenance, and not end of life. Currently, this means Ruby 2.4
+and later. Older versions of Ruby may still work, but are unsupported and not
+recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
+about the Ruby support schedule.
+
+
Quickstart
+
+
Here is how to run a Hello World function on your local machine.
+
+
Create a Gemfile listing the Functions Framework as a dependency:
Install the bundle, and start the framework. This spins up a local web server
+running your "hello" function:
+
+
bundle install
+# ...installs the functions_framework gem and other dependencies
+bundle exec functions-framework-ruby --target hello
+# ...starts the functions server in the foreground
+
+
+
In a separate shell, you can send requests to this function using curl:
These guides provide additional getting-started information.
+
+
+
Writing Functions :
+How to write functions that respond to HTTP requests, industry-standard
+CloudEvents, as well as events sent from Google
+Cloud services such as Pub/Sub and
+Storage.
+
Testing Functions :
+How to use the testing features of the Functions Framework to write local
+unit tests for your functions using standard Ruby testing frameworks such
+as Minitest and
+RSpec.
+
Running a Functions Server :
+How to use the functions-framework-ruby executable to run a local
+functions server.
Here is a roadmap to the internal modules in the Ruby functions framework.
+
+
+
CLI is the implementation of the
+functions-framework-ruby executable. Most apps will not need to interact
+with this class directly.
+
Function is the internal representation of a
+function, indicating the type of function (http or cloud event), the
+name of the function, and the block of code implementing it. Most apps
+do not need to interact with this class directly.
+
Registry looks up functions by name. When you
+define a set of named functions, they are added to a registry, and when
+you start a server and specify the target function by name, it is looked
+up from the registry. Most apps do not need to interact with this class
+directly.
+
Server is a web server that makes a function
+available via HTTP. It wraps the Puma web server and runs a specific
+Function. Many apps can simply run the
+functions-framework-ruby executable to spin up a server. However, if you
+need closer control over your execution environment, you can use the
+Server class to run a server. Note that, in most
+cases, it is easier to use the FunctionsFramework.start or
+FunctionsFramework.run wrapper methods rather than instantiate a
+Server class directly.
+
Testing provides helpers that are useful when
+writing unit tests for functions.
The default target function name. If you define a function without
+specifying a name, or run the framework without giving a target, this name
+is used.
+
+
+
+
+
+
+
Returns:
+
+
+
+
+
+ (String)
+
+
+
+
+
+
+
+
+
+
"function".freeze
+
+
DEFAULT_SOURCE =
+
+
+
The default source file path. The CLI loads functions from this file if no
+source file is given explicitly.
+
+
+
+
+
+
+
Returns:
+
+
+
+
+
+ (String)
+
+
+
+
+
+
+
+
+
+
"./app.rb".freeze
+
+
CloudEvents =
+
+
+
The CloudEvents implementation was extracted to become the official
+CloudEvents SDK. This alias is left here for backward compatibility.
You must provide a name for the function, and a block that implemets the
+function. The block should take one argument: the event object of type
+CloudEvents::Event.
+Any return value is ignored.
You must provide a name for the function, and a block that implemets the
+function. The block should take a single Rack::Request argument. It
+should return one of the following: