From 836bb88d2deb38b996ef51e2dda15eee99bbb506 Mon Sep 17 00:00:00 2001 From: Daniel Azuma Date: Fri, 17 Jul 2020 13:47:40 -0700 Subject: [PATCH 01/22] Skeleton of gh-pages --- .circleci/config.yml | 63 --------- .gitignore | 18 ++- .nojekyll | 0 .rubocop.yml | 2 - .toys.rb | 53 -------- .yardopts | 11 -- 404.html | 22 ++++ CHANGELOG.md | 2 - CONTRIBUTING.md | 32 ----- Gemfile | 17 --- LICENSE | 201 ----------------------------- README.md | 18 --- functions_framework.gemspec | 49 ------- index.html | 15 +++ lib/functions_framework.rb | 21 --- lib/functions_framework/version.rb | 21 --- test/helper.rb | 19 --- test/test_version.rb | 24 ---- 18 files changed, 48 insertions(+), 540 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .nojekyll delete mode 100644 .rubocop.yml delete mode 100644 .toys.rb delete mode 100644 .yardopts create mode 100644 404.html delete mode 100644 CHANGELOG.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Gemfile delete mode 100644 LICENSE delete mode 100644 README.md delete mode 100644 functions_framework.gemspec create mode 100644 index.html delete mode 100644 lib/functions_framework.rb delete mode 100644 lib/functions_framework/version.rb delete mode 100644 test/helper.rb delete mode 100644 test/test_version.rb diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 5820e48e..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,63 +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. - -version: 2.1 -executors: - ruby24: - docker: - - image: "circleci/ruby:2.4-buster" - ruby25: - docker: - - image: "circleci/ruby:2.5-buster" - ruby26: - docker: - - image: "circleci/ruby:2.6-buster" - ruby27: - docker: - - image: "circleci/ruby:2.7-buster" -commands: - rake-test: - steps: - - checkout - - run: - name: Bundle - command: "gem install --no-document bundler && bundle install --jobs=3 --retry=3" - - run: - name: CI - command: "bundle exec toys ci" -jobs: - test-ruby24: - executor: ruby24 - steps: - - rake-test - test-ruby25: - executor: ruby25 - steps: - - rake-test - test-ruby26: - executor: ruby26 - steps: - - rake-test - test-ruby27: - executor: ruby27 - steps: - - rake-test -workflows: - version: 2 - builds: - jobs: - - test-ruby24: - - test-ruby25: - - test-ruby26: - - test-ruby27: diff --git a/.gitignore b/.gitignore index 7a8a4ca5..54946e14 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,11 @@ -/.bundle/ -/.yardoc -/Gemfile.lock -/coverage/ -/doc/ -/pkg/ -/tmp/ +.DS_Store +.bundle/ +.yardoc/ +Gemfile.lock +coverage/ +examples/ +doc/ +lib/ +pkg/ +test/ +tmp/ diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 00000000..e69de29b diff --git a/.rubocop.yml b/.rubocop.yml deleted file mode 100644 index 5b3d10c4..00000000 --- a/.rubocop.yml +++ /dev/null @@ -1,2 +0,0 @@ -inherit_gem: - google-style: google-style.yml diff --git a/.toys.rb b/.toys.rb deleted file mode 100644 index 68fc3e07..00000000 --- a/.toys.rb +++ /dev/null @@ -1,53 +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. - -expand :clean, paths: ["pkg", "doc", ".yardoc", "tmp"] - -expand :minitest, libs: ["lib", "test"] - -expand :rubocop - -expand :yardoc do |t| - t.generate_output_flag = true - t.fail_on_warning = true - t.fail_on_undocumented_objects = true -end - -expand :gem_build - -expand :gem_build, name: "release", push_gem: true - -expand :gem_build, name: "install", install_gem: true - -tool "ci" do - desc "Run all CI checks" - - include :exec, result_callback: :handle_result - include :terminal - - def handle_result result - if result.success? - puts "** #{result.name} passed\n\n", :green, :bold - else - puts "** CI terminated: #{result.name} failed!", :red, :bold - exit 1 - end - end - - def run - exec_tool ["test"], name: "Tests" - exec_tool ["rubocop"], name: "Style checker" - exec_tool ["yardoc"], name: "Docs generation" - end -end diff --git a/.yardopts b/.yardopts deleted file mode 100644 index 2805ab58..00000000 --- a/.yardopts +++ /dev/null @@ -1,11 +0,0 @@ ---no-private ---title=Functions Framework ---markup markdown ---markup-provider redcarpet ---main=README.md -./lib/functions_framework/**/*.rb -./lib/functions_framework.rb -- -README.md -CONTRIBUTING.md -CHANGELOG.md diff --git a/404.html b/404.html new file mode 100644 index 00000000..57744581 --- /dev/null +++ b/404.html @@ -0,0 +1,22 @@ + + + + + + +

+ Ruby Functions Framework documentation +

+ + + 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 @@ + + + + + + + +

+ Ruby Functions Framework documentation +

+ + + 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 + + + + + + + + + + + + + + + + + +
+ + +

Module: FunctionsFramework + + + +

+
+ + + + + + + + + + + +
+
Defined in:
+
lib/functions_framework/version.rb,
+ lib/functions_framework/cli.rb,
lib/functions_framework/server.rb,
lib/functions_framework/testing.rb,
lib/functions_framework/function.rb,
lib/functions_framework/registry.rb,
lib/functions_framework/legacy_event_converter.rb,
lib/functions_framework.rb
+
+
+ +
+ +

Overview

+
+

The Functions Framework for Ruby.

+ +

Functions Framework is an open source framework for writing lightweight, +portable Ruby functions that run in a serverless environment. For general +information about the Functions Framework, see +https://github.com/GoogleCloudPlatform/functions-framework. +To get started with the functions framework for Ruby, see +https://github.com/GoogleCloudPlatform/functions-framework-ruby for basic +examples.

+ +

Inside the FunctionsFramework module

+ +

The FunctionsFramework module includes the main entry points for the +functions framework. Use the FunctionsFramework.http, +event, or FunctionsFramework.cloud_event methods to +define functions. To serve functions via a web service, invoke the +functions-framework-ruby executable, or use the FunctionsFramework.start +or FunctionsFramework.run methods.

+ +

Internal modules

+ +

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.
  • +
+ + +
+
+
+ + +

Defined Under Namespace

+

+ + + Modules: Testing + + + + Classes: CLI, Function, LegacyEventConverter, Registry, Server + + +

+ + +

+ Constant Summary + collapse +

+ +
+ +
VERSION = +
+
+

Version of the Ruby Functions Framework

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (String) + + + +
  • + +
+ +
+
+
"0.5.0".freeze
+ +
DEFAULT_TARGET = +
+
+

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.

+ + +
+
+
+ + +
+
+
::CloudEvents
+ +
+ + + + + +

Class Attribute Summary collapse

+ + + + + + +

+ Class Method Summary + collapse +

+ + + + + +
+

Class Attribute Details

+ + + +
+

+ + .global_registryFunctionsFramework::Registry + + + + + +

+
+

The "global" registry that holds events defined by the +FunctionsFramework class methods.

+ + +
+
+
+ +

Returns:

+ + +
+ + + + +
+
+
+
+107
+108
+109
+
+
# File 'lib/functions_framework.rb', line 107
+
+def global_registry
+  @global_registry
+end
+
+
+ + + +
+

+ + .loggerLogger + + + + + +

+
+

A "global" logger that is used by the framework's web server, and can +also be used by functions.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Logger) + + + +
  • + +
+ +
+ + + + +
+
+
+
+115
+116
+117
+
+
# File 'lib/functions_framework.rb', line 115
+
+def logger
+  @logger
+end
+
+
+ +
+ + +
+

Class Method Details

+ + +
+

+ + .cloud_event(name = DEFAULT_TARGET, &block) ⇒ self + + + + + +

+
+

Define a function that responds to CloudEvents.

+ +

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.

+ +

Example

+ +
FunctionsFramework.cloud_event "my-function" do |event|
+  FunctionsFramework.logger.info "Event data: #{event.data.inspect}"
+end
+
+ + +
+
+
+

Parameters:

+
    + +
  • + + name + + + (String) + + + (defaults to: DEFAULT_TARGET) + + + — +

    The function name. Defaults to DEFAULT_TARGET.

    +
    + +
  • + +
  • + + block + + + (Proc) + + + + — +

    The function code as a proc.

    +
    + +
  • + +
+ +

Returns:

+
    + +
  • + + + (self) + + + +
  • + +
+ +
+ + + + +
+
+
+
+163
+164
+165
+166
+
+
# File 'lib/functions_framework.rb', line 163
+
+def cloud_event name = DEFAULT_TARGET, &block
+  global_registry.add_cloud_event name, &block
+  self
+end
+
+
+ +
+

+ + .http(name = DEFAULT_TARGET, &block) ⇒ self + + + + + +

+
+

Define a function that response to HTTP requests.

+ +

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:

+ +
    +
  • A standard 3-element Rack response array. See +https://github.com/rack/rack/blob/master/SPEC
  • +
  • A Rack::Response object.
  • +
  • A simple String that will be sent as the response body.
  • +
  • A Hash object that will be encoded as JSON and sent as the response +body.
  • +
+ +

Example

+ +
FunctionsFramework.http "my-function" do |request|
+  "I received a request for #{request.url}"
+end
+
+ + +
+
+
+

Parameters:

+
    + +
  • + + name + + + (String) + + + (defaults to: DEFAULT_TARGET) + + + — +

    The function name. Defaults to DEFAULT_TARGET.

    +
    + +
  • + +
  • + + block + + + (Proc) + + + + — +

    The function code as a proc.

    +
    + +
  • + +
+ +

Returns:

+
    + +
  • + + + (self) + + + +
  • + +
+ +
+ + + + +
+
+
+
+140
+141
+142
+143
+
+
# File 'lib/functions_framework.rb', line 140
+
+def http name = DEFAULT_TARGET, &block
+  global_registry.add_http name, &block
+  self
+end
+
+
+ +
+

+ + .run(target) {|FunctionsFramework::Server::Config| ... } ⇒ self + + + + + +

+
+

Run the functions framework server and block until it stops. The server +will look up the given target function name in the global registry.

+ + +
+
+
+

Parameters:

+
    + +
  • + + target + + + (FunctionsFramework::Function, String) + + + + — +

    The function to run, +or the name of the function to look up in the global registry.

    +
    + +
  • + +
+ +

Yields:

+ +

Returns:

+
    + +
  • + + + (self) + + + +
  • + +
+ +
+ + + + +
+
+
+
+201
+202
+203
+204
+205
+
+
# File 'lib/functions_framework.rb', line 201
+
+def run target, &block
+  server = start target, &block
+  server.wait_until_stopped
+  self
+end
+
+
+ +
+

+ + .start(target) {|FunctionsFramework::Server::Config| ... } ⇒ FunctionsFramework::Server + + + + + +

+
+

Start the functions framework server in the background. The server will +look up the given target function name in the global registry.

+ + +
+
+
+

Parameters:

+
    + +
  • + + target + + + (FunctionsFramework::Function, String) + + + + — +

    The function to run, +or the name of the function to look up in the global registry.

    +
    + +
  • + +
+ +

Yields:

+ +

Returns:

+ + +
+ + + + +
+
+
+
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+
+
# File 'lib/functions_framework.rb', line 178
+
+def start target, &block
+  require "functions_framework/server"
+  if target.is_a? ::FunctionsFramework::Function
+    function = target
+  else
+    function = global_registry[target]
+    raise ::ArgumentError, "Undefined function: #{target.inspect}" if function.nil?
+  end
+  server = Server.new function, &block
+  server.respond_to_signals
+  server.start
+end
+
+
+ +
+ +
+ + + +
+ + \ No newline at end of file diff --git a/v0.5.0/FunctionsFramework/CLI.html b/v0.5.0/FunctionsFramework/CLI.html new file mode 100644 index 00000000..8a0bd23c --- /dev/null +++ b/v0.5.0/FunctionsFramework/CLI.html @@ -0,0 +1,545 @@ + + + + + +Codestin Search App + + + + + + + + + + + + + + + + + +
+ + +

Class: FunctionsFramework::CLI + + + +

+
+ +
+
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+
+ + + + + + + + + + + +
+
Defined in:
+
lib/functions_framework/cli.rb
+
+ +
+ +

Overview

+
+

Implementation of the functions-framework-ruby executable.

+ + +
+
+
+ + +
+ +

+ Constant Summary + collapse +

+ +
+ +
DEFAULT_LOGGING_LEVEL = +
+
+

The default logging level, if not given in the environment variable.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Integer) + + + +
  • + +
+ +
+
+
::Logger::Severity::INFO
+ +
+ + + + + + + + + +

+ Instance Method Summary + collapse +

+ +
    + +
  • + + + #initialize ⇒ CLI + + + + + + + constructor + + + + + + + + +

    Create a new CLI, setting arguments to their defaults.

    +
    + +
  • + + +
  • + + + #parse_args(argv) ⇒ self + + + + + + + + + + + + + +

    Parse the given command line arguments.

    +
    + +
  • + + +
  • + + + #run ⇒ self + + + + + + + + + + + + + +

    Run the configured server, and block until it stops.

    +
    + +
  • + + +
+ + +
+

Constructor Details

+ +
+

+ + #initializeCLI + + + + + +

+
+

Create a new CLI, setting arguments to their defaults.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+
+
# File 'lib/functions_framework/cli.rb', line 34
+
+def initialize
+  @target = ::ENV["FUNCTION_TARGET"] || ::FunctionsFramework::DEFAULT_TARGET
+  @source = ::ENV["FUNCTION_SOURCE"] || ::FunctionsFramework::DEFAULT_SOURCE
+  @env = nil
+  @port = nil
+  @bind = nil
+  @min_threads = nil
+  @max_threads = nil
+  @detailed_errors = nil
+  @signature_type = ::ENV["FUNCTION_SIGNATURE_TYPE"]
+  @logging_level = init_logging_level
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + #parse_args(argv) ⇒ self + + + + + +

+
+

Parse the given command line arguments. +Exits if argument parsing failed.

+ + +
+
+
+

Parameters:

+
    + +
  • + + argv + + + (Array<String>) + + + +
  • + +
+ +

Returns:

+
    + +
  • + + + (self) + + + +
  • + +
+ +
+ + + + +
+
+
+
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
+99
+100
+101
+
+
# File 'lib/functions_framework/cli.rb', line 54
+
+def parse_args argv # rubocop:disable Metrics/MethodLength
+  option_parser = ::OptionParser.new do |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
+      puts op
+      exit
+    end
+  end
+  option_parser.parse! argv
+  error "Unrecognized arguments: #{argv}\n#{op}" unless argv.empty?
+  self
+end
+
+
+ +
+

+ + #runself + + + + + +

+
+

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
+
+def run
+  begin
+    server = start_server
+  rescue ::StandardError => e
+    error e.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 + + + + + + + + + + + + + + + + + +
+ + +

Class: FunctionsFramework::Function + + + +

+
+ +
+
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+
+ + + + + + + + + + + +
+
Defined in:
+
lib/functions_framework/function.rb
+
+ +
+ +

Overview

+
+

Representation of a function.

+ +

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.)

+ + +
+
+
+ + +

Defined Under Namespace

+

+ + + + + Classes: CallBase + + +

+ + + + +

Instance Attribute Summary collapse

+
    + +
  • + + + #name ⇒ String + + + + + + + + + readonly + + + + + + + + + +

    The function name.

    +
    + +
  • + + +
  • + + + #type ⇒ Symbol + + + + + + + + + readonly + + + + + + + + + +

    The function type.

    +
    + +
  • + + +
+ + + + + +

+ Instance Method Summary + collapse +

+ + + + +
+

Constructor Details

+ +
+

+ + #initialize(name, type, callable = nil, &block) ⇒ Function + + + + + +

+
+

Create a new function definition.

+ + +
+
+
+

Parameters:

+
    + +
  • + + name + + + (String) + + + + — +

    The function name

    +
    + +
  • + +
  • + + type + + + (Symbol) + + + + — +

    The type of function. Valid types are :http and +:cloud_event.

    +
    + +
  • + +
  • + + callable + + + (Class, #call) + + + (defaults to: nil) + + + — +

    A callable object or class.

    +
    + +
  • + +
  • + + block + + + (Proc) + + + + — +

    The function code as a block.

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+
+
# File 'lib/functions_framework/function.rb', line 58
+
+def initialize name, type, callable = nil, &block
+  @name = name
+  @type = type
+  @callable = @callable_class = nil
+  if callable.respond_to? :call
+    @callable = callable
+  elsif callable.is_a? ::Class
+    @callable_class = callable
+  elsif block_given?
+    @callable_class = ::Class.new CallBase do
+      define_method :call, &block
+    end
+  else
+    raise ::ArgumentError, "No callable given for function"
+  end
+end
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + #nameString (readonly) + + + + + +

+
+

Returns The function name.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (String) + + + + — +

    The function name

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+78
+79
+80
+
+
# File 'lib/functions_framework/function.rb', line 78
+
+def name
+  @name
+end
+
+
+ + + +
+

+ + #typeSymbol (readonly) + + + + + +

+
+

Returns The function type.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Symbol) + + + + — +

    The function type

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+83
+84
+85
+
+
# File 'lib/functions_framework/function.rb', line 83
+
+def type
+  @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.

+ + +
+
+
+

Parameters:

+
    + +
  • + + logger + + + (::Logger) + + + (defaults to: nil) + + + — +

    The logger for use by function executions. This +may or may not be used by the callable.

    +
    + +
  • + +
+ +

Returns:

+
    + +
  • + + + (#call) + + + +
  • + +
+ +
+ + + + +
+
+
+
+94
+95
+96
+97
+98
+
+
# File 'lib/functions_framework/function.rb', line 94
+
+def new_call logger: nil
+  return @callable unless @callable.nil?
+  logger ||= FunctionsFramework.logger
+  @callable_class.new logger: logger, function_name: name, function_type: type
+end
+
+
+ +
+ +
+ + + +
+ + \ No newline at end of file diff --git a/v0.5.0/FunctionsFramework/Function/CallBase.html b/v0.5.0/FunctionsFramework/Function/CallBase.html new file mode 100644 index 00000000..e8a4c859 --- /dev/null +++ b/v0.5.0/FunctionsFramework/Function/CallBase.html @@ -0,0 +1,334 @@ + + + + + +Codestin Search App + + + + + + + + + + + + + + + + + +
+ + +

Class: FunctionsFramework::Function::CallBase + + + +

+
+ +
+
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+
+ + + + + + + + + + + +
+
Defined in:
+
lib/functions_framework/function.rb
+
+ +
+ +

Overview

+
+

A base class for a callable object that provides calling context.

+ +

An object of this class is self while a function block is running.

+ + +
+
+
+ + +
+ + + +

Instance Attribute Summary collapse

+
    + +
  • + + + #context ⇒ Hash + + + + + + + + + readonly + + + + + + + + + +

    A keyed hash of context information.

    +
    + +
  • + + +
+ + + + + +

+ Instance Method Summary + collapse +

+ + + + +
+

Constructor Details

+ +
+

+ + #initialize(**context) ⇒ CallBase + + + + + +

+
+

Create a callable object with the given context.

+ + +
+
+
+

Parameters:

+
    + +
  • + + context + + + (keywords) + + + + — +

    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
+
+def initialize **context
+  @context = context
+end
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + #contextHash (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
+
+def context
+  @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 + + + + + + + + + + + + + + + + + +
+ + +

Class: FunctionsFramework::LegacyEventConverter + + + +

+
+ +
+
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+
+ + + + + + + + + + + +
+
Defined in:
+
lib/functions_framework/legacy_event_converter.rb
+
+ +
+ +

Overview

+
+

Converter from legacy GCF event formats to CloudEvents.

+ + +
+
+
+ + +
+ + + + + + + +

+ Instance Method Summary + collapse +

+ + + + + + +
+

Instance Method Details

+ + +
+

+ + #decode_rack_env(env) ⇒ ::CloudEvents::Event? + + + + + +

+
+

Decode an event from the given Rack environment hash.

+ + +
+
+
+

Parameters:

+
    + +
  • + + env + + + (Hash) + + + + — +

    The Rack environment

    +
    + +
  • + +
+ +

Returns:

+
    + +
  • + + + (::CloudEvents::Event) + + + + — +

    if the request could be converted

    +
    + +
  • + +
  • + + + (nil) + + + + — +

    if the event format was not recognized.

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+29
+30
+31
+32
+33
+34
+35
+36
+37
+
+
# File 'lib/functions_framework/legacy_event_converter.rb', line 29
+
+def decode_rack_env env
+  content_type = ::CloudEvents::ContentType.new env["CONTENT_TYPE"]
+  return nil unless content_type.media_type == "application" && content_type.subtype_base == "json"
+  input = read_input_json env["rack.input"], content_type.charset
+  return nil unless input
+  context = normalized_context input
+  return nil unless context
+  construct_cloud_event context, input["data"], content_type.charset
+end
+
+
+ +
+ +
+ + + +
+ + \ No newline at end of file diff --git a/v0.5.0/FunctionsFramework/Registry.html b/v0.5.0/FunctionsFramework/Registry.html new file mode 100644 index 00000000..5648b0b6 --- /dev/null +++ b/v0.5.0/FunctionsFramework/Registry.html @@ -0,0 +1,671 @@ + + + + + +Codestin Search App + + + + + + + + + + + + + + + + + +
+ + +

Class: FunctionsFramework::Registry + + + +

+
+ +
+
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+
+ + + + + + +
+
Includes:
+
MonitorMixin
+
+ + + + + + +
+
Defined in:
+
lib/functions_framework/registry.rb
+
+ +
+ +

Overview

+
+

Registry providing lookup of functions by name.

+ + +
+
+
+ + +
+ + + + + + + +

+ Instance Method Summary + collapse +

+ + + + + +
+

Constructor Details

+ +
+

+ + #initializeRegistry + + + + + +

+
+

Create a new empty registry.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+27
+28
+29
+30
+
+
# File 'lib/functions_framework/registry.rb', line 27
+
+def initialize
+  super()
+  @functions = {}
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + #[](name) ⇒ FunctionsFramework::Function? + + + + + +

+
+

Look up a function definition by name.

+ + +
+
+
+

Parameters:

+
    + +
  • + + name + + + (String) + + + + — +

    The function name

    +
    + +
  • + +
+ +

Returns:

+
    + +
  • + + + (FunctionsFramework::Function) + + + + — +

    if the function is found

    +
    + +
  • + +
  • + + + (nil) + + + + — +

    if the function is not found

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+39
+40
+41
+
+
# File 'lib/functions_framework/registry.rb', line 39
+
+def [] name
+  @functions[name.to_s]
+end
+
+
+ +
+

+ + #add_cloud_event(name, &block) ⇒ self + + + + + +

+
+

Add a CloudEvent function to the registry.

+ +

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.

+ + +
+
+
+

Parameters:

+
    + +
  • + + name + + + (String) + + + + — +

    The function name

    +
    + +
  • + +
  • + + block + + + (Proc) + + + + — +

    The function code as a proc

    +
    + +
  • + +
+ +

Returns:

+
    + +
  • + + + (self) + + + +
  • + +
+ +
+ + + + +
+
+
+
+90
+91
+92
+93
+94
+95
+96
+97
+
+
# File 'lib/functions_framework/registry.rb', line 90
+
+def add_cloud_event name, &block
+  name = name.to_s
+  synchronize do
+    raise ::ArgumentError, "Function already defined: #{name}" if @functions.key? name
+    @functions[name] = Function.new name, :cloud_event, &block
+  end
+  self
+end
+
+
+ +
+

+ + #add_http(name, &block) ⇒ self + + + + + +

+
+

Add an HTTP function to the registry.

+ +

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:

+ +
    +
  • A standard 3-element Rack response array. See +https://github.com/rack/rack/blob/master/SPEC
  • +
  • A Rack::Response object.
  • +
  • A simple String that will be sent as the response body.
  • +
  • A Hash object that will be encoded as JSON and sent as the response +body.
  • +
+ + +
+
+
+

Parameters:

+
    + +
  • + + name + + + (String) + + + + — +

    The function name

    +
    + +
  • + +
  • + + block + + + (Proc) + + + + — +

    The function code as a proc

    +
    + +
  • + +
+ +

Returns:

+
    + +
  • + + + (self) + + + +
  • + +
+ +
+ + + + +
+
+
+
+69
+70
+71
+72
+73
+74
+75
+76
+
+
# File 'lib/functions_framework/registry.rb', line 69
+
+def add_http name, &block
+  name = name.to_s
+  synchronize do
+    raise ::ArgumentError, "Function already defined: #{name}" if @functions.key? name
+    @functions[name] = Function.new name, :http, &block
+  end
+  self
+end
+
+
+ +
+

+ + #namesArray<String> + + + + + +

+
+

Returns the list of defined names

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Array<String>) + + + +
  • + +
+ +
+ + + + +
+
+
+
+48
+49
+50
+
+
# File 'lib/functions_framework/registry.rb', line 48
+
+def names
+  @functions.keys.sort
+end
+
+
+ +
+ +
+ + + +
+ + \ No newline at end of file diff --git a/v0.5.0/FunctionsFramework/Server.html b/v0.5.0/FunctionsFramework/Server.html new file mode 100644 index 00000000..45dd0fa6 --- /dev/null +++ b/v0.5.0/FunctionsFramework/Server.html @@ -0,0 +1,1004 @@ + + + + + +Codestin Search App + + + + + + + + + + + + + + + + + +
+ + +

Class: FunctionsFramework::Server + + + +

+
+ +
+
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+
+ + + + + + +
+
Includes:
+
MonitorMixin
+
+ + + + + + +
+
Defined in:
+
lib/functions_framework/server.rb
+
+ +
+ +

Overview

+
+

A web server that wraps a function.

+ + +
+
+
+ + +

Defined Under Namespace

+

+ + + + + Classes: Config + + +

+ + + + +

Instance Attribute Summary collapse

+ + + + + + +

+ Instance Method Summary + collapse +

+ + + + + +
+

Constructor Details

+ +
+

+ + #initialize(function) {|FunctionsFramework::Server::Config| ... } ⇒ Server + + + + + +

+
+

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.

+ + +
+
+
+

Parameters:

+ + +

Yields:

+ + +
+ + + + +
+
+
+
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+
+
# File 'lib/functions_framework/server.rb', line 40
+
+def initialize function
+  super()
+  @config = Config.new
+  yield @config if block_given?
+  @config.freeze
+  @function = function
+  @app =
+    case function.type
+    when :http
+      HttpApp.new function, @config
+    when :cloud_event
+      EventApp.new function, @config
+    else
+      raise "Unrecognized function type: #{function.type}"
+    end
+  @server = nil
+  @signals_installed = false
+end
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + #configFunctionsFramework::Server::Config (readonly) + + + + + +

+
+

The final configuration. This is a frozen object that cannot be modified.

+ + +
+
+
+ +

Returns:

+ + +
+ + + + +
+
+
+
+69
+70
+71
+
+
# File 'lib/functions_framework/server.rb', line 69
+
+def config
+  @config
+end
+
+
+ + + +
+

+ + #functionFunctionsFramework::Function (readonly) + + + + + +

+
+

The function to execute.

+ + +
+
+
+ +

Returns:

+ + +
+ + + + +
+
+
+
+63
+64
+65
+
+
# File 'lib/functions_framework/server.rb', line 63
+
+def function
+  @function
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + #respond_to_signalsself + + + + + +

+
+

Cause this server to respond to SIGTERM, SIGINT, and SIGHUP by shutting +down gracefully.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (self) + + + +
  • + +
+ +
+ + + + +
+
+
+
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+
+
# File 'lib/functions_framework/server.rb', line 143
+
+def respond_to_signals
+  synchronize do
+    return self if @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
+
+def running?
+  @server&.thread&.alive?
+end
+
+
+ +
+

+ + #startself + + + + + +

+
+

Start the web server in the background. Does nothing if the web server +is already running.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (self) + + + +
  • + +
+ +
+ + + + +
+
+
+
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+
+
# File 'lib/functions_framework/server.rb', line 77
+
+def start
+  synchronize do
+    unless running?
+      @server = ::Puma::Server.new @app
+      @server.min_threads = @config.min_threads
+      @server.max_threads = @config.max_threads
+      @server.leak_stack_on_error = @config.show_error_details?
+      @server.binder.add_tcp_listener @config.bind_addr, @config.port
+      @server.run true
+      @config.logger.info "FunctionsFramework: Serving function #{@function.name.inspect}" \
+                          " on port #{@config.port}..."
+    end
+  end
+  self
+end
+
+
+ +
+

+ + #stop(force: false, wait: false) ⇒ self + + + + + +

+
+

Stop the web server in the background. Does nothing if the web server +is not running.

+ + +
+
+
+

Parameters:

+
    + +
  • + + force + + + (Boolean) + + + (defaults to: false) + + + — +

    Use a forced halt instead of a graceful shutdown

    +
    + +
  • + +
  • + + wait + + + (Boolean) + + + (defaults to: false) + + + — +

    Block until shutdown is complete

    +
    + +
  • + +
+ +

Returns:

+
    + +
  • + + + (self) + + + +
  • + +
+ +
+ + + + +
+
+
+
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+
+
# File 'lib/functions_framework/server.rb', line 101
+
+def stop force: false, wait: false
+  synchronize do
+    if running?
+      @config.logger.info "FunctionsFramework: Shutting down server..."
+      if force
+        @server.halt wait
+      else
+        @server.stop wait
+      end
+    end
+  end
+  self
+end
+
+
+ +
+

+ + #wait_until_stopped(timeout: nil) ⇒ self + + + + + +

+
+

Wait for the server to stop. Returns immediately if the server is not +running.

+ + +
+
+
+

Parameters:

+
    + +
  • + + timeout + + + (nil, Numeric) + + + (defaults to: nil) + + + — +

    The timeout. If nil (the default), waits +indefinitely, otherwise times out after the given number of seconds.

    +
    + +
  • + +
+ +

Returns:

+
    + +
  • + + + (self) + + + +
  • + +
+ +
+ + + + +
+
+
+
+123
+124
+125
+126
+
+
# File 'lib/functions_framework/server.rb', line 123
+
+def wait_until_stopped timeout: nil
+  @server&.thread&.join timeout
+  self
+end
+
+
+ +
+ +
+ + + +
+ + \ No newline at end of file diff --git a/v0.5.0/FunctionsFramework/Server/Config.html b/v0.5.0/FunctionsFramework/Server/Config.html new file mode 100644 index 00000000..26f2ace5 --- /dev/null +++ b/v0.5.0/FunctionsFramework/Server/Config.html @@ -0,0 +1,1322 @@ + + + + + +Codestin Search App + + + + + + + + + + + + + + + + + +
+ + +

Class: FunctionsFramework::Server::Config + + + +

+
+ +
+
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+
+ + + + + + + + + + + +
+
Defined in:
+
lib/functions_framework/server.rb
+
+ +
+ +

Overview

+
+

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.

+ + +
+
+
+ + +
+ + + + + + + +

+ Instance Method Summary + collapse +

+ + + + +
+

Constructor Details

+ +
+

+ + #initializeConfig + + + + + +

+
+

Create a new config object with the default settings

+ + +
+
+
+ + +
+ + + + +
+
+
+
+195
+196
+197
+198
+199
+200
+201
+202
+203
+
+
# File 'lib/functions_framework/server.rb', line 195
+
+def initialize
+  self.rack_env = nil
+  self.bind_addr = nil
+  self.port = nil
+  self.min_threads = nil
+  self.max_threads = nil
+  self.show_error_details = nil
+  self.logger = nil
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + #bind_addrString + + + + + +

+
+

Returns the current bind address.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (String) + + + +
  • + +
+ +
+ + + + +
+
+
+
+279
+280
+281
+
+
# File 'lib/functions_framework/server.rb', line 279
+
+def bind_addr
+  @bind_addr
+end
+
+
+ +
+

+ + #bind_addr=(bind_addr) ⇒ Object + + + + + +

+
+

Set the bind address, or nil to use the default.

+ + +
+
+
+

Parameters:

+
    + +
  • + + bind_addr + + + (String, nil) + + + +
  • + +
+ + +
+ + + + +
+
+
+
+218
+219
+220
+
+
# File 'lib/functions_framework/server.rb', line 218
+
+def bind_addr= bind_addr
+  @bind_addr = bind_addr || ::ENV["FUNCTION_BIND_ADDR"] || "0.0.0.0"
+end
+
+
+ +
+

+ + #loggerLogger + + + + + +

+
+

Returns the logger.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Logger) + + + +
  • + +
+ +
+ + + + +
+
+
+
+319
+320
+321
+
+
# File 'lib/functions_framework/server.rb', line 319
+
+def logger
+  @logger
+end
+
+
+ +
+

+ + #logger=(logger) ⇒ Object + + + + + +

+
+

Set the logger for server messages, or nil to use the global default.

+ + +
+
+
+

Parameters:

+
    + +
  • + + logger + + + (Logger) + + + +
  • + +
+ + +
+ + + + +
+
+
+
+263
+264
+265
+
+
# File 'lib/functions_framework/server.rb', line 263
+
+def logger= logger
+  @logger = logger || ::FunctionsFramework.logger
+end
+
+
+ +
+

+ + #max_threadsInteger + + + + + +

+
+

Returns the maximum number of worker threads in the thread pool.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Integer) + + + +
  • + +
+ +
+ + + + +
+
+
+
+303
+304
+305
+
+
# File 'lib/functions_framework/server.rb', line 303
+
+def max_threads
+  @max_threads || (@rack_env == "development" ? 1 : 16)
+end
+
+
+ +
+

+ + #max_threads=(max_threads) ⇒ Object + + + + + +

+
+

Set the maximum number of worker threads, or nil to use the default.

+ + +
+
+
+

Parameters:

+
    + +
  • + + max_threads + + + (Integer, nil) + + + +
  • + +
+ + +
+ + + + +
+
+
+
+242
+243
+244
+
+
# File 'lib/functions_framework/server.rb', line 242
+
+def max_threads= max_threads
+  @max_threads = (max_threads || ::ENV["FUNCTION_MAX_THREADS"])&.to_i
+end
+
+
+ +
+

+ + #min_threadsInteger + + + + + +

+
+

Returns the minimum number of worker threads in the thread pool.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Integer) + + + +
  • + +
+ +
+ + + + +
+
+
+
+295
+296
+297
+
+
# File 'lib/functions_framework/server.rb', line 295
+
+def min_threads
+  @min_threads || 1
+end
+
+
+ +
+

+ + #min_threads=(min_threads) ⇒ Object + + + + + +

+
+

Set the minimum number of worker threads, or nil to use the default.

+ + +
+
+
+

Parameters:

+
    + +
  • + + min_threads + + + (Integer, nil) + + + +
  • + +
+ + +
+ + + + +
+
+
+
+234
+235
+236
+
+
# File 'lib/functions_framework/server.rb', line 234
+
+def min_threads= min_threads
+  @min_threads = (min_threads || ::ENV["FUNCTION_MIN_THREADS"])&.to_i
+end
+
+
+ +
+

+ + #portInteger + + + + + +

+
+

Returns the current port number.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Integer) + + + +
  • + +
+ +
+ + + + +
+
+
+
+287
+288
+289
+
+
# File 'lib/functions_framework/server.rb', line 287
+
+def port
+  @port
+end
+
+
+ +
+

+ + #port=(port) ⇒ Object + + + + + +

+
+

Set the port number, or nil to use the default.

+ + +
+
+
+

Parameters:

+
    + +
  • + + port + + + (Integer, nil) + + + +
  • + +
+ + +
+ + + + +
+
+
+
+226
+227
+228
+
+
# File 'lib/functions_framework/server.rb', line 226
+
+def port= port
+  @port = (port || ::ENV["PORT"] || 8080).to_i
+end
+
+
+ +
+

+ + #rack_envString + + + + + +

+
+

Returns the current Rack environment.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (String) + + + +
  • + +
+ +
+ + + + +
+
+
+
+271
+272
+273
+
+
# File 'lib/functions_framework/server.rb', line 271
+
+def rack_env
+  @rack_env
+end
+
+
+ +
+

+ + #rack_env=(rack_env) ⇒ Object + + + + + +

+
+

Set the Rack environment, or nil to use the default.

+ + +
+
+
+

Parameters:

+
    + +
  • + + rack_env + + + (String, nil) + + + +
  • + +
+ + +
+ + + + +
+
+
+
+209
+210
+211
+212
+
+
# File 'lib/functions_framework/server.rb', line 209
+
+def rack_env= rack_env
+  @rack_env = rack_env || ::ENV["RACK_ENV"] ||
+              (::ENV["K_REVISION"] ? "production" : "development")
+end
+
+
+ +
+

+ + #show_error_details=(show_error_details) ⇒ Object + + + + + +

+
+

Set whether to show detailed error messages, or nil to use the default.

+ + +
+
+
+

Parameters:

+
    + +
  • + + show_error_details + + + (Boolean, nil) + + + +
  • + +
+ + +
+ + + + +
+
+
+
+250
+251
+252
+253
+254
+255
+256
+257
+
+
# File 'lib/functions_framework/server.rb', line 250
+
+def show_error_details= show_error_details
+  @show_error_details =
+    if show_error_details.nil?
+      !::ENV["FUNCTION_DETAILED_ERRORS"].to_s.empty?
+    else
+      show_error_details ? true : false
+    end
+end
+
+
+ +
+

+ + #show_error_details?Boolean + + + + + +

+
+

Returns whether to show detailed error messages.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + +
  • + +
+ +
+ + + + +
+
+
+
+311
+312
+313
+
+
# File 'lib/functions_framework/server.rb', line 311
+
+def show_error_details?
+  @show_error_details.nil? ? (@rack_env == "development") : @show_error_details
+end
+
+
+ +
+ +
+ + + +
+ + \ No newline at end of file diff --git a/v0.5.0/FunctionsFramework/Testing.html b/v0.5.0/FunctionsFramework/Testing.html new file mode 100644 index 00000000..c847891e --- /dev/null +++ b/v0.5.0/FunctionsFramework/Testing.html @@ -0,0 +1,1199 @@ + + + + + +Codestin Search App + + + + + + + + + + + + + + + + + +
+ + +

Module: FunctionsFramework::Testing + + + +

+
+ + + + +
+
Extended by:
+
Testing
+
+ + + + + + +
+
Included in:
+
Testing
+
+ + + +
+
Defined in:
+
lib/functions_framework/testing.rb
+
+ +
+ +

Overview

+
+

Helpers for writing unit tests.

+ +

Methods on this module can be called as module methods, or this module can +be included in a test class.

+ +

Example

+ +

Suppose we have the following app that uses the functions framework:

+ +
# app.rb
+
+require "functions_framework"
+
+FunctionsFramework.http "my-function" do |request|
+  "Hello, world!"
+end
+
+ +

The following is a test that could be run against that app:

+ +
# test_app.rb
+
+require "minitest/autorun"
+require "functions_framework/testing"
+
+class MyTest < Minitest::Test
+  # Make the testing methods available.
+  include FunctionsFramework::Testing
+
+  def test_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
+
+ + +
+
+
+ + +
+ + + + + + + +

+ Instance Method Summary + collapse +

+ + + + + + +
+

Instance Method Details

+ + +
+

+ + #call_event(name, event) ⇒ nil + + + + + +

+
+

Call the given event function for testing. The underlying function must +be of type :cloud_event`.

+ + +
+
+
+

Parameters:

+
    + +
  • + + name + + + (String) + + + + — +

    The name of the function to call

    +
    + +
  • + +
  • + + event + + + (::CloudEvents::Event) + + + + — +

    The event to send

    +
    + +
  • + +
+ +

Returns:

+
    + +
  • + + + (nil) + + + +
  • + +
+ +
+ + + + +
+
+
+
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+
+
# File 'lib/functions_framework/testing.rb', line 106
+
+def call_event name, event
+  function = ::FunctionsFramework.global_registry[name]
+  case function&.type
+  when :cloud_event
+    function.new_call.call event
+    nil
+  when nil
+    raise "Unknown function name #{name}"
+  else
+    raise "Function #{name} is not a CloudEvent function"
+  end
+end
+
+
+ +
+

+ + #call_http(name, request) ⇒ Rack::Response + + + + + +

+
+

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
+
+def call_http name, request
+  function = ::FunctionsFramework.global_registry[name]
+  case function&.type
+  when :http
+    Testing.interpret_response { function.new_call.call request }
+  when nil
+    raise "Unknown function name #{name}"
+  else
+    raise "Function #{name} is not an HTTP function"
+  end
+end
+
+
+ +
+

+ + #load_temporary(path, &block) ⇒ Object + + + + + +

+
+

Load the given functions source for the duration of the given block, +and restore the previous status afterward.

+ + +
+
+
+

Parameters:

+
    + +
  • + + path + + + (String) + + + + — +

    File path to load

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+73
+74
+75
+76
+
+
# File 'lib/functions_framework/testing.rb', line 73
+
+def load_temporary path, &block
+  path = ::File.expand_path path
+  Testing.load_for_testing path, &block
+end
+
+
+ +
+

+ + #make_cloud_event(data, id: nil, source: nil, type: nil, spec_version: nil, data_content_type: nil, data_schema: nil, subject: nil, time: nil) ⇒ ::CloudEvents::Event + + + + + +

+
+

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) + + + — +

    Event ID (optional)

    +
    + +
  • + +
  • + + source + + + (String, URI) + + + (defaults to: nil) + + + — +

    Event source (optional)

    +
    + +
  • + +
  • + + type + + + (String) + + + (defaults to: nil) + + + — +

    Event type (optional)

    +
    + +
  • + +
  • + + spec_version + + + (String) + + + (defaults to: nil) + + + — +

    Spec version (optional)

    +
    + +
  • + +
  • + + data_content_type + + + (String, ::CloudEvents::ContentType) + + + (defaults to: nil) + + + — +

    Content type for the data (optional)

    +
    + +
  • + +
  • + + data_schema + + + (String, URI) + + + (defaults to: nil) + + + — +

    Data schema (optional)

    +
    + +
  • + +
  • + + subject + + + (String) + + + (defaults to: nil) + + + — +

    Subject (optional)

    +
    + +
  • + +
  • + + time + + + (String, DateTime) + + + (defaults to: nil) + + + — +

    Event timestamp (optional)

    +
    + +
  • + +
+ +

Returns:

+
    + +
  • + + + (::CloudEvents::Event) + + + +
  • + +
+ +
+ + + + +
+
+
+
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+
+
# File 'lib/functions_framework/testing.rb', line 184
+
+def make_cloud_event data,
+                     id: nil,
+                     source: nil,
+                     type: nil,
+                     spec_version: nil,
+                     data_content_type: nil,
+                     data_schema: nil,
+                     subject: nil,
+                     time: nil
+  id ||= "random-id-#{rand 100_000_000}"
+  source ||= "functions-framework-testing"
+  type ||= "com.example.test"
+  spec_version ||= "1.0"
+  ::CloudEvents::Event.new id:                id,
+                           source:            source,
+                           type:              type,
+                           spec_version:      spec_version,
+                           data_content_type: data_content_type,
+                           data_schema:       data_schema,
+                           subject:           subject,
+                           time:              time,
+                           data:              data
+end
+
+
+ +
+

+ + #make_get_request(url, headers = []) ⇒ Rack::Request + + + + + +

+
+

Make a simple GET request, for passing to a function test.

+ + +
+
+
+

Parameters:

+
    + +
  • + + url + + + (URI, String) + + + + — +

    The URL to get.

    +
    + +
  • + +
  • + + headers + + + (Array, Hash) + + + (defaults to: []) + + + — +

    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
+
+def make_get_request url, headers = []
+  make_request url, headers: headers
+end
+
+
+ +
+

+ + #make_post_request(url, body, headers = []) ⇒ Rack::Request + + + + + +

+
+

Make a simple POST request, for passing to a function test.

+ + +
+
+
+

Parameters:

+
    + +
  • + + url + + + (URI, String) + + + + — +

    The URL to post to.

    +
    + +
  • + +
  • + + body + + + (String) + + + + — +

    The body to post.

    +
    + +
  • + +
  • + + headers + + + (Array, Hash) + + + (defaults to: []) + + + — +

    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
+
+def make_post_request url, body, headers = []
+  make_request url, method: ::Rack::POST, body: body, headers: headers
+end
+
+
+ +
+

+ + #make_request(url, method: ::Rack::GET, body: nil, headers: []) ⇒ Rack::Request + + + + + +

+
+

Make a Rack request, for passing to a function test.

+ + +
+
+
+

Parameters:

+
    + +
  • + + url + + + (URI, String) + + + + — +

    The URL to get, including query params.

    +
    + +
  • + +
  • + + method + + + (String) + + + (defaults to: ::Rack::GET) + + + — +

    The HTTP method (defaults to "GET").

    +
    + +
  • + +
  • + + body + + + (String) + + + (defaults to: nil) + + + — +

    The HTTP body, if any.

    +
    + +
  • + +
  • + + headers + + + (Array, Hash) + + + (defaults to: []) + + + — +

    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) + + + +
  • + +
+ +
+ + + + +
+
+
+
+131
+132
+133
+134
+135
+136
+
+
# File 'lib/functions_framework/testing.rb', line 131
+
+def make_request url, method: ::Rack::GET, body: nil, headers: []
+  env = Testing.build_standard_env URI(url), headers
+  env[::Rack::REQUEST_METHOD] = method
+  env[::Rack::RACK_INPUT] = ::StringIO.new body if body
+  ::Rack::Request.new env
+end
+
+
+ +
+ +
+ + + +
+ + \ No newline at end of file diff --git a/v0.5.0/_index.html b/v0.5.0/_index.html new file mode 100644 index 00000000..0082614b --- /dev/null +++ b/v0.5.0/_index.html @@ -0,0 +1,218 @@ + + + + + +Codestin Search App + + + + + + + + + + + + + + + + + +
+ + +

Functions

+
+

Alphabetic Index

+ +

File Listing

+ + +
+

Namespace Listing A-Z

+ + + + + + + + +
+ + +
    +
  • C
  • +
      + +
    • + CLI + + (FunctionsFramework) + +
    • + +
    • + CallBase + + (FunctionsFramework::Function) + +
    • + +
    • + Config + + (FunctionsFramework::Server) + +
    • + +
    +
+ + + + + + + + +
    +
  • R
  • +
      + +
    • + Registry + + (FunctionsFramework) + +
    • + +
    +
+ + +
    +
  • S
  • +
      + +
    • + Server + + (FunctionsFramework) + +
    • + +
    +
+ + +
    +
  • T
  • +
      + +
    • + Testing + + (FunctionsFramework) + +
    • + +
    +
+ +
+ +
+ +
+ + + +
+ + \ No newline at end of file diff --git a/v0.5.0/class_list.html b/v0.5.0/class_list.html new file mode 100644 index 00000000..8cdca07e --- /dev/null +++ b/v0.5.0/class_list.html @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + Codestin Search App + + + +
+
+

Class List

+ + + +
+ + +
+ + diff --git a/v0.5.0/css/common.css b/v0.5.0/css/common.css new file mode 100644 index 00000000..cf25c452 --- /dev/null +++ b/v0.5.0/css/common.css @@ -0,0 +1 @@ +/* Override this file with custom rules */ \ No newline at end of file diff --git a/v0.5.0/css/full_list.css b/v0.5.0/css/full_list.css new file mode 100644 index 00000000..fa359824 --- /dev/null +++ b/v0.5.0/css/full_list.css @@ -0,0 +1,58 @@ +body { + margin: 0; + font-family: "Lucida Sans", "Lucida Grande", Verdana, Arial, sans-serif; + font-size: 13px; + height: 101%; + overflow-x: hidden; + background: #fafafa; +} + +h1 { padding: 12px 10px; padding-bottom: 0; margin: 0; font-size: 1.4em; } +.clear { clear: both; } +.fixed_header { position: fixed; background: #fff; width: 100%; padding-bottom: 10px; margin-top: 0; top: 0; z-index: 9999; height: 70px; } +#search { position: absolute; right: 5px; top: 9px; padding-left: 24px; } +#content.insearch #search, #content.insearch #noresults { background: url(data:image/gif;base64,R0lGODlhEAAQAPYAAP///wAAAPr6+pKSkoiIiO7u7sjIyNjY2J6engAAAI6OjsbGxjIyMlJSUuzs7KamppSUlPLy8oKCghwcHLKysqSkpJqamvT09Pj4+KioqM7OzkRERAwMDGBgYN7e3ujo6Ly8vCoqKjY2NkZGRtTU1MTExDw8PE5OTj4+PkhISNDQ0MrKylpaWrS0tOrq6nBwcKysrLi4uLq6ul5eXlxcXGJiYoaGhuDg4H5+fvz8/KKiohgYGCwsLFZWVgQEBFBQUMzMzDg4OFhYWBoaGvDw8NbW1pycnOLi4ubm5kBAQKqqqiQkJCAgIK6urnJyckpKSjQ0NGpqatLS0sDAwCYmJnx8fEJCQlRUVAoKCggICLCwsOTk5ExMTPb29ra2tmZmZmhoaNzc3KCgoBISEiIiIgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCAAAACwAAAAAEAAQAAAHaIAAgoMgIiYlg4kACxIaACEJCSiKggYMCRselwkpghGJBJEcFgsjJyoAGBmfggcNEx0flBiKDhQFlIoCCA+5lAORFb4AJIihCRbDxQAFChAXw9HSqb60iREZ1omqrIPdJCTe0SWI09GBACH5BAkIAAAALAAAAAAQABAAAAdrgACCgwc0NTeDiYozCQkvOTo9GTmDKy8aFy+NOBA7CTswgywJDTIuEjYFIY0JNYMtKTEFiRU8Pjwygy4ws4owPyCKwsMAJSTEgiQlgsbIAMrO0dKDGMTViREZ14kYGRGK38nHguHEJcvTyIEAIfkECQgAAAAsAAAAABAAEAAAB2iAAIKDAggPg4iJAAMJCRUAJRIqiRGCBI0WQEEJJkWDERkYAAUKEBc4Po1GiKKJHkJDNEeKig4URLS0ICImJZAkuQAhjSi/wQyNKcGDCyMnk8u5rYrTgqDVghgZlYjcACTA1sslvtHRgQAh+QQJCAAAACwAAAAAEAAQAAAHZ4AAgoOEhYaCJSWHgxGDJCQARAtOUoQRGRiFD0kJUYWZhUhKT1OLhR8wBaaFBzQ1NwAlkIszCQkvsbOHL7Y4q4IuEjaqq0ZQD5+GEEsJTDCMmIUhtgk1lo6QFUwJVDKLiYJNUd6/hoEAIfkECQgAAAAsAAAAABAAEAAAB2iAAIKDhIWGgiUlh4MRgyQkjIURGRiGGBmNhJWHm4uen4ICCA+IkIsDCQkVACWmhwSpFqAABQoQF6ALTkWFnYMrVlhWvIKTlSAiJiVVPqlGhJkhqShHV1lCW4cMqSkAR1ofiwsjJyqGgQAh+QQJCAAAACwAAAAAEAAQAAAHZ4AAgoOEhYaCJSWHgxGDJCSMhREZGIYYGY2ElYebi56fhyWQniSKAKKfpaCLFlAPhl0gXYNGEwkhGYREUywag1wJwSkHNDU3D0kJYIMZQwk8MjPBLx9eXwuETVEyAC/BOKsuEjYFhoEAIfkECQgAAAAsAAAAABAAEAAAB2eAAIKDhIWGgiUlh4MRgyQkjIURGRiGGBmNhJWHm4ueICImip6CIQkJKJ4kigynKaqKCyMnKqSEK05StgAGQRxPYZaENqccFgIID4KXmQBhXFkzDgOnFYLNgltaSAAEpxa7BQoQF4aBACH5BAkIAAAALAAAAAAQABAAAAdogACCg4SFggJiPUqCJSWGgkZjCUwZACQkgxGEXAmdT4UYGZqCGWQ+IjKGGIUwPzGPhAc0NTewhDOdL7Ykji+dOLuOLhI2BbaFETICx4MlQitdqoUsCQ2vhKGjglNfU0SWmILaj43M5oEAOwAAAAAAAAAAAA==) no-repeat center left; } +#full_list { padding: 0; list-style: none; margin-left: 0; margin-top: 80px; font-size: 1.1em; } +#full_list ul { padding: 0; } +#full_list li { padding: 0; margin: 0; list-style: none; } +#full_list li .item { padding: 5px 5px 5px 12px; } +#noresults { padding: 7px 12px; background: #fff; } +#content.insearch #noresults { margin-left: 7px; } +li.collapsed ul { display: none; } +li a.toggle { cursor: default; position: relative; left: -5px; top: 4px; text-indent: -999px; width: 10px; height: 9px; margin-left: -10px; display: block; float: left; background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAK8AAACvABQqw0mAAAABx0RVh0U29mdHdhcmUAQWRvYmUgRmlyZXdvcmtzIENTM5jWRgMAAAAVdEVYdENyZWF0aW9uIFRpbWUAMy8xNC8wOeNZPpQAAAE2SURBVDiNrZTBccIwEEXfelIAHUA6CZ24BGaWO+FuzZAK4k6gg5QAdGAq+Bxs2Yqx7BzyL7Llp/VfzZeQhCTc/ezuGzKKnKSzpCxXJM8fwNXda3df5RZETlIt6YUzSQDs93sl8w3wBZxCCE10GM1OcWbWjB2mWgEH4Mfdyxm3PSepBHibgQE2wLe7r4HjEidpnXMYdQPKEMJcsZ4zs2POYQOcaPfwMVOo58zsAdMt18BuoVDPxUJRacELbXv3hUIX2vYmOUvi8C8ydz/ThjXrqKqqLbDIAdsCKBd+Wo7GWa7o9qzOQHVVVXeAbs+yHHCH4aTsaCOQqunmUy1yBUAXkdMIfMlgF5EXLo2OpV/c/Up7jG4hhHcYLgWzAZXUc2b2ixsfvc/RmNNfOXD3Q/oeL9axJE1yT9IOoUu6MGUkAAAAAElFTkSuQmCC) no-repeat bottom left; } +li.collapsed a.toggle { opacity: 0.5; cursor: default; background-position: top left; } +li { color: #888; cursor: pointer; } +li.deprecated { text-decoration: line-through; font-style: italic; } +li.odd { background: #f0f0f0; } +li.even { background: #fafafa; } +.item:hover { background: #ddd; } +li small:before { content: "("; } +li small:after { content: ")"; } +li small.search_info { display: none; } +a, a:visited { text-decoration: none; color: #05a; } +li.clicked > .item { background: #05a; color: #ccc; } +li.clicked > .item a, li.clicked > .item a:visited { color: #eee; } +li.clicked > .item a.toggle { opacity: 0.5; background-position: bottom right; } +li.collapsed.clicked a.toggle { background-position: top right; } +#search input { border: 1px solid #bbb; border-radius: 3px; } +#full_list_nav { margin-left: 10px; font-size: 0.9em; display: block; color: #aaa; } +#full_list_nav a, #nav a:visited { color: #358; } +#full_list_nav a:hover { background: transparent; color: #5af; } +#full_list_nav span:after { content: ' | '; } +#full_list_nav span:last-child:after { content: ''; } + +#content h1 { margin-top: 0; } +li { white-space: nowrap; cursor: normal; } +li small { display: block; font-size: 0.8em; } +li small:before { content: ""; } +li small:after { content: ""; } +li small.search_info { display: none; } +#search { width: 170px; position: static; margin: 3px; margin-left: 10px; font-size: 0.9em; color: #888; padding-left: 0; padding-right: 24px; } +#content.insearch #search { background-position: center right; } +#search input { width: 110px; } + +#full_list.insearch ul { display: block; } +#full_list.insearch .item { display: none; } +#full_list.insearch .found { display: block; padding-left: 11px !important; } +#full_list.insearch li a.toggle { display: none; } +#full_list.insearch li small.search_info { display: block; } diff --git a/v0.5.0/css/style.css b/v0.5.0/css/style.css new file mode 100644 index 00000000..62f4349d --- /dev/null +++ b/v0.5.0/css/style.css @@ -0,0 +1,496 @@ +html { + width: 100%; + height: 100%; +} +body { + font-family: "Lucida Sans", "Lucida Grande", Verdana, Arial, sans-serif; + font-size: 13px; + width: 100%; + margin: 0; + padding: 0; + display: flex; + display: -webkit-flex; + display: -ms-flexbox; +} + +#nav { + position: relative; + width: 100%; + height: 100%; + border: 0; + border-right: 1px dotted #eee; + overflow: auto; +} +.nav_wrap { + margin: 0; + padding: 0; + width: 20%; + height: 100%; + position: relative; + display: flex; + display: -webkit-flex; + display: -ms-flexbox; + flex-shrink: 0; + -webkit-flex-shrink: 0; + -ms-flex: 1 0; +} +#resizer { + position: absolute; + right: -5px; + top: 0; + width: 10px; + height: 100%; + cursor: col-resize; + z-index: 9999; +} +#main { + flex: 5 1; + -webkit-flex: 5 1; + -ms-flex: 5 1; + outline: none; + position: relative; + background: #fff; + padding: 1.2em; + padding-top: 0.2em; +} + +@media (max-width: 920px) { + .nav_wrap { width: 100%; top: 0; right: 0; overflow: visible; position: absolute; } + #resizer { display: none; } + #nav { + z-index: 9999; + background: #fff; + display: none; + position: absolute; + top: 40px; + right: 12px; + width: 500px; + max-width: 80%; + height: 80%; + overflow-y: scroll; + border: 1px solid #999; + border-collapse: collapse; + box-shadow: -7px 5px 25px #aaa; + border-radius: 2px; + } +} + +@media (min-width: 920px) { + body { height: 100%; overflow: hidden; } + #main { height: 100%; overflow: auto; } + #search { display: none; } +} + +#main img { max-width: 100%; } +h1 { font-size: 25px; margin: 1em 0 0.5em; padding-top: 4px; border-top: 1px dotted #d5d5d5; } +h1.noborder { border-top: 0px; margin-top: 0; padding-top: 4px; } +h1.title { margin-bottom: 10px; } +h1.alphaindex { margin-top: 0; font-size: 22px; } +h2 { + padding: 0; + padding-bottom: 3px; + border-bottom: 1px #aaa solid; + font-size: 1.4em; + margin: 1.8em 0 0.5em; + position: relative; +} +h2 small { font-weight: normal; font-size: 0.7em; display: inline; position: absolute; right: 0; } +h2 small a { + display: block; + height: 20px; + border: 1px solid #aaa; + border-bottom: 0; + border-top-left-radius: 5px; + background: #f8f8f8; + position: relative; + padding: 2px 7px; +} +.clear { clear: both; } +.inline { display: inline; } +.inline p:first-child { display: inline; } +.docstring, .tags, #filecontents { font-size: 15px; line-height: 1.5145em; } +.docstring p > code, .docstring p > tt, .tags p > code, .tags p > tt { + color: #c7254e; background: #f9f2f4; padding: 2px 4px; font-size: 1em; + border-radius: 4px; +} +.docstring h1, .docstring h2, .docstring h3, .docstring h4 { padding: 0; border: 0; border-bottom: 1px dotted #bbb; } +.docstring h1 { font-size: 1.2em; } +.docstring h2 { font-size: 1.1em; } +.docstring h3, .docstring h4 { font-size: 1em; border-bottom: 0; padding-top: 10px; } +.summary_desc .object_link a, .docstring .object_link a { + font-family: monospace; font-size: 1.05em; + color: #05a; background: #EDF4FA; padding: 2px 4px; font-size: 1em; + border-radius: 4px; +} +.rdoc-term { padding-right: 25px; font-weight: bold; } +.rdoc-list p { margin: 0; padding: 0; margin-bottom: 4px; } +.summary_desc pre.code .object_link a, .docstring pre.code .object_link a { + padding: 0px; background: inherit; color: inherit; border-radius: inherit; +} + +/* style for */ +#filecontents table, .docstring table { border-collapse: collapse; } +#filecontents table th, #filecontents table td, +.docstring table th, .docstring table td { border: 1px solid #ccc; padding: 8px; padding-right: 17px; } +#filecontents table tr:nth-child(odd), +.docstring table tr:nth-child(odd) { background: #eee; } +#filecontents table tr:nth-child(even), +.docstring table tr:nth-child(even) { background: #fff; } +#filecontents table th, .docstring table th { background: #fff; } + +/* style for
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Command-line flagEnvironment variableDescription
--portPORTThe port on which the Functions Framework listens for requests. Default: 8080.
--targetFUNCTION_TARGETThe name of the exported function to be invoked in response to requests. Default: function.
--sourceFUNCTION_SOURCEThe path to the file containing your function. Default: app.rb (in the current working directory).
--signature-typeFUNCTION_SIGNATURE_TYPEVerifies that the function has the expected signature. Allowed values: http, event, or cloudevent.
--environmentRACK_ENVSets the Rack environment.
--bindFUNCTION_BIND_ADDRBinds to the given address. Default: 0.0.0.0.
--min-threadsFUNCTION_MIN_THREADSSets the minimum thread pool size, overriding Puma's default.
--max-threadsFUNCTION_MAX_THREADSSets the maximum thread pool size, overriding Puma's default.
--detailed-errorsFUNCTION_DETAILED_ERRORSNo value. If present, shows exception details in exception responses. Defaults to false.
--verboseFUNCTION_LOGGING_LEVELNo value. Increases log verbosity (e.g. from INFO to DEBUG). Can be given more than once.
--quietFUNCTION_LOGGING_LEVELNo 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 + + + + + + + + + + + + + + + + + +
+ + +

Testing Functions

+ +

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.

+ +
require "minitest/autorun"
+require "functions_framework/testing"
+
+class MyTest < Minitest::Test
+  include FunctionsFramework::Testing
+  # define tests...
+end
+
+ +
require "rspec"
+require "functions_framework/testing"
+
+describe "My functions" do
+  include FunctionsFramework::Testing
+  # define examples...
+end
+
+ +

Loading functions for testing

+ +

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"
+
+class MyTest < Minitest::Test
+  include FunctionsFramework::Testing
+
+  def test_a_function
+    load_temporary "foo.rb" do
+      # Test a function defined in foo.rb
+    end
+  end
+
+  def test_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.

+ +
require "minitest/autorun"
+require "functions_framework/testing"
+
+class MyTest < Minitest::Test
+  include FunctionsFramework::Testing
+
+  def test_http_function
+    load_temporary "app.rb" do
+      request = make_post_request "https://example.com/foo", "{\"name\":\"Ruby\"}",
+                                  ["Content-Type: application/json"]
+      response = call_http "my_function", request
+      assert_equal 200, response.status
+      assert_equal "Hello, Ruby!", response.body.join
+    end
+  end
+end
+
+ +

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.

+ +
require "minitest/autorun"
+require "functions_framework/testing"
+
+class MyTest < Minitest::Test
+  include FunctionsFramework::Testing
+
+  def test_erroring_http_function
+    load_temporary "app.rb" do
+      request = make_post_request "https://example.com/foo", "{\"name\":\"Ruby\"}",
+                                  ["Content-Type: application/json"]
+      response = call_http "error_function", request
+      assert_equal 500, response.status
+      assert_match(/ArgumentError/, response.body.join)
+    end
+  end
+end
+
+ +

Testing CloudEvent functions

+ +

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"
+
+class MyTest < Minitest::Test
+  include FunctionsFramework::Testing
+
+  def test_event_function
+    load_temporary "app.rb" do
+      event = make_cloud_event "Hello, world!", type: "my-type"
+      _out, err = capture_subprocess_io do
+        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 + + + + + + + + + + + + + + + + + +
+ + +

Writing Functions

+ +

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:

+ +
require "functions_framework"
+
+FunctionsFramework.http "hello" do |request|
+  # Return the response body.
+  "Hello, world!\n"
+end
+
+ +

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:

+ +
# Gemfile
+source "https://rubygems.org"
+gem "functions_framework", "~> 0.5"
+gem "sinatra", "~> 2.0"
+
+ +

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:

+ +
require "functions_framework"
+require "sinatra/base"
+
+class App < Sinatra::Base
+  get "/hello/:name" do
+    "Hello, #{params[:name]}!"
+  end
+end
+
+FunctionsFramework.http "sinatra_example" do |request|
+  App.call request.env
+end
+
+ +

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:

+ +
require "functions_framework"
+
+FunctionsFramework.cloud_event "hello" do |event|
+  FunctionsFramework.logger.info "I received an event of type #{event.type}!"
+end
+
+ +

The event parameter will be either a +CloudEvents V0.3 Event +object (see spec) or a +CloudEvents V1.0 Event +object (see spec).

+ +

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!"
+  rescue RuntimeError => 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.

+ +

A simple project might look like this:

+ +
(project directory)
+|
++- Gemfile
+|
++- app.rb
+|
++- lib/
+|  |
+|  +- hello.rb
+|
++- test/
+   |
+   ...
+
+ +
# Gemfile
+source "https://rubygems.org"
+gem "functions_framework", "~> 0.5"
+
+ +
# app.rb
+require "functions_framework"
+require_relative "lib/hello"
+
+FunctionsFramework.http "hello" do |request|
+  Hello.new(request).build_response
+end
+
+ +
# lib/hello.rb
+class Hello
+  def initialize request
+    @request = request
+  end
+
+  def build_response
+    "Received request: #{request.method} #{request.url}\n"
+  end
+end
+
+ +

Next steps

+ +

To learn about writing unit tests for functions, see +Testing Functions.

+ +

To learn how to run your functions in a server, see +Running a Functions Server.

+ +

To learn how to deploy your functions to Google Cloud Functions or Google Cloud +Run, see +Deploying Functions.

+
+ + + +
+ + \ No newline at end of file diff --git a/v0.5.0/file_list.html b/v0.5.0/file_list.html new file mode 100644 index 00000000..b9d59994 --- /dev/null +++ b/v0.5.0/file_list.html @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + Codestin Search App + + + +
+
+

File List

+ + + +
+ + +
+ + diff --git a/v0.5.0/frames.html b/v0.5.0/frames.html new file mode 100644 index 00000000..2ac156f5 --- /dev/null +++ b/v0.5.0/frames.html @@ -0,0 +1,17 @@ + + + + + Codestin Search App + + + + diff --git a/v0.5.0/index.html b/v0.5.0/index.html new file mode 100644 index 00000000..d6d2c262 --- /dev/null +++ b/v0.5.0/index.html @@ -0,0 +1,208 @@ + + + + + +Codestin Search App + + + + + + + + + + + + + + + + + +
+ + +

Functions Framework for Ruby

+ +

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:

+ + + +

The framework allows you to go from:

+ +
FunctionsFramework.http("hello") do |request|
+  "Hello, world!\n"
+end
+
+ +

To:

+ +
curl http://my-url
+# Output: Hello, world!
+
+ +

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:

+ +
# Gemfile
+source "https://rubygems.org"
+gem "functions_framework", "~> 0.5"
+
+ +

Create a file called app.rb and include the following code. This defines a +simple function called "hello".

+ +
# app.rb
+require "functions_framework"
+
+FunctionsFramework.http("hello") do |request|
+  "Hello, world!\n"
+end
+
+ +

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:

+ +
curl http://localhost:8080
+# Output: Hello, world!
+
+ +

Stop the server with CTRL+C.

+ +

Documentation

+ +

These guides provide additional getting-started information.

+ + + +

The library reference documentation can be found at: +https://rubydoc.info/gems/functions_framework

+ +

Additional examples are available in the GitHub repository: +https://github.com/GoogleCloudPlatform/functions-framework-ruby/blob/master/examples/

+ +

Development

+ +

The source for the Ruby Functions Framework is available on GitHub at +https://github.com/GoogleCloudPlatform/functions-framework-ruby. For more +information on the Functions Framework contract implemented by this framework, +as well as links to Functions Frameworks for other languages, see +https://github.com/GoogleCloudPlatform/functions-framework.

+ +

The Functions Framework is open source under the Apache 2.0 license. +Contributions are welcome. Please see the contributing guide at +https://github.com/GoogleCloudPlatform/functions-framework-ruby/blob/master/.github/CONTRIBUTING.md.

+ +

Report issues at +https://github.com/GoogleCloudPlatform/functions-framework-ruby/issues.

+
+ + + +
+ + \ No newline at end of file diff --git a/v0.5.0/js/app.js b/v0.5.0/js/app.js new file mode 100644 index 00000000..8d067fe3 --- /dev/null +++ b/v0.5.0/js/app.js @@ -0,0 +1,314 @@ +(function() { + +var localStorage = {}, sessionStorage = {}; +try { localStorage = window.localStorage; } catch (e) { } +try { sessionStorage = window.sessionStorage; } catch (e) { } + +function createSourceLinks() { + $('.method_details_list .source_code'). + before("[View source]"); + $('.toggleSource').toggle(function() { + $(this).parent().nextAll('.source_code').slideDown(100); + $(this).text("Hide source"); + }, + function() { + $(this).parent().nextAll('.source_code').slideUp(100); + $(this).text("View source"); + }); +} + +function createDefineLinks() { + var tHeight = 0; + $('.defines').after(" more..."); + $('.toggleDefines').toggle(function() { + tHeight = $(this).parent().prev().height(); + $(this).prev().css('display', 'inline'); + $(this).parent().prev().height($(this).parent().height()); + $(this).text("(less)"); + }, + function() { + $(this).prev().hide(); + $(this).parent().prev().height(tHeight); + $(this).text("more..."); + }); +} + +function createFullTreeLinks() { + var tHeight = 0; + $('.inheritanceTree').toggle(function() { + tHeight = $(this).parent().prev().height(); + $(this).parent().toggleClass('showAll'); + $(this).text("(hide)"); + $(this).parent().prev().height($(this).parent().height()); + }, + function() { + $(this).parent().toggleClass('showAll'); + $(this).parent().prev().height(tHeight); + $(this).text("show all"); + }); +} + +function searchFrameButtons() { + $('.full_list_link').click(function() { + toggleSearchFrame(this, $(this).attr('href')); + return false; + }); + window.addEventListener('message', function(e) { + if (e.data === 'navEscape') { + $('#nav').slideUp(100); + $('#search a').removeClass('active inactive'); + $(window).focus(); + } + }); + + $(window).resize(function() { + if ($('#search:visible').length === 0) { + $('#nav').removeAttr('style'); + $('#search a').removeClass('active inactive'); + $(window).focus(); + } + }); +} + +function toggleSearchFrame(id, link) { + var frame = $('#nav'); + $('#search a').removeClass('active').addClass('inactive'); + if (frame.attr('src') === link && frame.css('display') !== "none") { + frame.slideUp(100); + $('#search a').removeClass('active inactive'); + } + else { + $(id).addClass('active').removeClass('inactive'); + if (frame.attr('src') !== link) frame.attr('src', link); + frame.slideDown(100); + } +} + +function linkSummaries() { + $('.summary_signature').click(function() { + document.location = $(this).find('a').attr('href'); + }); +} + +function summaryToggle() { + $('.summary_toggle').click(function(e) { + e.preventDefault(); + localStorage.summaryCollapsed = $(this).text(); + $('.summary_toggle').each(function() { + $(this).text($(this).text() == "collapse" ? "expand" : "collapse"); + var next = $(this).parent().parent().nextAll('ul.summary').first(); + if (next.hasClass('compact')) { + next.toggle(); + next.nextAll('ul.summary').first().toggle(); + } + else if (next.hasClass('summary')) { + var list = $('