code
stringlengths
26
124k
docstring
stringlengths
23
125k
func_name
stringlengths
1
98
language
stringclasses
1 value
repo
stringlengths
5
53
path
stringlengths
7
151
url
stringlengths
50
211
license
stringclasses
7 values
def filters @filters ||= {} end
Public: Filters hash where the key is the mention base URL. Effectively a cache.
filters
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-mentions-1.6.0/lib/jekyll-mentions.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-mentions-1.6.0/lib/jekyll-mentions.rb
Apache-2.0
def mention_base(config = {}) mention_config = config["jekyll-mentions"] case mention_config when nil, NilClass default_mention_base when String mention_config.to_s when Hash mention_config.fetch("base_url", default_mention_base) else raise InvalidJekyllMentionConfig, "Your jekyll-mentions config has to either be a string or a hash. " \ "It's a #{mention_config.class} right now." end end
Public: Calculate the base URL to use for mentioning. The custom base URL can be defined in either the site config or a document's front matter as `jekyll-mentions.base_url` or `jekyll-mentions`, and must be a valid URL (i.e. it must include a protocol and valid domain). It should _not_ have a trailing slash. config - The effective configuration that includes configurations for mentions. Returns a URL to use as the base URL for mentions. Defaults to the https://github.com.
mention_base
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-mentions-1.6.0/lib/jekyll-mentions.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-mentions-1.6.0/lib/jekyll-mentions.rb
Apache-2.0
def mentionable?(doc) (doc.is_a?(Jekyll::Page) || doc.write?) && (doc.output_ext == ".html" || (doc.permalink&.end_with?("/"))) && (doc.data["jekyll-mentions"] != false) end
Public: Defines the conditions for a document to be mentionable. doc - the Jekyll::Document or Jekyll::Page Returns true if the doc is written & is HTML.
mentionable?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-mentions-1.6.0/lib/jekyll-mentions.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-mentions-1.6.0/lib/jekyll-mentions.rb
Apache-2.0
def pages_to_add pages.reject { |page| blacklisted?(page) } end
An array of Jekyll::Pages to add, *excluding* blacklisted files
pages_to_add
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-optional-front-matter-0.3.2/lib/jekyll-optional-front-matter/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-optional-front-matter-0.3.2/lib/jekyll-optional-front-matter/generator.rb
Apache-2.0
def static_files_to_remove markdown_files.reject { |page| blacklisted?(page) } end
An array of Jekyll::StaticFile's, *excluding* blacklisted files
static_files_to_remove
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-optional-front-matter-0.3.2/lib/jekyll-optional-front-matter/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-optional-front-matter-0.3.2/lib/jekyll-optional-front-matter/generator.rb
Apache-2.0
def pages markdown_files.map { |static_file| page_from_static_file(static_file) } end
An array of potential Jekyll::Pages to add, *including* blacklisted files
pages
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-optional-front-matter-0.3.2/lib/jekyll-optional-front-matter/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-optional-front-matter-0.3.2/lib/jekyll-optional-front-matter/generator.rb
Apache-2.0
def markdown_files site.static_files.select { |file| markdown_converter.matches(file.extname) } end
An array of Jekyll::StaticFile's with a site-defined markdown extension
markdown_files
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-optional-front-matter-0.3.2/lib/jekyll-optional-front-matter/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-optional-front-matter-0.3.2/lib/jekyll-optional-front-matter/generator.rb
Apache-2.0
def page_from_static_file(static_file) base = static_file.instance_variable_get("@base") dir = static_file.instance_variable_get("@dir") name = static_file.instance_variable_get("@name") Jekyll::Page.new(site, base, dir, name) end
Given a Jekyll::StaticFile, returns the file as a Jekyll::Page
page_from_static_file
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-optional-front-matter-0.3.2/lib/jekyll-optional-front-matter/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-optional-front-matter-0.3.2/lib/jekyll-optional-front-matter/generator.rb
Apache-2.0
def blacklisted?(page) return false if whitelisted?(page) FILENAME_BLACKLIST.include?(page.basename.upcase) end
Does the given Jekyll::Page match our filename blacklist?
blacklisted?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-optional-front-matter-0.3.2/lib/jekyll-optional-front-matter/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-optional-front-matter-0.3.2/lib/jekyll-optional-front-matter/generator.rb
Apache-2.0
def initialize(site, page, all_posts, num_pages = nil) @page = page @per_page = site.config['paginate'].to_i @total_pages = num_pages || Pager.calculate_pages(all_posts, @per_page) if @page > @total_pages raise RuntimeError, "page number can't be greater than total pages: #{@page} > #{@total_pages}" end init = (@page - 1) * @per_page offset = (init + @per_page - 1) >= all_posts.size ? all_posts.size : (init + @per_page - 1) @total_posts = all_posts.size @posts = all_posts[init..offset] @previous_page = @page != 1 ? @page - 1 : nil @previous_page_path = Pager.paginate_path(site, @previous_page) @next_page = @page != @total_pages ? @page + 1 : nil @next_page_path = Pager.paginate_path(site, @next_page) end
Initialize a new Pager. site - the Jekyll::Site object page - The Integer page number. all_posts - The Array of all the site's Posts. num_pages - The Integer number of pages or nil if you'd like the number of pages calculated.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-paginate-1.1.0/lib/jekyll-paginate/pager.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-paginate-1.1.0/lib/jekyll-paginate/pager.rb
Apache-2.0
def to_liquid { 'page' => page, 'per_page' => per_page, 'posts' => posts, 'total_posts' => total_posts, 'total_pages' => total_pages, 'previous_page' => previous_page, 'previous_page_path' => previous_page_path, 'next_page' => next_page, 'next_page_path' => next_page_path } end
Convert this Pager's data to a Hash suitable for use by Liquid. Returns the Hash representation of this Pager.
to_liquid
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-paginate-1.1.0/lib/jekyll-paginate/pager.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-paginate-1.1.0/lib/jekyll-paginate/pager.rb
Apache-2.0
def generate(site) if Pager.pagination_enabled?(site) if template = template_page(site) paginate(site, template) else Jekyll.logger.warn "Pagination:", "Pagination is enabled, but I couldn't find " + "an index.html page to use as the pagination template. Skipping pagination." end end end
Generate paginated pages if necessary. site - The Site. Returns nothing.
generate
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-paginate-1.1.0/lib/jekyll-paginate/pagination.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-paginate-1.1.0/lib/jekyll-paginate/pagination.rb
Apache-2.0
def paginate(site, page) all_posts = site.site_payload['site']['posts'] all_posts = all_posts.reject { |p| p['hidden'] } pages = Pager.calculate_pages(all_posts, site.config['paginate'].to_i) (1..pages).each do |num_page| pager = Pager.new(site, num_page, all_posts, pages) if num_page > 1 newpage = Page.new(site, site.source, page.dir, page.name) newpage.pager = pager newpage.dir = Pager.paginate_path(site, num_page) site.pages << newpage else page.pager = pager end end end
Paginates the blog's posts. Renders the index.html file into paginated directories, e.g.: page2/index.html, page3/index.html, etc and adds more site-wide data. site - The Site. page - The index.html Page that requires pagination. {"paginator" => { "page" => <Number>, "per_page" => <Number>, "posts" => [<Post>], "total_posts" => <Number>, "total_pages" => <Number>, "previous_page" => <Number>, "next_page" => <Number> }}
paginate
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-paginate-1.1.0/lib/jekyll-paginate/pagination.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-paginate-1.1.0/lib/jekyll-paginate/pagination.rb
Apache-2.0
def template_page(site) site.pages.dup.select do |page| Pager.pagination_candidate?(site.config, page) end.sort do |one, two| two.path.size <=> one.path.size end.first end
Public: Find the Jekyll::Page which will act as the pager template site - the Jekyll::Site object Returns the Jekyll::Page which will act as the pager template
template_page
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-paginate-1.1.0/lib/jekyll-paginate/pagination.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-paginate-1.1.0/lib/jekyll-paginate/pagination.rb
Apache-2.0
def to_page page = Jekyll::Page.new(@site, @base, @dir, @name) page.data["permalink"] = File.dirname(url) + "/" page end
Convert this static file to a Page
to_page
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-readme-index-0.3.0/lib/jekyll/static_file_ext.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-readme-index-0.3.0/lib/jekyll/static_file_ext.rb
Apache-2.0
def readmes site.static_files.select { |file| file.relative_path =~ readme_regex } end
Returns an array of all READMEs as StaticFiles
readmes
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-readme-index-0.3.0/lib/jekyll-readme-index/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-readme-index-0.3.0/lib/jekyll-readme-index/generator.rb
Apache-2.0
def should_be_index?(readme) return false unless readme !dir_has_index? File.dirname(readme.url) end
Should the given readme be the containing directory's index?
should_be_index?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-readme-index-0.3.0/lib/jekyll-readme-index/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-readme-index-0.3.0/lib/jekyll-readme-index/generator.rb
Apache-2.0
def dir_has_index?(relative_path) relative_path << "/" unless relative_path.end_with? "/" regex = %r!^#{Regexp.escape(relative_path)}#{INDEX_REGEX}!i (site.pages + site.static_files).any? { |file| file.url =~ regex } end
Does the given directory have an index? relative_path - the directory path relative to the site root
dir_has_index?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-readme-index-0.3.0/lib/jekyll-readme-index/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-readme-index-0.3.0/lib/jekyll-readme-index/generator.rb
Apache-2.0
def readme_regex @readme_regex ||= %r!/readme(#{Regexp.union(markdown_converter.extname_list)})$!i end
Regexp to match a file path against to detect if the given file is a README
readme_regex
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-readme-index-0.3.0/lib/jekyll-readme-index/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-readme-index-0.3.0/lib/jekyll-readme-index/generator.rb
Apache-2.0
def generate_redirect_from(doc) doc.redirect_from.each do |path| page = RedirectPage.redirect_from(doc, path) doc.site.pages << page redirects[page.redirect_from] = page.redirect_to end end
For every `redirect_from` entry, generate a redirect page
generate_redirect_from
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/generator.rb
Apache-2.0
def redirect_to if to_liquid["redirect_to"].is_a?(Array) to_liquid["redirect_to"].compact.first else to_liquid["redirect_to"] end end
Returns a string representing the relative path or URL to which the document should be redirected
redirect_to
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/redirectable.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/redirectable.rb
Apache-2.0
def redirect_from if to_liquid["redirect_from"].is_a?(Array) to_liquid["redirect_from"].compact else [to_liquid["redirect_from"]].compact end end
Returns an array representing the relative paths to other documents which should be redirected to this document
redirect_from
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/redirectable.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/redirectable.rb
Apache-2.0
def read_yaml(_base, _name, _opts = {}) self.content = self.output = "" self.data ||= DEFAULT_DATA.dup end
Overwrite the default read_yaml method since the file doesn't exist
read_yaml
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/redirect_page.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/redirect_page.rb
Apache-2.0
def set_paths(from, to) @context ||= context from = ensure_leading_slash(from) data.merge!( "permalink" => from, "redirect" => { "from" => from, "to" => %r!^https?://!.match?(to) ? to : absolute_url(to), } ) end
Helper function to set the appropriate path metadata from - the relative path to the redirect page to - the relative path or absolute URL to the redirect target
set_paths
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/redirect_page.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/redirect_page.rb
Apache-2.0
def zip_url @zip_url ||= Addressable::URI.new( :scheme => theme.scheme, :host => "codeload.#{theme.host}", :path => [theme.owner, theme.name, "zip", theme.git_ref].join("/") ).normalize end
Full URL to codeload zip download endpoint for the given theme
zip_url
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-remote-theme-0.4.3/lib/jekyll-remote-theme/downloader.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-remote-theme-0.4.3/lib/jekyll-remote-theme/downloader.rb
Apache-2.0
def path_without_name_and_ref(path) Jekyll.sanitized_path theme.root, path.split("/").drop(1).join("/") end
Codeload generated zip files contain a top level folder in the form of THEME_NAME-GIT_REF/. While requests for Git repos are case insensitive, the zip subfolder will respect the case in the repository's name, thus making it impossible to predict the true path to the theme. In case we're on a case-sensitive file system, strip the parent folder from all paths.
path_without_name_and_ref
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-remote-theme-0.4.3/lib/jekyll-remote-theme/downloader.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-remote-theme-0.4.3/lib/jekyll-remote-theme/downloader.rb
Apache-2.0
def initialize(raw_theme) @raw_theme = raw_theme.to_s.downcase.strip super(@raw_theme) end
Initializes a new Jekyll::RemoteTheme::Theme raw_theme can be in the form of: 1. owner/theme-name - a GitHub owner + theme-name string 2. owner/theme-name@git_ref - a GitHub owner + theme-name + Git ref string 3. http[s]://github.<yourEnterprise>.com/owner/theme-name - An enterprise GitHub instance + a GitHub owner + a theme-name string 4. http[s]://github.<yourEnterprise>.com/owner/theme-name@git_ref - An enterprise GitHub instance + a GitHub owner + a theme-name + Git ref string
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-remote-theme-0.4.3/lib/jekyll-remote-theme/theme.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-remote-theme-0.4.3/lib/jekyll-remote-theme/theme.rb
Apache-2.0
def initialize(page: nil, site: nil) raise ArgumentError unless page && site @mutations = {} @page = page @site = site end
Initialize a new AuthorDrop page - The page hash (e.g., Page#to_liquid) site - The Jekyll::Drops::SiteDrop
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/author_drop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/author_drop.rb
Apache-2.0
def resolved_author return @resolved_author if defined? @resolved_author sources = [page["author"]] sources << page["authors"].first if page["authors"].is_a?(Array) sources << site["author"] @resolved_author = sources.find { |s| !s.to_s.empty? } end
Finds the page author in the page.author, page.authors, or site.author Returns a string or hash representing the author
resolved_author
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/author_drop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/author_drop.rb
Apache-2.0
def site_data_hash @site_data_hash ||= begin return {} unless resolved_author.is_a?(String) return {} unless site.data["authors"].is_a?(Hash) author_hash = site.data["authors"][resolved_author] author_hash.is_a?(Hash) ? author_hash : {} end end
If resolved_author is a string, attempts to find coresponding author metadata in `site.data.authors` Returns a hash representing additional metadata or an empty hash
site_data_hash
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/author_drop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/author_drop.rb
Apache-2.0
def author_hash @author_hash ||= begin case resolved_author when Hash resolved_author when String { "name" => resolved_author }.merge!(site_data_hash) else {} end end end
Returns the normalized author hash representing the page author, including site-wide metadata if the author is provided as a string, or an empty hash, if the author cannot be resolved
author_hash
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/author_drop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/author_drop.rb
Apache-2.0
def title? return false unless title return @display_title if defined?(@display_title) @display_title = (@text !~ %r!title=false!i) end
Should the `<title>` tag be generated for this page?
title?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/drop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/drop.rb
Apache-2.0
def page_title @page_title ||= format_string(page["title"]) || site_title end
Page title without site title or description appended
page_title
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/drop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/drop.rb
Apache-2.0
def title @title ||= begin if site_title && page_title != site_title page_title + TITLE_SEPARATOR + site_title elsif site_description && site_title site_title + TITLE_SEPARATOR + site_tagline_or_description else page_title || site_title end end return page_number + @title if page_number @title end
Page title with site title or description appended rubocop:disable Metrics/CyclomaticComplexity
title
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/drop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/drop.rb
Apache-2.0
def json_ld @json_ld ||= JSONLDDrop.new(self) end
A drop representing the JSON-LD output
json_ld
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/drop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/drop.rb
Apache-2.0
def image @image ||= ImageDrop.new(:page => page, :context => @context) @image if @image.path end
Returns a Drop representing the page's image Returns nil if the image has no path, to preserve backwards compatability
image
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/drop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/drop.rb
Apache-2.0
def sub_hash(hash, key) if hash[key].is_a?(Hash) hash[key] else EMPTY_READ_ONLY_HASH end end
Safely returns a sub hash hash - the parent hash key - the key in the parent hash Returns the sub hash or an empty hash, if it does not exist
sub_hash
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/drop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/drop.rb
Apache-2.0
def initialize(page: nil, context: nil) raise ArgumentError unless page && context @mutations = {} @page = page @context = context end
Initialize a new ImageDrop page - The page hash (e.g., Page#to_liquid) context - the Liquid::Context
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/image_drop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/image_drop.rb
Apache-2.0
def path @path ||= filters.uri_escape(absolute_url) if absolute_url end
Called path for backwards compatability, this is really the escaped, absolute URL representing the page's image Returns nil if no image path can be determined
path
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/image_drop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/image_drop.rb
Apache-2.0
def image_hash @image_hash ||= begin image_meta = page["image"] case image_meta when Hash { "path" => nil }.merge!(image_meta) when String { "path" => image_meta } else { "path" => nil } end end end
The normalized image hash with a `path` key (which may be nil)
image_hash
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/image_drop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/image_drop.rb
Apache-2.0
def json_ld Jekyll.logger.warn "Jekyll::SeoTag::JSONLD is deprecated" @json_ld ||= JSONLDDrop.new(self) end
Self should be a Jekyll::SeoTag::Drop instance (when extending the module)
json_ld
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/json_ld.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/json_ld.rb
Apache-2.0
def initialize(page_drop) @mutations = {} @page_drop = page_drop end
page_drop should be an instance of Jekyll::SeoTag::Drop
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/json_ld_drop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/json_ld_drop.rb
Apache-2.0
def to_json(state = nil) keys.sort.each_with_object({}) do |(key, _), result| v = self[key] result[key] = v unless v.nil? end.to_json(state) end
Returns a JSON-encoded object containing the JSON-LD data. Keys are sorted.
to_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/json_ld_drop.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/json_ld_drop.rb
Apache-2.0
def absolute_url?(string) return unless string Addressable::URI.parse(string).absolute? rescue Addressable::URI::InvalidURIError nil end
Determines if the given string is an absolute URL Returns true if an absolute URL Returns false if it's a relative URL Returns nil if it is not a string or can't be parsed as a URL
absolute_url?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/url_helper.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-seo-tag-2.8.0/lib/jekyll-seo-tag/url_helper.rb
Apache-2.0
def generate(site) @site = site @site.pages << sitemap unless file_exists?("sitemap.xml") @site.pages << robots unless file_exists?("robots.txt") end
Main plugin action, called by Jekyll-core
generate
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-sitemap-1.4.0/lib/jekyll/jekyll-sitemap.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-sitemap-1.4.0/lib/jekyll/jekyll-sitemap.rb
Apache-2.0
def static_files @site.static_files.select { |file| INCLUDED_EXTENSIONS.include? file.extname } end
Array of all non-jekyll site files with an HTML extension
static_files
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-sitemap-1.4.0/lib/jekyll/jekyll-sitemap.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-sitemap-1.4.0/lib/jekyll/jekyll-sitemap.rb
Apache-2.0
def source_path(file = "sitemap.xml") File.expand_path "../#{file}", __dir__ end
Path to sitemap.xml template file
source_path
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-sitemap-1.4.0/lib/jekyll/jekyll-sitemap.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-sitemap-1.4.0/lib/jekyll/jekyll-sitemap.rb
Apache-2.0
def file_exists?(file_path) pages_and_files.any? { |p| p.url == "/#{file_path}" } end
Checks if a file already exists in the site source
file_exists?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-sitemap-1.4.0/lib/jekyll/jekyll-sitemap.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-sitemap-1.4.0/lib/jekyll/jekyll-sitemap.rb
Apache-2.0
def watch(options, site = nil) ENV["LISTEN_GEM_DEBUGGING"] ||= "1" if options["verbose"] site ||= Jekyll::Site.new(options) listener = build_listener(site, options) listener.start Jekyll.logger.info "Auto-regeneration:", "enabled for '#{options["source"]}'" unless options["serving"] trap("INT") do listener.stop Jekyll.logger.info "", "Halting auto-regeneration." exit 0 end sleep_forever end rescue ThreadError # You pressed Ctrl-C, oh my! end
Public: Continuously watch for file changes and rebuild the site whenever a change is detected. If the optional site argument is populated, that site instance will be reused and the options Hash ignored. Otherwise, a new site instance will be instantiated from the options Hash and used. options - A Hash containing the site configuration site - The current site instance (populated starting with Jekyll 3.2) (optional, default: nil) Returns nothing.
watch
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-watch-2.2.1/lib/jekyll/watcher.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-watch-2.2.1/lib/jekyll/watcher.rb
Apache-2.0
def listen_ignore_paths(options) source = Pathname.new(options["source"]).expand_path paths = to_exclude(options) paths.map do |p| absolute_path = Pathname.new(normalize_encoding(p, options["source"].encoding)).expand_path next unless absolute_path.exist? begin relative_path = absolute_path.relative_path_from(source).to_s relative_path = File.join(relative_path, "") if absolute_path.directory? unless relative_path.start_with?("../") path_to_ignore = %r!^#{Regexp.escape(relative_path)}! Jekyll.logger.debug "Watcher:", "Ignoring #{path_to_ignore}" path_to_ignore end rescue ArgumentError # Could not find a relative path end end.compact + [%r!^\.jekyll\-metadata!] end
Paths to ignore for the watch option options - A Hash of options passed to the command Returns a list of relative paths from source that should be ignored
listen_ignore_paths
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-watch-2.2.1/lib/jekyll/watcher.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-watch-2.2.1/lib/jekyll/watcher.rb
Apache-2.0
def process(options) Jekyll.logger.log_level = :error if options["quiet"] Jekyll::Watcher.watch(options) if options["watch"] end
Build your jekyll site Continuously watch if `watch` is set to true in the config.
process
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jekyll-watch-2.2.1/lib/jekyll/commands/watch.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jekyll-watch-2.2.1/lib/jekyll/commands/watch.rb
Apache-2.0
def filter_with_emoji(src) filters[src] ||= HTML::Pipeline.new([ HTML::Pipeline::EmojiFilter, ], :asset_root => src, :img_attrs => { :align => nil }) end
Public: Create or fetch the filter for the given {{src}} asset root. src - the asset root URL (e.g. https://github.githubassets.com/images/icons/) Returns an HTML::Pipeline instance for the given asset root.
filter_with_emoji
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jemoji-0.12.0/lib/jemoji.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jemoji-0.12.0/lib/jemoji.rb
Apache-2.0
def filters @filters ||= {} end
Public: Filters hash where the key is the asset root source. Effectively a cache.
filters
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jemoji-0.12.0/lib/jemoji.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jemoji-0.12.0/lib/jemoji.rb
Apache-2.0
def emoji_src(config = {}) if config.key?("emoji") && config["emoji"].key?("src") config["emoji"]["src"] else default_asset_root end end
Public: Calculate the asset root source for the given config. The custom emoji asset root can be defined in the config as emoji.src, and must be a valid URL (i.e. it must include a protocol and valid domain) config - the hash-like configuration of the document's site Returns a full URL to use as the asset root URL. Defaults to the root URL for assets provided by an ASSET_HOST_URL environment variable, otherwise the root URL for emoji assets at assets-cdn.github.com.
emoji_src
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jemoji-0.12.0/lib/jemoji.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jemoji-0.12.0/lib/jemoji.rb
Apache-2.0
def emojiable?(doc) (doc.is_a?(Jekyll::Page) || doc.write?) && doc.output_ext == ".html" || (doc.permalink&.end_with?("/")) end
Public: Defines the conditions for a document to be emojiable. doc - the Jekyll::Document or Jekyll::Page Returns true if the doc is written & is HTML.
emojiable?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/jemoji-0.12.0/lib/jemoji.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/jemoji-0.12.0/lib/jemoji.rb
Apache-2.0
def deep_const_get(path) # :nodoc: path.to_s.split(/::/).inject(Object) do |p, c| case when c.empty? then p when p.const_defined?(c, true) then p.const_get(c) else begin p.const_missing(c) rescue NameError => e raise ArgumentError, "can't get const #{path}: #{e}" end end end end
Return the constant located at _path_. The format of _path_ has to be either ::A::B::C or A::B::C. In any case, A has to be located at the top level (absolute namespace path?). If there doesn't exist a constant at the given path, an ArgumentError is raised.
deep_const_get
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
Apache-2.0
def parse(source, opts = {}) Parser.new(source, **(opts||{})).parse end
:call-seq: JSON.parse(source, opts) -> object Returns the Ruby objects created by parsing the given +source+. Argument +source+ contains the \String to be parsed. Argument +opts+, if given, contains a \Hash of options for the parsing. See {Parsing Options}[#module-JSON-label-Parsing+Options]. --- When +source+ is a \JSON array, returns a Ruby \Array: source = '["foo", 1.0, true, false, null]' ruby = JSON.parse(source) ruby # => ["foo", 1.0, true, false, nil] ruby.class # => Array When +source+ is a \JSON object, returns a Ruby \Hash: source = '{"a": "foo", "b": 1.0, "c": true, "d": false, "e": null}' ruby = JSON.parse(source) ruby # => {"a"=>"foo", "b"=>1.0, "c"=>true, "d"=>false, "e"=>nil} ruby.class # => Hash For examples of parsing for all \JSON data types, see {Parsing \JSON}[#module-JSON-label-Parsing+JSON]. Parses nested JSON objects: source = <<-EOT { "name": "Dave", "age" :40, "hats": [ "Cattleman's", "Panama", "Tophat" ] } EOT ruby = JSON.parse(source) ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]} --- Raises an exception if +source+ is not valid JSON: # Raises JSON::ParserError (783: unexpected token at ''): JSON.parse('')
parse
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
Apache-2.0
def parse!(source, opts = {}) opts = { :max_nesting => false, :allow_nan => true }.merge(opts) Parser.new(source, **(opts||{})).parse end
:call-seq: JSON.parse!(source, opts) -> object Calls parse(source, opts) with +source+ and possibly modified +opts+. Differences from JSON.parse: - Option +max_nesting+, if not provided, defaults to +false+, which disables checking for nesting depth. - Option +allow_nan+, if not provided, defaults to +true+.
parse!
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
Apache-2.0
def load_file(filespec, opts = {}) parse(File.read(filespec), opts) end
:call-seq: JSON.load_file(path, opts={}) -> object Calls: parse(File.read(path), opts) See method #parse.
load_file
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
Apache-2.0
def load_file!(filespec, opts = {}) parse!(File.read(filespec), opts) end
:call-seq: JSON.load_file!(path, opts = {}) Calls: JSON.parse!(File.read(path, opts)) See method #parse!
load_file!
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
Apache-2.0
def generate(obj, opts = nil) if State === opts state, opts = opts, nil else state = State.new end if opts if opts.respond_to? :to_hash opts = opts.to_hash elsif opts.respond_to? :to_h opts = opts.to_h else raise TypeError, "can't convert #{opts.class} into Hash" end state = state.configure(opts) end state.generate(obj) end
:call-seq: JSON.generate(obj, opts = nil) -> new_string Returns a \String containing the generated \JSON data. See also JSON.fast_generate, JSON.pretty_generate. Argument +obj+ is the Ruby object to be converted to \JSON. Argument +opts+, if given, contains a \Hash of options for the generation. See {Generating Options}[#module-JSON-label-Generating+Options]. --- When +obj+ is an \Array, returns a \String containing a \JSON array: obj = ["foo", 1.0, true, false, nil] json = JSON.generate(obj) json # => '["foo",1.0,true,false,null]' When +obj+ is a \Hash, returns a \String containing a \JSON object: obj = {foo: 0, bar: 's', baz: :bat} json = JSON.generate(obj) json # => '{"foo":0,"bar":"s","baz":"bat"}' For examples of generating from other Ruby objects, see {Generating \JSON from Other Objects}[#module-JSON-label-Generating+JSON+from+Other+Objects]. --- Raises an exception if any formatting option is not a \String. Raises an exception if +obj+ contains circular references: a = []; b = []; a.push(b); b.push(a) # Raises JSON::NestingError (nesting of 100 is too deep): JSON.generate(a)
generate
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
Apache-2.0
def fast_generate(obj, opts = nil) if State === opts state, opts = opts, nil else state = JSON.create_fast_state end if opts if opts.respond_to? :to_hash opts = opts.to_hash elsif opts.respond_to? :to_h opts = opts.to_h else raise TypeError, "can't convert #{opts.class} into Hash" end state.configure(opts) end state.generate(obj) end
:startdoc: :call-seq: JSON.fast_generate(obj, opts) -> new_string Arguments +obj+ and +opts+ here are the same as arguments +obj+ and +opts+ in JSON.generate. By default, generates \JSON data without checking for circular references in +obj+ (option +max_nesting+ set to +false+, disabled). Raises an exception if +obj+ contains circular references: a = []; b = []; a.push(b); b.push(a) # Raises SystemStackError (stack level too deep): JSON.fast_generate(a)
fast_generate
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
Apache-2.0
def pretty_generate(obj, opts = nil) if State === opts state, opts = opts, nil else state = JSON.create_pretty_state end if opts if opts.respond_to? :to_hash opts = opts.to_hash elsif opts.respond_to? :to_h opts = opts.to_h else raise TypeError, "can't convert #{opts.class} into Hash" end state.configure(opts) end state.generate(obj) end
:startdoc: :call-seq: JSON.pretty_generate(obj, opts = nil) -> new_string Arguments +obj+ and +opts+ here are the same as arguments +obj+ and +opts+ in JSON.generate. Default options are: { indent: ' ', # Two spaces space: ' ', # One space array_nl: "\n", # Newline object_nl: "\n" # Newline } Example: obj = {foo: [:bar, :baz], bat: {bam: 0, bad: 1}} json = JSON.pretty_generate(obj) puts json Output: { "foo": [ "bar", "baz" ], "bat": { "bam": 0, "bad": 1 } }
pretty_generate
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
Apache-2.0
def load(source, proc = nil, options = {}) opts = load_default_options.merge options if source.respond_to? :to_str source = source.to_str elsif source.respond_to? :to_io source = source.to_io.read elsif source.respond_to?(:read) source = source.read end if opts[:allow_blank] && (source.nil? || source.empty?) source = 'null' end result = parse(source, opts) recurse_proc(result, &proc) if proc result end
:call-seq: JSON.load(source, proc = nil, options = {}) -> object Returns the Ruby objects created by parsing the given +source+. - Argument +source+ must be, or be convertible to, a \String: - If +source+ responds to instance method +to_str+, <tt>source.to_str</tt> becomes the source. - If +source+ responds to instance method +to_io+, <tt>source.to_io.read</tt> becomes the source. - If +source+ responds to instance method +read+, <tt>source.read</tt> becomes the source. - If both of the following are true, source becomes the \String <tt>'null'</tt>: - Option +allow_blank+ specifies a truthy value. - The source, as defined above, is +nil+ or the empty \String <tt>''</tt>. - Otherwise, +source+ remains the source. - Argument +proc+, if given, must be a \Proc that accepts one argument. It will be called recursively with each result (depth-first order). See details below. BEWARE: This method is meant to serialise data from trusted user input, like from your own database server or clients under your control, it could be dangerous to allow untrusted users to pass JSON sources into it. - Argument +opts+, if given, contains a \Hash of options for the parsing. See {Parsing Options}[#module-JSON-label-Parsing+Options]. The default options can be changed via method JSON.load_default_options=. --- When no +proc+ is given, modifies +source+ as above and returns the result of <tt>parse(source, opts)</tt>; see #parse. Source for following examples: source = <<-EOT { "name": "Dave", "age" :40, "hats": [ "Cattleman's", "Panama", "Tophat" ] } EOT Load a \String: ruby = JSON.load(source) ruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]} Load an \IO object: require 'stringio' object = JSON.load(StringIO.new(source)) object # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]} Load a \File object: path = 't.json' File.write(path, source) File.open(path) do |file| JSON.load(file) end # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]} --- When +proc+ is given: - Modifies +source+ as above. - Gets the +result+ from calling <tt>parse(source, opts)</tt>. - Recursively calls <tt>proc(result)</tt>. - Returns the final result. Example: require 'json' # Some classes for the example. class Base def initialize(attributes) @attributes = attributes end end class User < Base; end class Account < Base; end class Admin < Base; end # The JSON source. json = <<-EOF { "users": [ {"type": "User", "username": "jane", "email": "[email protected]"}, {"type": "User", "username": "john", "email": "[email protected]"} ], "accounts": [ {"account": {"type": "Account", "paid": true, "account_id": "1234"}}, {"account": {"type": "Account", "paid": false, "account_id": "1235"}} ], "admins": {"type": "Admin", "password": "0wn3d"} } EOF # Deserializer method. def deserialize_obj(obj, safe_types = %w(User Account Admin)) type = obj.is_a?(Hash) && obj["type"] safe_types.include?(type) ? Object.const_get(type).new(obj) : obj end # Call to JSON.load ruby = JSON.load(json, proc {|obj| case obj when Hash obj.each {|k, v| obj[k] = deserialize_obj v } when Array obj.map! {|v| deserialize_obj v } end }) pp ruby Output: {"users"=> [#<User:0x00000000064c4c98 @attributes= {"type"=>"User", "username"=>"jane", "email"=>"[email protected]"}>, #<User:0x00000000064c4bd0 @attributes= {"type"=>"User", "username"=>"john", "email"=>"[email protected]"}>], "accounts"=> [{"account"=> #<Account:0x00000000064c4928 @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>}, {"account"=> #<Account:0x00000000064c4680 @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}], "admins"=> #<Admin:0x00000000064c41f8 @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
load
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
Apache-2.0
def recurse_proc(result, &proc) # :nodoc: case result when Array result.each { |x| recurse_proc x, &proc } proc.call result when Hash result.each { |x, y| recurse_proc x, &proc; recurse_proc y, &proc } proc.call result else proc.call result end end
Recursively calls passed _Proc_ if the parsed data structure is an _Array_ or _Hash_
recurse_proc
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
Apache-2.0
def j(*objs) objs.each do |obj| puts JSON::generate(obj, :allow_nan => true, :max_nesting => false) end nil end
Outputs _objs_ to STDOUT as JSON strings in the shortest form, that is in one line.
j
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
Apache-2.0
def jj(*objs) objs.each do |obj| puts JSON::pretty_generate(obj, :allow_nan => true, :max_nesting => false) end nil end
Outputs _objs_ to STDOUT as JSON strings in a pretty format, with indentation and over many lines.
jj
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/common.rb
Apache-2.0
def as_json(*) { JSON.create_id => self.class.name, 'b' => _dump, } end
Marshal the object to JSON. method used for JSON marshalling support.
as_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/bigdecimal.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/bigdecimal.rb
Apache-2.0
def as_json(*) { JSON.create_id => self.class.name, 'r' => real, 'i' => imag, } end
Returns a hash, that will be turned into a JSON object and represent this object.
as_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/complex.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/complex.rb
Apache-2.0
def as_json(*) { JSON.create_id => self.class.name, 'y' => year, 'm' => month, 'd' => day, 'sg' => start, } end
Returns a hash, that will be turned into a JSON object and represent this object.
as_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/date.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/date.rb
Apache-2.0
def as_json(*) { JSON.create_id => self.class.name, 'y' => year, 'm' => month, 'd' => day, 'H' => hour, 'M' => min, 'S' => sec, 'of' => offset.to_s, 'sg' => start, } end
Returns a hash, that will be turned into a JSON object and represent this object.
as_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/date_time.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/date_time.rb
Apache-2.0
def as_json(*) { JSON.create_id => self.class.name, 'm' => message, 'b' => backtrace, } end
Returns a hash, that will be turned into a JSON object and represent this object.
as_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/exception.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/exception.rb
Apache-2.0
def as_json(*) klass = self.class.name klass.to_s.empty? and raise JSON::JSONError, "Only named structs are supported!" { JSON.create_id => klass, 't' => table, } end
Returns a hash, that will be turned into a JSON object and represent this object.
as_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/ostruct.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/ostruct.rb
Apache-2.0
def as_json(*) { JSON.create_id => self.class.name, 'a' => [ first, last, exclude_end? ] } end
Returns a hash, that will be turned into a JSON object and represent this object.
as_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/range.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/range.rb
Apache-2.0
def as_json(*) { JSON.create_id => self.class.name, 'n' => numerator, 'd' => denominator, } end
Returns a hash, that will be turned into a JSON object and represent this object.
as_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/rational.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/rational.rb
Apache-2.0
def as_json(*) { JSON.create_id => self.class.name, 'o' => options, 's' => source, } end
Returns a hash, that will be turned into a JSON object and represent this object.
as_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/regexp.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/regexp.rb
Apache-2.0
def as_json(*) { JSON.create_id => self.class.name, 'a' => to_a, } end
Marshal the object to JSON. method used for JSON marshalling support.
as_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/set.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/set.rb
Apache-2.0
def as_json(*) klass = self.class.name klass.to_s.empty? and raise JSON::JSONError, "Only named structs are supported!" { JSON.create_id => klass, 'v' => values, } end
Returns a hash, that will be turned into a JSON object and represent this object.
as_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/struct.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/struct.rb
Apache-2.0
def as_json(*) { JSON.create_id => self.class.name, 's' => to_s, } end
Returns a hash, that will be turned into a JSON object and represent this object.
as_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/symbol.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/symbol.rb
Apache-2.0
def as_json(*) nanoseconds = [ tv_usec * 1000 ] respond_to?(:tv_nsec) and nanoseconds << tv_nsec nanoseconds = nanoseconds.max { JSON.create_id => self.class.name, 's' => tv_sec, 'n' => nanoseconds, } end
Returns a hash, that will be turned into a JSON object and represent this object.
as_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/time.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/add/time.rb
Apache-2.0
def utf8_to_json(string, escape_slash = false) # :nodoc: string = string.dup string.force_encoding(::Encoding::ASCII_8BIT) map = escape_slash ? ESCAPE_SLASH_MAP : MAP string.gsub!(/[\/"\\\x0-\x1f]/) { map[$&] || $& } string.force_encoding(::Encoding::UTF_8) string end
Convert a UTF8 encoded Ruby string _string_ to a JSON string, encoded with UTF16 big endian characters as \u????, and return it.
utf8_to_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/generator.rb
Apache-2.0
def configure(opts) if opts.respond_to?(:to_hash) opts = opts.to_hash elsif opts.respond_to?(:to_h) opts = opts.to_h else raise TypeError, "can't convert #{opts.class} into Hash" end for key, value in opts instance_variable_set "@#{key}", value end @indent = opts[:indent] if opts.key?(:indent) @space = opts[:space] if opts.key?(:space) @space_before = opts[:space_before] if opts.key?(:space_before) @object_nl = opts[:object_nl] if opts.key?(:object_nl) @array_nl = opts[:array_nl] if opts.key?(:array_nl) @allow_nan = !!opts[:allow_nan] if opts.key?(:allow_nan) @ascii_only = opts[:ascii_only] if opts.key?(:ascii_only) @depth = opts[:depth] || 0 @buffer_initial_length ||= opts[:buffer_initial_length] @escape_slash = !!opts[:escape_slash] if opts.key?(:escape_slash) if !opts.key?(:max_nesting) # defaults to 100 @max_nesting = 100 elsif opts[:max_nesting] @max_nesting = opts[:max_nesting] else @max_nesting = 0 end self end
Configure this State instance with the Hash _opts_, and return itself.
configure
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/generator.rb
Apache-2.0
def to_h result = {} for iv in instance_variables iv = iv.to_s[1..-1] result[iv.to_sym] = self[iv] end result end
Returns the configuration instance variables as a hash, that can be passed to the configure method.
to_h
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/generator.rb
Apache-2.0
def generate(obj) result = obj.to_json(self) JSON.valid_utf8?(result) or raise GeneratorError, "source sequence #{result.inspect} is illegal/malformed utf-8" result end
Generates a valid JSON document from object +obj+ and returns the result. If no valid JSON document can be created this method raises a GeneratorError exception.
generate
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/generator.rb
Apache-2.0
def to_json(state = nil, *) state = State.from_state(state) state.check_max_nesting json_transform(state) end
Returns a JSON string containing a JSON object, that is unparsed from this Hash instance. _state_ is a JSON::State object, that can also be used to configure the produced JSON string output further. _depth_ is used to find out nesting depth, to indent accordingly.
to_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/generator.rb
Apache-2.0
def to_json(state = nil, *) state = State.from_state(state) state.check_max_nesting json_transform(state) end
Returns a JSON string containing a JSON array, that is unparsed from this Array instance. _state_ is a JSON::State object, that can also be used to configure the produced JSON string output further.
to_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/generator.rb
Apache-2.0
def to_json(state = nil, *) state = State.from_state(state) case when infinite? if state.allow_nan? to_s else raise GeneratorError, "#{self} not allowed in JSON" end when nan? if state.allow_nan? to_s else raise GeneratorError, "#{self} not allowed in JSON" end else to_s end end
Returns a JSON string representation for this Float number.
to_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/generator.rb
Apache-2.0
def to_json(state = nil, *args) state = State.from_state(state) if encoding == ::Encoding::UTF_8 string = self else string = encode(::Encoding::UTF_8) end if state.ascii_only? '"' << JSON.utf8_to_json_ascii(string, state.escape_slash) << '"' else '"' << JSON.utf8_to_json(string, state.escape_slash) << '"' end end
This string should be encoded with UTF-8 A call to this method returns a JSON string encoded with UTF16 big endian characters as \u????.
to_json
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/generator.rb
Apache-2.0
def to_json_raw_object { JSON.create_id => self.class.name, 'raw' => self.unpack('C*'), } end
This method creates a raw object hash, that can be nested into other data structures and will be unparsed as a raw string. This method should be used, if you want to convert raw strings to JSON instead of UTF-8 strings, e. g. binary data.
to_json_raw_object
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/generator.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/generator.rb
Apache-2.0
def initialize(source, opts = {}) opts ||= {} source = convert_encoding source super source if !opts.key?(:max_nesting) # defaults to 100 @max_nesting = 100 elsif opts[:max_nesting] @max_nesting = opts[:max_nesting] else @max_nesting = 0 end @allow_nan = !!opts[:allow_nan] @symbolize_names = !!opts[:symbolize_names] @freeze = !!opts[:freeze] if opts.key?(:create_additions) @create_additions = !!opts[:create_additions] else @create_additions = false end @symbolize_names && @create_additions and raise ArgumentError, 'options :symbolize_names and :create_additions cannot be used '\ 'in conjunction' @create_id = @create_additions ? JSON.create_id : nil @object_class = opts[:object_class] || Hash @array_class = opts[:array_class] || Array @decimal_class = opts[:decimal_class] @match_string = opts[:match_string] end
Creates a new JSON::Pure::Parser instance for the string _source_. It will be configured by the _opts_ hash. _opts_ can have the following keys: * *max_nesting*: The maximum depth of nesting allowed in the parsed data structures. Disable depth checking with :max_nesting => false|nil|0, it defaults to 100. * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in defiance of RFC 7159 to be parsed by the Parser. This option defaults to false. * *freeze*: If set to true, all parsed objects will be frozen. Parsed string will be deduplicated if possible. * *symbolize_names*: If set to true, returns symbols for the names (keys) in a JSON object. Otherwise strings are returned, which is also the default. It's not possible to use this option in conjunction with the *create_additions* option. * *create_additions*: If set to true, the Parser creates additions when a matching class and create_id are found. This option defaults to false. * *object_class*: Defaults to Hash * *array_class*: Defaults to Array * *decimal_class*: Specifies which class to use instead of the default (Float) when parsing decimal numbers. This class must accept a single string argument in its constructor.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/parser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/parser.rb
Apache-2.0
def parse reset obj = nil while !eos? && skip(IGNORE) do end if eos? raise ParserError, "source is not valid JSON!" else obj = parse_value UNPARSED.equal?(obj) and raise ParserError, "source is not valid JSON!" obj.freeze if @freeze end while !eos? && skip(IGNORE) do end eos? or raise ParserError, "source is not valid JSON!" obj end
Parses the current JSON string _source_ and returns the complete data structure as a result.
parse
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/parser.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/json-2.6.3/lib/json/pure/parser.rb
Apache-2.0
def initialize(source, options = {}) @options = Options.merge(options).freeze parser = (@options[:input] || 'kramdown').to_s parser = parser[0..0].upcase + parser[1..-1] try_require('parser', parser) if Parser.const_defined?(parser) @root, @warnings = Parser.const_get(parser).parse(source, @options) else raise Kramdown::Error, "kramdown has no parser to handle the specified " \ "input format: #{@options[:input]}" end end
Create a new Kramdown document from the string +source+ and use the provided +options+. The options that can be used are defined in the Options module. The special options key :input can be used to select the parser that should parse the +source+. It has to be the name of a class in the Kramdown::Parser module. For example, to select the kramdown parser, one would set the :input key to +Kramdown+. If this key is not set, it defaults to +Kramdown+. The +source+ is immediately parsed by the selected parser so that the root element is immediately available and the output can be generated.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/document.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/document.rb
Apache-2.0
def method_missing(id, *attr, &block) if id.to_s =~ /^to_(\w+)$/ && (name = Utils.camelize($1)) && try_require('converter', name) && Converter.const_defined?(name) output, warnings = Converter.const_get(name).convert(@root, @options) @warnings.concat(warnings) output else super end end
Check if a method is invoked that begins with +to_+ and if so, try to instantiate a converter class (i.e. a class in the Kramdown::Converter module) and use it for converting the document. For example, +to_html+ would instantiate the Kramdown::Converter::Html class.
method_missing
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/document.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/document.rb
Apache-2.0
def try_require(type, name) require("kramdown/#{type}/#{Utils.snake_case(name)}") true rescue LoadError true end
Try requiring a parser or converter class and don't raise an error if the file is not found.
try_require
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/document.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/document.rb
Apache-2.0
def initialize(type, value = nil, attr = nil, options = nil) @type, @value, @attr, @options = type, value, attr, options @children = [] end
Create a new Element object of type +type+. The optional parameters +value+, +attr+ and +options+ can also be set in this constructor for convenience.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/element.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/element.rb
Apache-2.0
def options @options ||= {} end
The options hash for the element. It is used for storing arbitray options.
options
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/element.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/element.rb
Apache-2.0
def block? (CATEGORY[type] || options[:category]) == :block end
syntactic sugar to simplify calls such as +Kramdown::Element.category(el) == :block+ with +el.block?+. Returns boolean true or false.
block?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/element.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/element.rb
Apache-2.0
def span? (CATEGORY[type] || options[:category]) == :span end
syntactic sugar to simplify calls such as +Kramdown::Element.category(el) == :span+ with +el.span?+. Returns boolean true or false.
span?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/element.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/element.rb
Apache-2.0
def initialize(root, options) @options = options @root = root @data = {} @warnings = [] end
Initialize the converter with the given +root+ element and +options+ hash.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/converter/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/converter/base.rb
Apache-2.0
def convert(_el) raise NotImplementedError end
Convert the element +el+ and return the resulting object. This is the only method that has to be implemented by sub-classes!
convert
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/converter/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/kramdown-2.3.2/lib/kramdown/converter/base.rb
Apache-2.0