id
int32 0
24.9k
| repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
list | docstring
stringlengths 8
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 94
266
|
|---|---|---|---|---|---|---|---|---|---|---|---|
10,800
|
decidim/decidim
|
decidim-core/app/helpers/decidim/newsletters_helper.rb
|
Decidim.NewslettersHelper.custom_url_for_mail_root
|
def custom_url_for_mail_root(organization, newsletter_id = nil)
if newsletter_id.present?
decidim.root_url(host: organization.host) + utm_codes(organization.host, newsletter_id.to_s)
else
decidim.root_url(host: organization.host)
end
end
|
ruby
|
def custom_url_for_mail_root(organization, newsletter_id = nil)
if newsletter_id.present?
decidim.root_url(host: organization.host) + utm_codes(organization.host, newsletter_id.to_s)
else
decidim.root_url(host: organization.host)
end
end
|
[
"def",
"custom_url_for_mail_root",
"(",
"organization",
",",
"newsletter_id",
"=",
"nil",
")",
"if",
"newsletter_id",
".",
"present?",
"decidim",
".",
"root_url",
"(",
"host",
":",
"organization",
".",
"host",
")",
"+",
"utm_codes",
"(",
"organization",
".",
"host",
",",
"newsletter_id",
".",
"to_s",
")",
"else",
"decidim",
".",
"root_url",
"(",
"host",
":",
"organization",
".",
"host",
")",
"end",
"end"
] |
this method is used to generate the root link on mail with the utm_codes
If the newsletter_id is nil, it returns the root_url
|
[
"this",
"method",
"is",
"used",
"to",
"generate",
"the",
"root",
"link",
"on",
"mail",
"with",
"the",
"utm_codes",
"If",
"the",
"newsletter_id",
"is",
"nil",
"it",
"returns",
"the",
"root_url"
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/newsletters_helper.rb#L35-L41
|
10,801
|
decidim/decidim
|
decidim-core/app/helpers/decidim/layout_helper.rb
|
Decidim.LayoutHelper.icon
|
def icon(name, options = {})
html_properties = {}
html_properties["width"] = options[:width]
html_properties["height"] = options[:height]
html_properties["aria-label"] = options[:aria_label]
html_properties["role"] = options[:role]
html_properties["aria-hidden"] = options[:aria_hidden]
html_properties["class"] = (["icon--#{name}"] + _icon_classes(options)).join(" ")
content_tag :svg, html_properties do
content_tag :use, nil, "xlink:href" => "#{asset_path("decidim/icons.svg")}#icon-#{name}"
end
end
|
ruby
|
def icon(name, options = {})
html_properties = {}
html_properties["width"] = options[:width]
html_properties["height"] = options[:height]
html_properties["aria-label"] = options[:aria_label]
html_properties["role"] = options[:role]
html_properties["aria-hidden"] = options[:aria_hidden]
html_properties["class"] = (["icon--#{name}"] + _icon_classes(options)).join(" ")
content_tag :svg, html_properties do
content_tag :use, nil, "xlink:href" => "#{asset_path("decidim/icons.svg")}#icon-#{name}"
end
end
|
[
"def",
"icon",
"(",
"name",
",",
"options",
"=",
"{",
"}",
")",
"html_properties",
"=",
"{",
"}",
"html_properties",
"[",
"\"width\"",
"]",
"=",
"options",
"[",
":width",
"]",
"html_properties",
"[",
"\"height\"",
"]",
"=",
"options",
"[",
":height",
"]",
"html_properties",
"[",
"\"aria-label\"",
"]",
"=",
"options",
"[",
":aria_label",
"]",
"html_properties",
"[",
"\"role\"",
"]",
"=",
"options",
"[",
":role",
"]",
"html_properties",
"[",
"\"aria-hidden\"",
"]",
"=",
"options",
"[",
":aria_hidden",
"]",
"html_properties",
"[",
"\"class\"",
"]",
"=",
"(",
"[",
"\"icon--#{name}\"",
"]",
"+",
"_icon_classes",
"(",
"options",
")",
")",
".",
"join",
"(",
"\" \"",
")",
"content_tag",
":svg",
",",
"html_properties",
"do",
"content_tag",
":use",
",",
"nil",
",",
"\"xlink:href\"",
"=>",
"\"#{asset_path(\"decidim/icons.svg\")}#icon-#{name}\"",
"end",
"end"
] |
Outputs an SVG-based icon.
name - The String with the icon name.
options - The Hash options used to customize the icon (default {}):
:width - The Number of width in pixels (optional).
:height - The Number of height in pixels (optional).
:aria_label - The String to set as aria label (optional).
:aria_hidden - The Truthy value to enable aria_hidden (optional).
:role - The String to set as the role (optional).
:class - The String to add as a CSS class (optional).
Returns a String.
|
[
"Outputs",
"an",
"SVG",
"-",
"based",
"icon",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/layout_helper.rb#L30-L44
|
10,802
|
decidim/decidim
|
decidim-core/app/helpers/decidim/layout_helper.rb
|
Decidim.LayoutHelper.external_icon
|
def external_icon(path, options = {})
classes = _icon_classes(options) + ["external-icon"]
if path.split(".").last == "svg"
asset = Rails.application.assets_manifest.find_sources(path).first
asset.gsub("<svg ", "<svg class=\"#{classes.join(" ")}\" ").html_safe
else
image_tag(path, class: classes.join(" "), style: "display: none")
end
end
|
ruby
|
def external_icon(path, options = {})
classes = _icon_classes(options) + ["external-icon"]
if path.split(".").last == "svg"
asset = Rails.application.assets_manifest.find_sources(path).first
asset.gsub("<svg ", "<svg class=\"#{classes.join(" ")}\" ").html_safe
else
image_tag(path, class: classes.join(" "), style: "display: none")
end
end
|
[
"def",
"external_icon",
"(",
"path",
",",
"options",
"=",
"{",
"}",
")",
"classes",
"=",
"_icon_classes",
"(",
"options",
")",
"+",
"[",
"\"external-icon\"",
"]",
"if",
"path",
".",
"split",
"(",
"\".\"",
")",
".",
"last",
"==",
"\"svg\"",
"asset",
"=",
"Rails",
".",
"application",
".",
"assets_manifest",
".",
"find_sources",
"(",
"path",
")",
".",
"first",
"asset",
".",
"gsub",
"(",
"\"<svg \"",
",",
"\"<svg class=\\\"#{classes.join(\" \")}\\\" \"",
")",
".",
"html_safe",
"else",
"image_tag",
"(",
"path",
",",
"class",
":",
"classes",
".",
"join",
"(",
"\" \"",
")",
",",
"style",
":",
"\"display: none\"",
")",
"end",
"end"
] |
Outputs a SVG icon from an external file. It apparently renders an image
tag, but then a JS script kicks in and replaces it with an inlined SVG
version.
path - The asset's path
Returns an <img /> tag with the SVG icon.
|
[
"Outputs",
"a",
"SVG",
"icon",
"from",
"an",
"external",
"file",
".",
"It",
"apparently",
"renders",
"an",
"image",
"tag",
"but",
"then",
"a",
"JS",
"script",
"kicks",
"in",
"and",
"replaces",
"it",
"with",
"an",
"inlined",
"SVG",
"version",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/layout_helper.rb#L53-L62
|
10,803
|
decidim/decidim
|
decidim-core/app/services/decidim/continuity_badge_tracker.rb
|
Decidim.ContinuityBadgeTracker.track!
|
def track!(date)
@subject.with_lock do
last_session_at = status.try(:last_session_at) || date
current_streak = status.try(:current_streak) || 1
streak = if last_session_at == date
current_streak
elsif last_session_at == date - 1.day
current_streak + 1
else
1
end
update_status(date, streak)
update_badge(streak)
end
end
|
ruby
|
def track!(date)
@subject.with_lock do
last_session_at = status.try(:last_session_at) || date
current_streak = status.try(:current_streak) || 1
streak = if last_session_at == date
current_streak
elsif last_session_at == date - 1.day
current_streak + 1
else
1
end
update_status(date, streak)
update_badge(streak)
end
end
|
[
"def",
"track!",
"(",
"date",
")",
"@subject",
".",
"with_lock",
"do",
"last_session_at",
"=",
"status",
".",
"try",
"(",
":last_session_at",
")",
"||",
"date",
"current_streak",
"=",
"status",
".",
"try",
"(",
":current_streak",
")",
"||",
"1",
"streak",
"=",
"if",
"last_session_at",
"==",
"date",
"current_streak",
"elsif",
"last_session_at",
"==",
"date",
"-",
"1",
".",
"day",
"current_streak",
"+",
"1",
"else",
"1",
"end",
"update_status",
"(",
"date",
",",
"streak",
")",
"update_badge",
"(",
"streak",
")",
"end",
"end"
] |
Initializes the class with a polymorphic subject
subject - A in instance of a subclass of ActiveRecord::Base to be tracked
Public: Tracks the past activity of a user to update the continuity badge's
score. It will set it to the amount of consecutive days a user has logged into
the system.
date - The date of the last user's activity. Usually `Time.zone.today`.
Returns nothing.
|
[
"Initializes",
"the",
"class",
"with",
"a",
"polymorphic",
"subject"
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/services/decidim/continuity_badge_tracker.rb#L22-L38
|
10,804
|
decidim/decidim
|
decidim-core/app/mailers/decidim/decidim_devise_mailer.rb
|
Decidim.DecidimDeviseMailer.invitation_instructions
|
def invitation_instructions(user, token, opts = {})
with_user(user) do
@token = token
@organization = user.organization
@opts = opts
opts[:subject] = I18n.t("devise.mailer.#{opts[:invitation_instructions]}.subject", organization: user.organization.name) if opts[:invitation_instructions]
end
devise_mail(user, opts[:invitation_instructions] || :invitation_instructions, opts)
end
|
ruby
|
def invitation_instructions(user, token, opts = {})
with_user(user) do
@token = token
@organization = user.organization
@opts = opts
opts[:subject] = I18n.t("devise.mailer.#{opts[:invitation_instructions]}.subject", organization: user.organization.name) if opts[:invitation_instructions]
end
devise_mail(user, opts[:invitation_instructions] || :invitation_instructions, opts)
end
|
[
"def",
"invitation_instructions",
"(",
"user",
",",
"token",
",",
"opts",
"=",
"{",
"}",
")",
"with_user",
"(",
"user",
")",
"do",
"@token",
"=",
"token",
"@organization",
"=",
"user",
".",
"organization",
"@opts",
"=",
"opts",
"opts",
"[",
":subject",
"]",
"=",
"I18n",
".",
"t",
"(",
"\"devise.mailer.#{opts[:invitation_instructions]}.subject\"",
",",
"organization",
":",
"user",
".",
"organization",
".",
"name",
")",
"if",
"opts",
"[",
":invitation_instructions",
"]",
"end",
"devise_mail",
"(",
"user",
",",
"opts",
"[",
":invitation_instructions",
"]",
"||",
":invitation_instructions",
",",
"opts",
")",
"end"
] |
Sends an email with the invitation instructions to a new user.
user - The User that has been invited.
token - The String to be sent as a token to verify the invitation.
opts - A Hash with options to send the email (optional).
|
[
"Sends",
"an",
"email",
"with",
"the",
"invitation",
"instructions",
"to",
"a",
"new",
"user",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/mailers/decidim/decidim_devise_mailer.rb#L16-L26
|
10,805
|
decidim/decidim
|
decidim-core/app/cells/decidim/activities_cell.rb
|
Decidim.ActivitiesCell.show
|
def show
return if activities.blank?
activities.map do |activity|
activity.organization_lazy
activity.resource_lazy
activity.participatory_space_lazy
activity.component_lazy
end
render
end
|
ruby
|
def show
return if activities.blank?
activities.map do |activity|
activity.organization_lazy
activity.resource_lazy
activity.participatory_space_lazy
activity.component_lazy
end
render
end
|
[
"def",
"show",
"return",
"if",
"activities",
".",
"blank?",
"activities",
".",
"map",
"do",
"|",
"activity",
"|",
"activity",
".",
"organization_lazy",
"activity",
".",
"resource_lazy",
"activity",
".",
"participatory_space_lazy",
"activity",
".",
"component_lazy",
"end",
"render",
"end"
] |
Since we're rendering each activity separatedly we need to trigger
BatchLoader in order to accumulate all the ids to be found later.
|
[
"Since",
"we",
"re",
"rendering",
"each",
"activity",
"separatedly",
"we",
"need",
"to",
"trigger",
"BatchLoader",
"in",
"order",
"to",
"accumulate",
"all",
"the",
"ids",
"to",
"be",
"found",
"later",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/cells/decidim/activities_cell.rb#L13-L24
|
10,806
|
decidim/decidim
|
decidim-core/app/helpers/decidim/component_path_helper.rb
|
Decidim.ComponentPathHelper.main_component_path
|
def main_component_path(component)
current_params = try(:params) || {}
EngineRouter.main_proxy(component).root_path(locale: current_params[:locale])
end
|
ruby
|
def main_component_path(component)
current_params = try(:params) || {}
EngineRouter.main_proxy(component).root_path(locale: current_params[:locale])
end
|
[
"def",
"main_component_path",
"(",
"component",
")",
"current_params",
"=",
"try",
"(",
":params",
")",
"||",
"{",
"}",
"EngineRouter",
".",
"main_proxy",
"(",
"component",
")",
".",
"root_path",
"(",
"locale",
":",
"current_params",
"[",
":locale",
"]",
")",
"end"
] |
Returns the defined root path for a given component.
component - the Component we want to find the root path for.
Returns a relative url.
|
[
"Returns",
"the",
"defined",
"root",
"path",
"for",
"a",
"given",
"component",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/component_path_helper.rb#L11-L14
|
10,807
|
decidim/decidim
|
decidim-core/app/helpers/decidim/component_path_helper.rb
|
Decidim.ComponentPathHelper.main_component_url
|
def main_component_url(component)
current_params = try(:params) || {}
EngineRouter.main_proxy(component).root_url(locale: current_params[:locale])
end
|
ruby
|
def main_component_url(component)
current_params = try(:params) || {}
EngineRouter.main_proxy(component).root_url(locale: current_params[:locale])
end
|
[
"def",
"main_component_url",
"(",
"component",
")",
"current_params",
"=",
"try",
"(",
":params",
")",
"||",
"{",
"}",
"EngineRouter",
".",
"main_proxy",
"(",
"component",
")",
".",
"root_url",
"(",
"locale",
":",
"current_params",
"[",
":locale",
"]",
")",
"end"
] |
Returns the defined root url for a given component.
component - the Component we want to find the root path for.
Returns an absolute url.
|
[
"Returns",
"the",
"defined",
"root",
"url",
"for",
"a",
"given",
"component",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/component_path_helper.rb#L21-L24
|
10,808
|
decidim/decidim
|
decidim-core/app/helpers/decidim/component_path_helper.rb
|
Decidim.ComponentPathHelper.manage_component_path
|
def manage_component_path(component)
current_params = try(:params) || {}
EngineRouter.admin_proxy(component).root_path(locale: current_params[:locale])
end
|
ruby
|
def manage_component_path(component)
current_params = try(:params) || {}
EngineRouter.admin_proxy(component).root_path(locale: current_params[:locale])
end
|
[
"def",
"manage_component_path",
"(",
"component",
")",
"current_params",
"=",
"try",
"(",
":params",
")",
"||",
"{",
"}",
"EngineRouter",
".",
"admin_proxy",
"(",
"component",
")",
".",
"root_path",
"(",
"locale",
":",
"current_params",
"[",
":locale",
"]",
")",
"end"
] |
Returns the defined admin root path for a given component.
component - the Component we want to find the root path for.
Returns a relative url.
|
[
"Returns",
"the",
"defined",
"admin",
"root",
"path",
"for",
"a",
"given",
"component",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/component_path_helper.rb#L31-L34
|
10,809
|
decidim/decidim
|
decidim-core/app/helpers/decidim/searches_helper.rb
|
Decidim.SearchesHelper.searchable_resource_human_name
|
def searchable_resource_human_name(resource, count: 5)
resource = if resource.is_a?(String)
resource.constantize
else
resource
end
resource.model_name.human(count: count)
end
|
ruby
|
def searchable_resource_human_name(resource, count: 5)
resource = if resource.is_a?(String)
resource.constantize
else
resource
end
resource.model_name.human(count: count)
end
|
[
"def",
"searchable_resource_human_name",
"(",
"resource",
",",
"count",
":",
"5",
")",
"resource",
"=",
"if",
"resource",
".",
"is_a?",
"(",
"String",
")",
"resource",
".",
"constantize",
"else",
"resource",
"end",
"resource",
".",
"model_name",
".",
"human",
"(",
"count",
":",
"count",
")",
"end"
] |
Renders the human name of the given class name.
klass_name - a String representing the class name of the resource to render
count - (optional) the number of resources so that the I18n backend
can decide to translate into singluar or plural form.
|
[
"Renders",
"the",
"human",
"name",
"of",
"the",
"given",
"class",
"name",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/searches_helper.rb#L11-L19
|
10,810
|
decidim/decidim
|
decidim-core/app/helpers/decidim/searches_helper.rb
|
Decidim.SearchesHelper.search_path_by
|
def search_path_by(resource_type: nil, space_state: nil)
new_params = {
utf8: params[:utf8],
filter: {
decidim_scope_id: params.dig(:filter, :decidim_scope_id),
term: params[:term] || params.dig(:filter, :term)
}
}
new_params[:filter][:resource_type] = resource_type if resource_type.present?
new_params[:filter][:space_state] = space_state if space_state.present?
decidim.search_path(new_params)
end
|
ruby
|
def search_path_by(resource_type: nil, space_state: nil)
new_params = {
utf8: params[:utf8],
filter: {
decidim_scope_id: params.dig(:filter, :decidim_scope_id),
term: params[:term] || params.dig(:filter, :term)
}
}
new_params[:filter][:resource_type] = resource_type if resource_type.present?
new_params[:filter][:space_state] = space_state if space_state.present?
decidim.search_path(new_params)
end
|
[
"def",
"search_path_by",
"(",
"resource_type",
":",
"nil",
",",
"space_state",
":",
"nil",
")",
"new_params",
"=",
"{",
"utf8",
":",
"params",
"[",
":utf8",
"]",
",",
"filter",
":",
"{",
"decidim_scope_id",
":",
"params",
".",
"dig",
"(",
":filter",
",",
":decidim_scope_id",
")",
",",
"term",
":",
"params",
"[",
":term",
"]",
"||",
"params",
".",
"dig",
"(",
":filter",
",",
":term",
")",
"}",
"}",
"new_params",
"[",
":filter",
"]",
"[",
":resource_type",
"]",
"=",
"resource_type",
"if",
"resource_type",
".",
"present?",
"new_params",
"[",
":filter",
"]",
"[",
":space_state",
"]",
"=",
"space_state",
"if",
"space_state",
".",
"present?",
"decidim",
".",
"search_path",
"(",
"new_params",
")",
"end"
] |
Generates a link to filter the current search by the given type. If no
type is given, it generates a link to the main results page.
resource_type - An optional String with the name of the model class to filter
space_state - An optional String with the name of the state of the space
|
[
"Generates",
"a",
"link",
"to",
"filter",
"the",
"current",
"search",
"by",
"the",
"given",
"type",
".",
"If",
"no",
"type",
"is",
"given",
"it",
"generates",
"a",
"link",
"to",
"the",
"main",
"results",
"page",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/searches_helper.rb#L26-L37
|
10,811
|
decidim/decidim
|
decidim-core/app/helpers/decidim/searches_helper.rb
|
Decidim.SearchesHelper.search_path_by_state_link
|
def search_path_by_state_link(state)
path = search_path_by(resource_type: params.dig(:filter, :resource_type), space_state: state)
is_active = params.dig(:filter, :space_state).to_s == state.to_s
link_to path, class: "order-by__tab#{" is-active" if is_active}" do
content_tag(:strong, t(state || :all, scope: "decidim.searches.filters.state"))
end
end
|
ruby
|
def search_path_by_state_link(state)
path = search_path_by(resource_type: params.dig(:filter, :resource_type), space_state: state)
is_active = params.dig(:filter, :space_state).to_s == state.to_s
link_to path, class: "order-by__tab#{" is-active" if is_active}" do
content_tag(:strong, t(state || :all, scope: "decidim.searches.filters.state"))
end
end
|
[
"def",
"search_path_by_state_link",
"(",
"state",
")",
"path",
"=",
"search_path_by",
"(",
"resource_type",
":",
"params",
".",
"dig",
"(",
":filter",
",",
":resource_type",
")",
",",
"space_state",
":",
"state",
")",
"is_active",
"=",
"params",
".",
"dig",
"(",
":filter",
",",
":space_state",
")",
".",
"to_s",
"==",
"state",
".",
"to_s",
"link_to",
"path",
",",
"class",
":",
"\"order-by__tab#{\" is-active\" if is_active}\"",
"do",
"content_tag",
"(",
":strong",
",",
"t",
"(",
"state",
"||",
":all",
",",
"scope",
":",
"\"decidim.searches.filters.state\"",
")",
")",
"end",
"end"
] |
Generates the path and link to filter by space state, taking into account
the other filters applied.
|
[
"Generates",
"the",
"path",
"and",
"link",
"to",
"filter",
"by",
"space",
"state",
"taking",
"into",
"account",
"the",
"other",
"filters",
"applied",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/searches_helper.rb#L52-L59
|
10,812
|
decidim/decidim
|
decidim-core/app/helpers/decidim/decidim_form_helper.rb
|
Decidim.DecidimFormHelper.decidim_form_for
|
def decidim_form_for(record, options = {}, &block)
options[:data] ||= {}
options[:data].update(abide: true, "live-validate" => true, "validate-on-blur" => true)
options[:html] ||= {}
options[:html].update(novalidate: true)
output = ""
output += base_error_messages(record).to_s
output += form_for(record, options, &block).to_s
output.html_safe
end
|
ruby
|
def decidim_form_for(record, options = {}, &block)
options[:data] ||= {}
options[:data].update(abide: true, "live-validate" => true, "validate-on-blur" => true)
options[:html] ||= {}
options[:html].update(novalidate: true)
output = ""
output += base_error_messages(record).to_s
output += form_for(record, options, &block).to_s
output.html_safe
end
|
[
"def",
"decidim_form_for",
"(",
"record",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"options",
"[",
":data",
"]",
"||=",
"{",
"}",
"options",
"[",
":data",
"]",
".",
"update",
"(",
"abide",
":",
"true",
",",
"\"live-validate\"",
"=>",
"true",
",",
"\"validate-on-blur\"",
"=>",
"true",
")",
"options",
"[",
":html",
"]",
"||=",
"{",
"}",
"options",
"[",
":html",
"]",
".",
"update",
"(",
"novalidate",
":",
"true",
")",
"output",
"=",
"\"\"",
"output",
"+=",
"base_error_messages",
"(",
"record",
")",
".",
"to_s",
"output",
"+=",
"form_for",
"(",
"record",
",",
"options",
",",
"block",
")",
".",
"to_s",
"output",
".",
"html_safe",
"end"
] |
A custom form for that injects client side validations with Abide.
record - The object to build the form for.
options - A Hash of options to pass to the form builder.
&block - The block to execute as content of the form.
Returns a String.
|
[
"A",
"custom",
"form",
"for",
"that",
"injects",
"client",
"side",
"validations",
"with",
"Abide",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/decidim_form_helper.rb#L13-L25
|
10,813
|
decidim/decidim
|
decidim-core/app/helpers/decidim/decidim_form_helper.rb
|
Decidim.DecidimFormHelper.editor_field_tag
|
def editor_field_tag(name, value, options = {})
options[:toolbar] ||= "basic"
options[:lines] ||= 10
content_tag(:div, class: "editor") do
template = ""
template += label_tag(name, options[:label]) if options[:label] != false
template += hidden_field_tag(name, value, options)
template += content_tag(:div, nil, class: "editor-container", data: {
toolbar: options[:toolbar]
}, style: "height: #{options[:lines]}rem")
template.html_safe
end
end
|
ruby
|
def editor_field_tag(name, value, options = {})
options[:toolbar] ||= "basic"
options[:lines] ||= 10
content_tag(:div, class: "editor") do
template = ""
template += label_tag(name, options[:label]) if options[:label] != false
template += hidden_field_tag(name, value, options)
template += content_tag(:div, nil, class: "editor-container", data: {
toolbar: options[:toolbar]
}, style: "height: #{options[:lines]}rem")
template.html_safe
end
end
|
[
"def",
"editor_field_tag",
"(",
"name",
",",
"value",
",",
"options",
"=",
"{",
"}",
")",
"options",
"[",
":toolbar",
"]",
"||=",
"\"basic\"",
"options",
"[",
":lines",
"]",
"||=",
"10",
"content_tag",
"(",
":div",
",",
"class",
":",
"\"editor\"",
")",
"do",
"template",
"=",
"\"\"",
"template",
"+=",
"label_tag",
"(",
"name",
",",
"options",
"[",
":label",
"]",
")",
"if",
"options",
"[",
":label",
"]",
"!=",
"false",
"template",
"+=",
"hidden_field_tag",
"(",
"name",
",",
"value",
",",
"options",
")",
"template",
"+=",
"content_tag",
"(",
":div",
",",
"nil",
",",
"class",
":",
"\"editor-container\"",
",",
"data",
":",
"{",
"toolbar",
":",
"options",
"[",
":toolbar",
"]",
"}",
",",
"style",
":",
"\"height: #{options[:lines]}rem\"",
")",
"template",
".",
"html_safe",
"end",
"end"
] |
A custom helper to include an editor field without requiring a form object
name - The input name
value - The input value
options - The set of options to send to the field
:label - The Boolean value to create or not the input label (optional) (default: true)
:toolbar - The String value to configure WYSIWYG toolbar. It should be 'basic' or
or 'full' (optional) (default: 'basic')
:lines - The Integer to indicate how many lines should editor have (optional)
Returns a rich editor to be included in an html template.
|
[
"A",
"custom",
"helper",
"to",
"include",
"an",
"editor",
"field",
"without",
"requiring",
"a",
"form",
"object"
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/decidim_form_helper.rb#L38-L51
|
10,814
|
decidim/decidim
|
decidim-core/app/helpers/decidim/decidim_form_helper.rb
|
Decidim.DecidimFormHelper.scopes_picker_field_tag
|
def scopes_picker_field_tag(name, value, id: nil)
picker_options = {
id: id || sanitize_to_id(name),
class: "picker-single",
name: name
}
prompt_params = yield(nil)
selected_scopes = value ? Decidim::Scope.where(id: value) : []
scopes = selected_scopes.map { |scope| [scope, yield(scope)] }
template = ""
template += render("decidim/scopes/scopes_picker_input",
picker_options: picker_options,
prompt_params: prompt_params,
scopes: scopes,
checkboxes_on_top: true)
template.html_safe
end
|
ruby
|
def scopes_picker_field_tag(name, value, id: nil)
picker_options = {
id: id || sanitize_to_id(name),
class: "picker-single",
name: name
}
prompt_params = yield(nil)
selected_scopes = value ? Decidim::Scope.where(id: value) : []
scopes = selected_scopes.map { |scope| [scope, yield(scope)] }
template = ""
template += render("decidim/scopes/scopes_picker_input",
picker_options: picker_options,
prompt_params: prompt_params,
scopes: scopes,
checkboxes_on_top: true)
template.html_safe
end
|
[
"def",
"scopes_picker_field_tag",
"(",
"name",
",",
"value",
",",
"id",
":",
"nil",
")",
"picker_options",
"=",
"{",
"id",
":",
"id",
"||",
"sanitize_to_id",
"(",
"name",
")",
",",
"class",
":",
"\"picker-single\"",
",",
"name",
":",
"name",
"}",
"prompt_params",
"=",
"yield",
"(",
"nil",
")",
"selected_scopes",
"=",
"value",
"?",
"Decidim",
"::",
"Scope",
".",
"where",
"(",
"id",
":",
"value",
")",
":",
"[",
"]",
"scopes",
"=",
"selected_scopes",
".",
"map",
"{",
"|",
"scope",
"|",
"[",
"scope",
",",
"yield",
"(",
"scope",
")",
"]",
"}",
"template",
"=",
"\"\"",
"template",
"+=",
"render",
"(",
"\"decidim/scopes/scopes_picker_input\"",
",",
"picker_options",
":",
"picker_options",
",",
"prompt_params",
":",
"prompt_params",
",",
"scopes",
":",
"scopes",
",",
"checkboxes_on_top",
":",
"true",
")",
"template",
".",
"html_safe",
"end"
] |
A custom helper to include a scope picker field without requiring a form
object
name - The input name
value - The input value as a scope id
options - The set of options to send to the field
:id - The id to generate for the element (optional)
Returns a scopes picker tag to be included in an html template.
|
[
"A",
"custom",
"helper",
"to",
"include",
"a",
"scope",
"picker",
"field",
"without",
"requiring",
"a",
"form",
"object"
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/decidim_form_helper.rb#L62-L80
|
10,815
|
decidim/decidim
|
decidim-core/app/helpers/decidim/decidim_form_helper.rb
|
Decidim.DecidimFormHelper.translated_field_tag
|
def translated_field_tag(type, object_name, name, value = {}, options = {})
locales = available_locales
field_label = label_tag(name, options[:label])
if locales.count == 1
field_name = "#{name}_#{locales.first.to_s.gsub("-", "__")}"
field_input = send(
type,
"#{object_name}[#{field_name}]",
value[locales.first.to_s]
)
return safe_join [field_label, field_input]
end
tabs_id = options[:tabs_id] || "#{object_name}-#{name}-tabs".underscore
enabled_tabs = options[:enable_tabs].nil? ? true : options[:enable_tabs]
tabs_panels_data = enabled_tabs ? { tabs: true } : {}
label_tabs = content_tag(:div, class: "label--tabs") do
tabs_panels = "".html_safe
if options[:label] != false
tabs_panels = content_tag(:ul, class: "tabs tabs--lang", id: tabs_id, data: tabs_panels_data) do
locales.each_with_index.inject("".html_safe) do |string, (locale, index)|
string + content_tag(:li, class: tab_element_class_for("title", index)) do
title = I18n.with_locale(locale) { I18n.t("name", scope: "locale") }
element_class = nil
element_class = "is-tab-error" if form_field_has_error?(options[:object], name_with_locale(name, locale))
tab_content_id = "#{tabs_id}-#{name}-panel-#{index}"
content_tag(:a, title, href: "##{tab_content_id}", class: element_class)
end
end
end
end
safe_join [field_label, tabs_panels]
end
tabs_content = content_tag(:div, class: "tabs-content", data: { tabs_content: tabs_id }) do
locales.each_with_index.inject("".html_safe) do |string, (locale, index)|
tab_content_id = "#{tabs_id}-#{name}-panel-#{index}"
string + content_tag(:div, class: tab_element_class_for("panel", index), id: tab_content_id) do
send(type, "#{object_name}[#{name_with_locale(name, locale)}]", value[locale.to_s], options.merge(id: "#{tabs_id}_#{name}_#{locale}", label: false))
end
end
end
safe_join [label_tabs, tabs_content]
end
|
ruby
|
def translated_field_tag(type, object_name, name, value = {}, options = {})
locales = available_locales
field_label = label_tag(name, options[:label])
if locales.count == 1
field_name = "#{name}_#{locales.first.to_s.gsub("-", "__")}"
field_input = send(
type,
"#{object_name}[#{field_name}]",
value[locales.first.to_s]
)
return safe_join [field_label, field_input]
end
tabs_id = options[:tabs_id] || "#{object_name}-#{name}-tabs".underscore
enabled_tabs = options[:enable_tabs].nil? ? true : options[:enable_tabs]
tabs_panels_data = enabled_tabs ? { tabs: true } : {}
label_tabs = content_tag(:div, class: "label--tabs") do
tabs_panels = "".html_safe
if options[:label] != false
tabs_panels = content_tag(:ul, class: "tabs tabs--lang", id: tabs_id, data: tabs_panels_data) do
locales.each_with_index.inject("".html_safe) do |string, (locale, index)|
string + content_tag(:li, class: tab_element_class_for("title", index)) do
title = I18n.with_locale(locale) { I18n.t("name", scope: "locale") }
element_class = nil
element_class = "is-tab-error" if form_field_has_error?(options[:object], name_with_locale(name, locale))
tab_content_id = "#{tabs_id}-#{name}-panel-#{index}"
content_tag(:a, title, href: "##{tab_content_id}", class: element_class)
end
end
end
end
safe_join [field_label, tabs_panels]
end
tabs_content = content_tag(:div, class: "tabs-content", data: { tabs_content: tabs_id }) do
locales.each_with_index.inject("".html_safe) do |string, (locale, index)|
tab_content_id = "#{tabs_id}-#{name}-panel-#{index}"
string + content_tag(:div, class: tab_element_class_for("panel", index), id: tab_content_id) do
send(type, "#{object_name}[#{name_with_locale(name, locale)}]", value[locale.to_s], options.merge(id: "#{tabs_id}_#{name}_#{locale}", label: false))
end
end
end
safe_join [label_tabs, tabs_content]
end
|
[
"def",
"translated_field_tag",
"(",
"type",
",",
"object_name",
",",
"name",
",",
"value",
"=",
"{",
"}",
",",
"options",
"=",
"{",
"}",
")",
"locales",
"=",
"available_locales",
"field_label",
"=",
"label_tag",
"(",
"name",
",",
"options",
"[",
":label",
"]",
")",
"if",
"locales",
".",
"count",
"==",
"1",
"field_name",
"=",
"\"#{name}_#{locales.first.to_s.gsub(\"-\", \"__\")}\"",
"field_input",
"=",
"send",
"(",
"type",
",",
"\"#{object_name}[#{field_name}]\"",
",",
"value",
"[",
"locales",
".",
"first",
".",
"to_s",
"]",
")",
"return",
"safe_join",
"[",
"field_label",
",",
"field_input",
"]",
"end",
"tabs_id",
"=",
"options",
"[",
":tabs_id",
"]",
"||",
"\"#{object_name}-#{name}-tabs\"",
".",
"underscore",
"enabled_tabs",
"=",
"options",
"[",
":enable_tabs",
"]",
".",
"nil?",
"?",
"true",
":",
"options",
"[",
":enable_tabs",
"]",
"tabs_panels_data",
"=",
"enabled_tabs",
"?",
"{",
"tabs",
":",
"true",
"}",
":",
"{",
"}",
"label_tabs",
"=",
"content_tag",
"(",
":div",
",",
"class",
":",
"\"label--tabs\"",
")",
"do",
"tabs_panels",
"=",
"\"\"",
".",
"html_safe",
"if",
"options",
"[",
":label",
"]",
"!=",
"false",
"tabs_panels",
"=",
"content_tag",
"(",
":ul",
",",
"class",
":",
"\"tabs tabs--lang\"",
",",
"id",
":",
"tabs_id",
",",
"data",
":",
"tabs_panels_data",
")",
"do",
"locales",
".",
"each_with_index",
".",
"inject",
"(",
"\"\"",
".",
"html_safe",
")",
"do",
"|",
"string",
",",
"(",
"locale",
",",
"index",
")",
"|",
"string",
"+",
"content_tag",
"(",
":li",
",",
"class",
":",
"tab_element_class_for",
"(",
"\"title\"",
",",
"index",
")",
")",
"do",
"title",
"=",
"I18n",
".",
"with_locale",
"(",
"locale",
")",
"{",
"I18n",
".",
"t",
"(",
"\"name\"",
",",
"scope",
":",
"\"locale\"",
")",
"}",
"element_class",
"=",
"nil",
"element_class",
"=",
"\"is-tab-error\"",
"if",
"form_field_has_error?",
"(",
"options",
"[",
":object",
"]",
",",
"name_with_locale",
"(",
"name",
",",
"locale",
")",
")",
"tab_content_id",
"=",
"\"#{tabs_id}-#{name}-panel-#{index}\"",
"content_tag",
"(",
":a",
",",
"title",
",",
"href",
":",
"\"##{tab_content_id}\"",
",",
"class",
":",
"element_class",
")",
"end",
"end",
"end",
"end",
"safe_join",
"[",
"field_label",
",",
"tabs_panels",
"]",
"end",
"tabs_content",
"=",
"content_tag",
"(",
":div",
",",
"class",
":",
"\"tabs-content\"",
",",
"data",
":",
"{",
"tabs_content",
":",
"tabs_id",
"}",
")",
"do",
"locales",
".",
"each_with_index",
".",
"inject",
"(",
"\"\"",
".",
"html_safe",
")",
"do",
"|",
"string",
",",
"(",
"locale",
",",
"index",
")",
"|",
"tab_content_id",
"=",
"\"#{tabs_id}-#{name}-panel-#{index}\"",
"string",
"+",
"content_tag",
"(",
":div",
",",
"class",
":",
"tab_element_class_for",
"(",
"\"panel\"",
",",
"index",
")",
",",
"id",
":",
"tab_content_id",
")",
"do",
"send",
"(",
"type",
",",
"\"#{object_name}[#{name_with_locale(name, locale)}]\"",
",",
"value",
"[",
"locale",
".",
"to_s",
"]",
",",
"options",
".",
"merge",
"(",
"id",
":",
"\"#{tabs_id}_#{name}_#{locale}\"",
",",
"label",
":",
"false",
")",
")",
"end",
"end",
"end",
"safe_join",
"[",
"label_tabs",
",",
"tabs_content",
"]",
"end"
] |
A custom helper to include a translated field without requiring a form object.
type - The type of the translated input field.
object_name - The object name used to identify the Foundation tabs.
name - The name of the input which will be suffixed with the corresponding locales.
value - A hash containing the value for each locale.
options - An optional hash of options.
* enable_tabs: Adds the data-tabs attribute so Foundation picks up automatically.
* tabs_id: The id to identify the Foundation tabs element.
* label: The label used for the field.
Returns a Foundation tabs element with the translated input field.
|
[
"A",
"custom",
"helper",
"to",
"include",
"a",
"translated",
"field",
"without",
"requiring",
"a",
"form",
"object",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/decidim_form_helper.rb#L94-L143
|
10,816
|
decidim/decidim
|
decidim-core/app/helpers/decidim/decidim_form_helper.rb
|
Decidim.DecidimFormHelper.decidim_form_slug_url
|
def decidim_form_slug_url(prepend_path = "", value = "")
prepend_slug_path = if prepend_path.present?
"/#{prepend_path}/"
else
"/"
end
content_tag(:span, class: "slug-url") do
[
request.protocol,
request.host_with_port,
prepend_slug_path
].join("").html_safe +
content_tag(:span, value, class: "slug-url-value")
end
end
|
ruby
|
def decidim_form_slug_url(prepend_path = "", value = "")
prepend_slug_path = if prepend_path.present?
"/#{prepend_path}/"
else
"/"
end
content_tag(:span, class: "slug-url") do
[
request.protocol,
request.host_with_port,
prepend_slug_path
].join("").html_safe +
content_tag(:span, value, class: "slug-url-value")
end
end
|
[
"def",
"decidim_form_slug_url",
"(",
"prepend_path",
"=",
"\"\"",
",",
"value",
"=",
"\"\"",
")",
"prepend_slug_path",
"=",
"if",
"prepend_path",
".",
"present?",
"\"/#{prepend_path}/\"",
"else",
"\"/\"",
"end",
"content_tag",
"(",
":span",
",",
"class",
":",
"\"slug-url\"",
")",
"do",
"[",
"request",
".",
"protocol",
",",
"request",
".",
"host_with_port",
",",
"prepend_slug_path",
"]",
".",
"join",
"(",
"\"\"",
")",
".",
"html_safe",
"+",
"content_tag",
"(",
":span",
",",
"value",
",",
"class",
":",
"\"slug-url-value\"",
")",
"end",
"end"
] |
Helper method to show how slugs will look like. Intended to be used in forms
together with some JavaScript code. More precisely, this will most probably
show in help texts in forms. The space slug is surrounded with a `span` so
the slug can be updated via JavaScript with the input value.
prepend_path - a path to prepend to the slug, without final slash
value - the initial value of the slug field, so that edit forms have a value
Returns an HTML-safe String.
|
[
"Helper",
"method",
"to",
"show",
"how",
"slugs",
"will",
"look",
"like",
".",
"Intended",
"to",
"be",
"used",
"in",
"forms",
"together",
"with",
"some",
"JavaScript",
"code",
".",
"More",
"precisely",
"this",
"will",
"most",
"probably",
"show",
"in",
"help",
"texts",
"in",
"forms",
".",
"The",
"space",
"slug",
"is",
"surrounded",
"with",
"a",
"span",
"so",
"the",
"slug",
"can",
"be",
"updated",
"via",
"JavaScript",
"with",
"the",
"input",
"value",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/decidim_form_helper.rb#L170-L184
|
10,817
|
decidim/decidim
|
decidim-core/app/helpers/decidim/traceability_helper.rb
|
Decidim.TraceabilityHelper.render_resource_last_editor
|
def render_resource_last_editor(resource)
render partial: "decidim/shared/version_author",
locals: {
author: Decidim.traceability.last_editor(resource)
}
end
|
ruby
|
def render_resource_last_editor(resource)
render partial: "decidim/shared/version_author",
locals: {
author: Decidim.traceability.last_editor(resource)
}
end
|
[
"def",
"render_resource_last_editor",
"(",
"resource",
")",
"render",
"partial",
":",
"\"decidim/shared/version_author\"",
",",
"locals",
":",
"{",
"author",
":",
"Decidim",
".",
"traceability",
".",
"last_editor",
"(",
"resource",
")",
"}",
"end"
] |
Renders the avatar and author name of the author of the last version of the given
resource.
resource - an object implementing `Decidim::Traceable`
Returns an HTML-safe String representing the HTML to render the author.
|
[
"Renders",
"the",
"avatar",
"and",
"author",
"name",
"of",
"the",
"author",
"of",
"the",
"last",
"version",
"of",
"the",
"given",
"resource",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/traceability_helper.rb#L13-L18
|
10,818
|
decidim/decidim
|
decidim-core/app/helpers/decidim/traceability_helper.rb
|
Decidim.TraceabilityHelper.render_resource_editor
|
def render_resource_editor(version)
render partial: "decidim/shared/version_author",
locals: {
author: Decidim.traceability.version_editor(version)
}
end
|
ruby
|
def render_resource_editor(version)
render partial: "decidim/shared/version_author",
locals: {
author: Decidim.traceability.version_editor(version)
}
end
|
[
"def",
"render_resource_editor",
"(",
"version",
")",
"render",
"partial",
":",
"\"decidim/shared/version_author\"",
",",
"locals",
":",
"{",
"author",
":",
"Decidim",
".",
"traceability",
".",
"version_editor",
"(",
"version",
")",
"}",
"end"
] |
Renders the avatar and author name of the author of the given version.
version - an object that responds to `whodunnit` and returns a String.
Returns an HTML-safe String representing the HTML to render the author.
|
[
"Renders",
"the",
"avatar",
"and",
"author",
"name",
"of",
"the",
"author",
"of",
"the",
"given",
"version",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/traceability_helper.rb#L25-L30
|
10,819
|
decidim/decidim
|
decidim-core/app/helpers/decidim/traceability_helper.rb
|
Decidim.TraceabilityHelper.diff_renderer
|
def diff_renderer
@diff_renderer ||= if current_version.item_type.include? "Decidim::Proposals"
Decidim::Proposals::DiffRenderer.new(current_version)
elsif current_version.item_type.include? "Decidim::Accountability"
Decidim::Accountability::DiffRenderer.new(current_version)
end
end
|
ruby
|
def diff_renderer
@diff_renderer ||= if current_version.item_type.include? "Decidim::Proposals"
Decidim::Proposals::DiffRenderer.new(current_version)
elsif current_version.item_type.include? "Decidim::Accountability"
Decidim::Accountability::DiffRenderer.new(current_version)
end
end
|
[
"def",
"diff_renderer",
"@diff_renderer",
"||=",
"if",
"current_version",
".",
"item_type",
".",
"include?",
"\"Decidim::Proposals\"",
"Decidim",
"::",
"Proposals",
"::",
"DiffRenderer",
".",
"new",
"(",
"current_version",
")",
"elsif",
"current_version",
".",
"item_type",
".",
"include?",
"\"Decidim::Accountability\"",
"Decidim",
"::",
"Accountability",
"::",
"DiffRenderer",
".",
"new",
"(",
"current_version",
")",
"end",
"end"
] |
Caches a DiffRenderer instance for the `current_version`.
|
[
"Caches",
"a",
"DiffRenderer",
"instance",
"for",
"the",
"current_version",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/traceability_helper.rb#L33-L39
|
10,820
|
decidim/decidim
|
decidim-core/app/helpers/decidim/traceability_helper.rb
|
Decidim.TraceabilityHelper.render_diff_value
|
def render_diff_value(value, type, action, options = {})
return "".html_safe if value.blank?
value_to_render = case type
when :date
l value, format: :long
when :percentage
number_to_percentage value, precision: 2
else
value
end
content_tag(:div, class: "card--list__item #{action}") do
content_tag(:div, class: "card--list__text") do
content_tag(:div, { class: "diff__value" }.merge(options)) do
value_to_render
end
end
end
end
|
ruby
|
def render_diff_value(value, type, action, options = {})
return "".html_safe if value.blank?
value_to_render = case type
when :date
l value, format: :long
when :percentage
number_to_percentage value, precision: 2
else
value
end
content_tag(:div, class: "card--list__item #{action}") do
content_tag(:div, class: "card--list__text") do
content_tag(:div, { class: "diff__value" }.merge(options)) do
value_to_render
end
end
end
end
|
[
"def",
"render_diff_value",
"(",
"value",
",",
"type",
",",
"action",
",",
"options",
"=",
"{",
"}",
")",
"return",
"\"\"",
".",
"html_safe",
"if",
"value",
".",
"blank?",
"value_to_render",
"=",
"case",
"type",
"when",
":date",
"l",
"value",
",",
"format",
":",
":long",
"when",
":percentage",
"number_to_percentage",
"value",
",",
"precision",
":",
"2",
"else",
"value",
"end",
"content_tag",
"(",
":div",
",",
"class",
":",
"\"card--list__item #{action}\"",
")",
"do",
"content_tag",
"(",
":div",
",",
"class",
":",
"\"card--list__text\"",
")",
"do",
"content_tag",
"(",
":div",
",",
"{",
"class",
":",
"\"diff__value\"",
"}",
".",
"merge",
"(",
"options",
")",
")",
"do",
"value_to_render",
"end",
"end",
"end",
"end"
] |
Renders the given value in a user-friendly way based on the value class.
value - an object to be rendered
Returns an HTML-ready String.
|
[
"Renders",
"the",
"given",
"value",
"in",
"a",
"user",
"-",
"friendly",
"way",
"based",
"on",
"the",
"value",
"class",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/traceability_helper.rb#L72-L91
|
10,821
|
decidim/decidim
|
decidim-core/app/cells/decidim/activity_cell.rb
|
Decidim.ActivityCell.title
|
def title
resource_title = resource.try(:resource_title) || resource.try(:title)
return if resource_title.blank?
if resource_title.is_a?(String)
resource_title
elsif resource_title.is_a?(Hash)
translated_attribute(resource_title)
end
end
|
ruby
|
def title
resource_title = resource.try(:resource_title) || resource.try(:title)
return if resource_title.blank?
if resource_title.is_a?(String)
resource_title
elsif resource_title.is_a?(Hash)
translated_attribute(resource_title)
end
end
|
[
"def",
"title",
"resource_title",
"=",
"resource",
".",
"try",
"(",
":resource_title",
")",
"||",
"resource",
".",
"try",
"(",
":title",
")",
"return",
"if",
"resource_title",
".",
"blank?",
"if",
"resource_title",
".",
"is_a?",
"(",
"String",
")",
"resource_title",
"elsif",
"resource_title",
".",
"is_a?",
"(",
"Hash",
")",
"translated_attribute",
"(",
"resource_title",
")",
"end",
"end"
] |
The title to show at the card.
The card will also be displayed OK if there's no title.
|
[
"The",
"title",
"to",
"show",
"at",
"the",
"card",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/cells/decidim/activity_cell.rb#L34-L43
|
10,822
|
decidim/decidim
|
decidim-core/app/cells/decidim/activity_cell.rb
|
Decidim.ActivityCell.description
|
def description
resource_description = resource.try(:resource_description) || resource.try(:description)
return if resource_description.blank?
resource_description = if resource_description.is_a?(String)
resource_description
elsif resource_description.is_a?(Hash)
translated_attribute(resource_description)
end
truncate(strip_tags(resource_description), length: 300)
end
|
ruby
|
def description
resource_description = resource.try(:resource_description) || resource.try(:description)
return if resource_description.blank?
resource_description = if resource_description.is_a?(String)
resource_description
elsif resource_description.is_a?(Hash)
translated_attribute(resource_description)
end
truncate(strip_tags(resource_description), length: 300)
end
|
[
"def",
"description",
"resource_description",
"=",
"resource",
".",
"try",
"(",
":resource_description",
")",
"||",
"resource",
".",
"try",
"(",
":description",
")",
"return",
"if",
"resource_description",
".",
"blank?",
"resource_description",
"=",
"if",
"resource_description",
".",
"is_a?",
"(",
"String",
")",
"resource_description",
"elsif",
"resource_description",
".",
"is_a?",
"(",
"Hash",
")",
"translated_attribute",
"(",
"resource_description",
")",
"end",
"truncate",
"(",
"strip_tags",
"(",
"resource_description",
")",
",",
"length",
":",
"300",
")",
"end"
] |
The description to show at the card.
The card will also be displayed OK if there's no description.
|
[
"The",
"description",
"to",
"show",
"at",
"the",
"card",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/cells/decidim/activity_cell.rb#L48-L59
|
10,823
|
decidim/decidim
|
decidim-core/app/helpers/decidim/cta_button_helper.rb
|
Decidim.CtaButtonHelper.cta_button
|
def cta_button
button_text = translated_attribute(current_organization.cta_button_text).presence || t("decidim.pages.home.hero.participate")
link_to button_text, cta_button_path, class: "hero-cta button expanded large button--sc"
end
|
ruby
|
def cta_button
button_text = translated_attribute(current_organization.cta_button_text).presence || t("decidim.pages.home.hero.participate")
link_to button_text, cta_button_path, class: "hero-cta button expanded large button--sc"
end
|
[
"def",
"cta_button",
"button_text",
"=",
"translated_attribute",
"(",
"current_organization",
".",
"cta_button_text",
")",
".",
"presence",
"||",
"t",
"(",
"\"decidim.pages.home.hero.participate\"",
")",
"link_to",
"button_text",
",",
"cta_button_path",
",",
"class",
":",
"\"hero-cta button expanded large button--sc\"",
"end"
] |
Renders the Call To Action button. Link and text can be configured
per organization.
|
[
"Renders",
"the",
"Call",
"To",
"Action",
"button",
".",
"Link",
"and",
"text",
"can",
"be",
"configured",
"per",
"organization",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/cta_button_helper.rb#L8-L12
|
10,824
|
decidim/decidim
|
decidim-core/app/helpers/decidim/cta_button_helper.rb
|
Decidim.CtaButtonHelper.cta_button_path
|
def cta_button_path
if current_organization.cta_button_path.present?
current_organization.cta_button_path
elsif Decidim::ParticipatoryProcess.where(organization: current_organization).published.any?
decidim_participatory_processes.participatory_processes_path
elsif current_user
decidim.account_path
elsif current_organization.sign_up_enabled?
decidim.new_user_registration_path
else
decidim.new_user_session_path
end
end
|
ruby
|
def cta_button_path
if current_organization.cta_button_path.present?
current_organization.cta_button_path
elsif Decidim::ParticipatoryProcess.where(organization: current_organization).published.any?
decidim_participatory_processes.participatory_processes_path
elsif current_user
decidim.account_path
elsif current_organization.sign_up_enabled?
decidim.new_user_registration_path
else
decidim.new_user_session_path
end
end
|
[
"def",
"cta_button_path",
"if",
"current_organization",
".",
"cta_button_path",
".",
"present?",
"current_organization",
".",
"cta_button_path",
"elsif",
"Decidim",
"::",
"ParticipatoryProcess",
".",
"where",
"(",
"organization",
":",
"current_organization",
")",
".",
"published",
".",
"any?",
"decidim_participatory_processes",
".",
"participatory_processes_path",
"elsif",
"current_user",
"decidim",
".",
"account_path",
"elsif",
"current_organization",
".",
"sign_up_enabled?",
"decidim",
".",
"new_user_registration_path",
"else",
"decidim",
".",
"new_user_session_path",
"end",
"end"
] |
Finds the CTA button path to reuse it in other places.
|
[
"Finds",
"the",
"CTA",
"button",
"path",
"to",
"reuse",
"it",
"in",
"other",
"places",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/cta_button_helper.rb#L15-L27
|
10,825
|
decidim/decidim
|
decidim-core/lib/decidim/data_portability_file_reader.rb
|
Decidim.DataPortabilityFileReader.file_path
|
def file_path
directory_name = Rails.root.join(Decidim::DataPortabilityUploader.new.store_dir)
FileUtils.mkdir_p(directory_name) unless File.exist?(directory_name)
directory_name + file_name
end
|
ruby
|
def file_path
directory_name = Rails.root.join(Decidim::DataPortabilityUploader.new.store_dir)
FileUtils.mkdir_p(directory_name) unless File.exist?(directory_name)
directory_name + file_name
end
|
[
"def",
"file_path",
"directory_name",
"=",
"Rails",
".",
"root",
".",
"join",
"(",
"Decidim",
"::",
"DataPortabilityUploader",
".",
"new",
".",
"store_dir",
")",
"FileUtils",
".",
"mkdir_p",
"(",
"directory_name",
")",
"unless",
"File",
".",
"exist?",
"(",
"directory_name",
")",
"directory_name",
"+",
"file_name",
"end"
] |
Returns a String with the absolute file_path to be read or generate.
|
[
"Returns",
"a",
"String",
"with",
"the",
"absolute",
"file_path",
"to",
"be",
"read",
"or",
"generate",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/lib/decidim/data_portability_file_reader.rb#L30-L34
|
10,826
|
decidim/decidim
|
decidim-core/app/helpers/decidim/filters_helper.rb
|
Decidim.FiltersHelper.filter_form_for
|
def filter_form_for(filter, url = url_for)
content_tag :div, class: "filters" do
form_for filter, namespace: filter_form_namespace, builder: FilterFormBuilder, url: url, as: :filter, method: :get, remote: true, html: { id: nil } do |form|
yield form
end
end
end
|
ruby
|
def filter_form_for(filter, url = url_for)
content_tag :div, class: "filters" do
form_for filter, namespace: filter_form_namespace, builder: FilterFormBuilder, url: url, as: :filter, method: :get, remote: true, html: { id: nil } do |form|
yield form
end
end
end
|
[
"def",
"filter_form_for",
"(",
"filter",
",",
"url",
"=",
"url_for",
")",
"content_tag",
":div",
",",
"class",
":",
"\"filters\"",
"do",
"form_for",
"filter",
",",
"namespace",
":",
"filter_form_namespace",
",",
"builder",
":",
"FilterFormBuilder",
",",
"url",
":",
"url",
",",
"as",
":",
":filter",
",",
"method",
":",
":get",
",",
"remote",
":",
"true",
",",
"html",
":",
"{",
"id",
":",
"nil",
"}",
"do",
"|",
"form",
"|",
"yield",
"form",
"end",
"end",
"end"
] |
This method wraps everything in a div with class filters and calls
the form_for helper with a custom builder
filter - A filter object
url - A String with the URL to post the from. Self URL by default.
block - A block to be called with the form builder
Returns the filter resource form wrapped in a div
|
[
"This",
"method",
"wraps",
"everything",
"in",
"a",
"div",
"with",
"class",
"filters",
"and",
"calls",
"the",
"form_for",
"helper",
"with",
"a",
"custom",
"builder"
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/filters_helper.rb#L14-L20
|
10,827
|
decidim/decidim
|
decidim-core/app/uploaders/decidim/attachment_uploader.rb
|
Decidim.AttachmentUploader.image?
|
def image?(new_file)
content_type = model.content_type || new_file.content_type
content_type.to_s.start_with? "image"
end
|
ruby
|
def image?(new_file)
content_type = model.content_type || new_file.content_type
content_type.to_s.start_with? "image"
end
|
[
"def",
"image?",
"(",
"new_file",
")",
"content_type",
"=",
"model",
".",
"content_type",
"||",
"new_file",
".",
"content_type",
"content_type",
".",
"to_s",
".",
"start_with?",
"\"image\"",
"end"
] |
Checks if the file is an image based on the content type. We need this so
we only create different versions of the file when it's an image.
new_file - The uploaded file.
Returns a Boolean.
|
[
"Checks",
"if",
"the",
"file",
"is",
"an",
"image",
"based",
"on",
"the",
"content",
"type",
".",
"We",
"need",
"this",
"so",
"we",
"only",
"create",
"different",
"versions",
"of",
"the",
"file",
"when",
"it",
"s",
"an",
"image",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/uploaders/decidim/attachment_uploader.rb#L43-L46
|
10,828
|
decidim/decidim
|
decidim-core/app/uploaders/decidim/attachment_uploader.rb
|
Decidim.AttachmentUploader.set_content_type_and_size_in_model
|
def set_content_type_and_size_in_model
model.content_type = file.content_type if file.content_type
model.file_size = file.size
end
|
ruby
|
def set_content_type_and_size_in_model
model.content_type = file.content_type if file.content_type
model.file_size = file.size
end
|
[
"def",
"set_content_type_and_size_in_model",
"model",
".",
"content_type",
"=",
"file",
".",
"content_type",
"if",
"file",
".",
"content_type",
"model",
".",
"file_size",
"=",
"file",
".",
"size",
"end"
] |
Copies the content type and file size to the model where this is mounted.
Returns nothing.
|
[
"Copies",
"the",
"content",
"type",
"and",
"file",
"size",
"to",
"the",
"model",
"where",
"this",
"is",
"mounted",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/uploaders/decidim/attachment_uploader.rb#L51-L54
|
10,829
|
decidim/decidim
|
decidim-core/lib/decidim/filter_form_builder.rb
|
Decidim.FilterFormBuilder.collection_radio_buttons
|
def collection_radio_buttons(method, collection, value_method, label_method, options = {}, html_options = {})
fieldset_wrapper options[:legend_title] do
super(method, collection, value_method, label_method, options, html_options) do |builder|
if block_given?
yield builder
else
builder.label { builder.radio_button + builder.text }
end
end
end
end
|
ruby
|
def collection_radio_buttons(method, collection, value_method, label_method, options = {}, html_options = {})
fieldset_wrapper options[:legend_title] do
super(method, collection, value_method, label_method, options, html_options) do |builder|
if block_given?
yield builder
else
builder.label { builder.radio_button + builder.text }
end
end
end
end
|
[
"def",
"collection_radio_buttons",
"(",
"method",
",",
"collection",
",",
"value_method",
",",
"label_method",
",",
"options",
"=",
"{",
"}",
",",
"html_options",
"=",
"{",
"}",
")",
"fieldset_wrapper",
"options",
"[",
":legend_title",
"]",
"do",
"super",
"(",
"method",
",",
"collection",
",",
"value_method",
",",
"label_method",
",",
"options",
",",
"html_options",
")",
"do",
"|",
"builder",
"|",
"if",
"block_given?",
"yield",
"builder",
"else",
"builder",
".",
"label",
"{",
"builder",
".",
"radio_button",
"+",
"builder",
".",
"text",
"}",
"end",
"end",
"end",
"end"
] |
Wrap the radio buttons collection in a custom fieldset.
It also renders the inputs inside its labels.
|
[
"Wrap",
"the",
"radio",
"buttons",
"collection",
"in",
"a",
"custom",
"fieldset",
".",
"It",
"also",
"renders",
"the",
"inputs",
"inside",
"its",
"labels",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/lib/decidim/filter_form_builder.rb#L10-L20
|
10,830
|
decidim/decidim
|
decidim-core/lib/decidim/filter_form_builder.rb
|
Decidim.FilterFormBuilder.collection_check_boxes
|
def collection_check_boxes(method, collection, value_method, label_method, options = {}, html_options = {})
fieldset_wrapper options[:legend_title] do
super(method, collection, value_method, label_method, options, html_options) do |builder|
if block_given?
yield builder
else
builder.label { builder.check_box + builder.text }
end
end
end
end
|
ruby
|
def collection_check_boxes(method, collection, value_method, label_method, options = {}, html_options = {})
fieldset_wrapper options[:legend_title] do
super(method, collection, value_method, label_method, options, html_options) do |builder|
if block_given?
yield builder
else
builder.label { builder.check_box + builder.text }
end
end
end
end
|
[
"def",
"collection_check_boxes",
"(",
"method",
",",
"collection",
",",
"value_method",
",",
"label_method",
",",
"options",
"=",
"{",
"}",
",",
"html_options",
"=",
"{",
"}",
")",
"fieldset_wrapper",
"options",
"[",
":legend_title",
"]",
"do",
"super",
"(",
"method",
",",
"collection",
",",
"value_method",
",",
"label_method",
",",
"options",
",",
"html_options",
")",
"do",
"|",
"builder",
"|",
"if",
"block_given?",
"yield",
"builder",
"else",
"builder",
".",
"label",
"{",
"builder",
".",
"check_box",
"+",
"builder",
".",
"text",
"}",
"end",
"end",
"end",
"end"
] |
Wrap the check_boxes collection in a custom fieldset.
It also renders the inputs inside its labels.
|
[
"Wrap",
"the",
"check_boxes",
"collection",
"in",
"a",
"custom",
"fieldset",
".",
"It",
"also",
"renders",
"the",
"inputs",
"inside",
"its",
"labels",
"."
] |
6e2b14e559a63088669904e3c5c49a5180700cf7
|
https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/lib/decidim/filter_form_builder.rb#L24-L34
|
10,831
|
capistrano/capistrano
|
lib/capistrano/dsl.rb
|
Capistrano.DSL.execute
|
def execute(*)
file, line, = caller.first.split(":")
colors = SSHKit::Color.new($stderr)
$stderr.puts colors.colorize("Warning: `execute' should be wrapped in an `on' scope in #{file}:#{line}.", :red)
$stderr.puts
$stderr.puts " task :example do"
$stderr.puts colors.colorize(" on roles(:app) do", :yellow)
$stderr.puts " execute 'whoami'"
$stderr.puts colors.colorize(" end", :yellow)
$stderr.puts " end"
$stderr.puts
raise NoMethodError, "undefined method `execute' for main:Object"
end
|
ruby
|
def execute(*)
file, line, = caller.first.split(":")
colors = SSHKit::Color.new($stderr)
$stderr.puts colors.colorize("Warning: `execute' should be wrapped in an `on' scope in #{file}:#{line}.", :red)
$stderr.puts
$stderr.puts " task :example do"
$stderr.puts colors.colorize(" on roles(:app) do", :yellow)
$stderr.puts " execute 'whoami'"
$stderr.puts colors.colorize(" end", :yellow)
$stderr.puts " end"
$stderr.puts
raise NoMethodError, "undefined method `execute' for main:Object"
end
|
[
"def",
"execute",
"(",
"*",
")",
"file",
",",
"line",
",",
"=",
"caller",
".",
"first",
".",
"split",
"(",
"\":\"",
")",
"colors",
"=",
"SSHKit",
"::",
"Color",
".",
"new",
"(",
"$stderr",
")",
"$stderr",
".",
"puts",
"colors",
".",
"colorize",
"(",
"\"Warning: `execute' should be wrapped in an `on' scope in #{file}:#{line}.\"",
",",
":red",
")",
"$stderr",
".",
"puts",
"$stderr",
".",
"puts",
"\" task :example do\"",
"$stderr",
".",
"puts",
"colors",
".",
"colorize",
"(",
"\" on roles(:app) do\"",
",",
":yellow",
")",
"$stderr",
".",
"puts",
"\" execute 'whoami'\"",
"$stderr",
".",
"puts",
"colors",
".",
"colorize",
"(",
"\" end\"",
",",
":yellow",
")",
"$stderr",
".",
"puts",
"\" end\"",
"$stderr",
".",
"puts",
"raise",
"NoMethodError",
",",
"\"undefined method `execute' for main:Object\"",
"end"
] |
Catch common beginner mistake and give a helpful error message on stderr
|
[
"Catch",
"common",
"beginner",
"mistake",
"and",
"give",
"a",
"helpful",
"error",
"message",
"on",
"stderr"
] |
7a14ddb47d64187c8a7ee14c7d78e874f30f08ef
|
https://github.com/capistrano/capistrano/blob/7a14ddb47d64187c8a7ee14c7d78e874f30f08ef/lib/capistrano/dsl.rb#L80-L92
|
10,832
|
tongueroo/jets
|
lib/jets/preheat.rb
|
Jets.Preheat.warm_all
|
def warm_all
threads = []
all_functions.each do |function_name|
next if function_name.include?('jets-public_controller') # handled by warm_public_controller_more
next if function_name.include?('jets-rack_controller') # handled by warm_rack_controller_more
threads << Thread.new do
warm(function_name)
end
end
threads.each { |t| t.join }
# Warm the these controllers more since they can be hit more often
warm_public_controller_more
warm_rack_controller_more
# return the funciton names so we can see in the Lambda console
# the functions being prewarmed
all_functions
end
|
ruby
|
def warm_all
threads = []
all_functions.each do |function_name|
next if function_name.include?('jets-public_controller') # handled by warm_public_controller_more
next if function_name.include?('jets-rack_controller') # handled by warm_rack_controller_more
threads << Thread.new do
warm(function_name)
end
end
threads.each { |t| t.join }
# Warm the these controllers more since they can be hit more often
warm_public_controller_more
warm_rack_controller_more
# return the funciton names so we can see in the Lambda console
# the functions being prewarmed
all_functions
end
|
[
"def",
"warm_all",
"threads",
"=",
"[",
"]",
"all_functions",
".",
"each",
"do",
"|",
"function_name",
"|",
"next",
"if",
"function_name",
".",
"include?",
"(",
"'jets-public_controller'",
")",
"# handled by warm_public_controller_more",
"next",
"if",
"function_name",
".",
"include?",
"(",
"'jets-rack_controller'",
")",
"# handled by warm_rack_controller_more",
"threads",
"<<",
"Thread",
".",
"new",
"do",
"warm",
"(",
"function_name",
")",
"end",
"end",
"threads",
".",
"each",
"{",
"|",
"t",
"|",
"t",
".",
"join",
"}",
"# Warm the these controllers more since they can be hit more often",
"warm_public_controller_more",
"warm_rack_controller_more",
"# return the funciton names so we can see in the Lambda console",
"# the functions being prewarmed",
"all_functions",
"end"
] |
Loop through all methods for each class and makes special prewarm call to each method.
|
[
"Loop",
"through",
"all",
"methods",
"for",
"each",
"class",
"and",
"makes",
"special",
"prewarm",
"call",
"to",
"each",
"method",
"."
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/preheat.rb#L30-L48
|
10,833
|
tongueroo/jets
|
lib/jets/job/dsl/iot_event.rb
|
Jets::Job::Dsl.IotEvent.iot_event
|
def iot_event(props={})
if props.is_a?(String) # SQL Statement
props = {sql: props}
topic_props = {topic_rule_payload: props}
elsif props.key?(:topic_rule_payload) # full properties structure
topic_props = props
else # just the topic_rule_payload
topic_props = {topic_rule_payload: props}
end
declare_iot_topic(topic_props)
end
|
ruby
|
def iot_event(props={})
if props.is_a?(String) # SQL Statement
props = {sql: props}
topic_props = {topic_rule_payload: props}
elsif props.key?(:topic_rule_payload) # full properties structure
topic_props = props
else # just the topic_rule_payload
topic_props = {topic_rule_payload: props}
end
declare_iot_topic(topic_props)
end
|
[
"def",
"iot_event",
"(",
"props",
"=",
"{",
"}",
")",
"if",
"props",
".",
"is_a?",
"(",
"String",
")",
"# SQL Statement",
"props",
"=",
"{",
"sql",
":",
"props",
"}",
"topic_props",
"=",
"{",
"topic_rule_payload",
":",
"props",
"}",
"elsif",
"props",
".",
"key?",
"(",
":topic_rule_payload",
")",
"# full properties structure",
"topic_props",
"=",
"props",
"else",
"# just the topic_rule_payload",
"topic_props",
"=",
"{",
"topic_rule_payload",
":",
"props",
"}",
"end",
"declare_iot_topic",
"(",
"topic_props",
")",
"end"
] |
The user must at least pass in an SQL statement
|
[
"The",
"user",
"must",
"at",
"least",
"pass",
"in",
"an",
"SQL",
"statement"
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/job/dsl/iot_event.rb#L4-L15
|
10,834
|
tongueroo/jets
|
lib/jets/resource/lambda/function.rb
|
Jets::Resource::Lambda.Function.lookup_class_properties
|
def lookup_class_properties(klass)
all_classes = []
while klass != Object
all_classes << klass
klass = klass.superclass
end
class_properties = {}
# Go back down class heirachry top to down
all_classes.reverse.each do |k|
class_properties.merge!(k.class_properties)
end
class_properties
end
|
ruby
|
def lookup_class_properties(klass)
all_classes = []
while klass != Object
all_classes << klass
klass = klass.superclass
end
class_properties = {}
# Go back down class heirachry top to down
all_classes.reverse.each do |k|
class_properties.merge!(k.class_properties)
end
class_properties
end
|
[
"def",
"lookup_class_properties",
"(",
"klass",
")",
"all_classes",
"=",
"[",
"]",
"while",
"klass",
"!=",
"Object",
"all_classes",
"<<",
"klass",
"klass",
"=",
"klass",
".",
"superclass",
"end",
"class_properties",
"=",
"{",
"}",
"# Go back down class heirachry top to down",
"all_classes",
".",
"reverse",
".",
"each",
"do",
"|",
"k",
"|",
"class_properties",
".",
"merge!",
"(",
"k",
".",
"class_properties",
")",
"end",
"class_properties",
"end"
] |
Accounts for inherited class_properties
|
[
"Accounts",
"for",
"inherited",
"class_properties"
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/resource/lambda/function.rb#L85-L97
|
10,835
|
tongueroo/jets
|
lib/jets/resource/lambda/function.rb
|
Jets::Resource::Lambda.Function.finalize_properties!
|
def finalize_properties!(props)
handler = full_handler(props)
runtime = get_runtime(props)
managed = {
handler: handler,
runtime: runtime,
description: description,
}
managed[:function_name] = function_name if function_name
layers = get_layers(runtime)
managed[:layers] = layers if layers
props.merge!(managed)
end
|
ruby
|
def finalize_properties!(props)
handler = full_handler(props)
runtime = get_runtime(props)
managed = {
handler: handler,
runtime: runtime,
description: description,
}
managed[:function_name] = function_name if function_name
layers = get_layers(runtime)
managed[:layers] = layers if layers
props.merge!(managed)
end
|
[
"def",
"finalize_properties!",
"(",
"props",
")",
"handler",
"=",
"full_handler",
"(",
"props",
")",
"runtime",
"=",
"get_runtime",
"(",
"props",
")",
"managed",
"=",
"{",
"handler",
":",
"handler",
",",
"runtime",
":",
"runtime",
",",
"description",
":",
"description",
",",
"}",
"managed",
"[",
":function_name",
"]",
"=",
"function_name",
"if",
"function_name",
"layers",
"=",
"get_layers",
"(",
"runtime",
")",
"managed",
"[",
":layers",
"]",
"=",
"layers",
"if",
"layers",
"props",
".",
"merge!",
"(",
"managed",
")",
"end"
] |
Properties managed by Jets with merged with finality.
|
[
"Properties",
"managed",
"by",
"Jets",
"with",
"merged",
"with",
"finality",
"."
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/resource/lambda/function.rb#L124-L136
|
10,836
|
tongueroo/jets
|
lib/jets/resource/iam/policy_document.rb
|
Jets::Resource::Iam.PolicyDocument.standardize
|
def standardize(definition)
case definition
when String
# Expands simple string from: logs => logs:*
definition = "#{definition}:*" unless definition.include?(':')
@policy[:statement] << {
action: [definition],
effect: "Allow",
resource: "*",
}
when Hash
definition = definition.stringify_keys
if definition.key?("Version") # special case where we replace the policy entirely
@policy = definition
else
@policy[:statement] << definition
end
end
end
|
ruby
|
def standardize(definition)
case definition
when String
# Expands simple string from: logs => logs:*
definition = "#{definition}:*" unless definition.include?(':')
@policy[:statement] << {
action: [definition],
effect: "Allow",
resource: "*",
}
when Hash
definition = definition.stringify_keys
if definition.key?("Version") # special case where we replace the policy entirely
@policy = definition
else
@policy[:statement] << definition
end
end
end
|
[
"def",
"standardize",
"(",
"definition",
")",
"case",
"definition",
"when",
"String",
"# Expands simple string from: logs => logs:*",
"definition",
"=",
"\"#{definition}:*\"",
"unless",
"definition",
".",
"include?",
"(",
"':'",
")",
"@policy",
"[",
":statement",
"]",
"<<",
"{",
"action",
":",
"[",
"definition",
"]",
",",
"effect",
":",
"\"Allow\"",
",",
"resource",
":",
"\"*\"",
",",
"}",
"when",
"Hash",
"definition",
"=",
"definition",
".",
"stringify_keys",
"if",
"definition",
".",
"key?",
"(",
"\"Version\"",
")",
"# special case where we replace the policy entirely",
"@policy",
"=",
"definition",
"else",
"@policy",
"[",
":statement",
"]",
"<<",
"definition",
"end",
"end",
"end"
] |
only process policy_document once
|
[
"only",
"process",
"policy_document",
"once"
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/resource/iam/policy_document.rb#L21-L39
|
10,837
|
tongueroo/jets
|
lib/jets/controller/rack/adapter.rb
|
Jets::Controller::Rack.Adapter.process
|
def process
status, headers, body = Jets.application.call(env)
convert_to_api_gateway(status, headers, body)
end
|
ruby
|
def process
status, headers, body = Jets.application.call(env)
convert_to_api_gateway(status, headers, body)
end
|
[
"def",
"process",
"status",
",",
"headers",
",",
"body",
"=",
"Jets",
".",
"application",
".",
"call",
"(",
"env",
")",
"convert_to_api_gateway",
"(",
"status",
",",
"headers",
",",
"body",
")",
"end"
] |
1. Convert API Gateway event event to Rack env
2. Process using full Rack middleware stack
3. Convert back to API gateway response structure payload
|
[
"1",
".",
"Convert",
"API",
"Gateway",
"event",
"event",
"to",
"Rack",
"env",
"2",
".",
"Process",
"using",
"full",
"Rack",
"middleware",
"stack",
"3",
".",
"Convert",
"back",
"to",
"API",
"gateway",
"response",
"structure",
"payload"
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/controller/rack/adapter.rb#L20-L23
|
10,838
|
tongueroo/jets
|
lib/jets/router.rb
|
Jets.Router.check_collision!
|
def check_collision!
paths = self.routes.map(&:path)
collision = Jets::Resource::ApiGateway::RestApi::Routes::Collision.new
collide = collision.collision?(paths)
raise collision.exception if collide
end
|
ruby
|
def check_collision!
paths = self.routes.map(&:path)
collision = Jets::Resource::ApiGateway::RestApi::Routes::Collision.new
collide = collision.collision?(paths)
raise collision.exception if collide
end
|
[
"def",
"check_collision!",
"paths",
"=",
"self",
".",
"routes",
".",
"map",
"(",
":path",
")",
"collision",
"=",
"Jets",
"::",
"Resource",
"::",
"ApiGateway",
"::",
"RestApi",
"::",
"Routes",
"::",
"Collision",
".",
"new",
"collide",
"=",
"collision",
".",
"collision?",
"(",
"paths",
")",
"raise",
"collision",
".",
"exception",
"if",
"collide",
"end"
] |
Validate routes that deployable
|
[
"Validate",
"routes",
"that",
"deployable"
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/router.rb#L18-L23
|
10,839
|
tongueroo/jets
|
lib/jets/router.rb
|
Jets.Router.resources
|
def resources(name)
get "#{name}", to: "#{name}#index"
get "#{name}/new", to: "#{name}#new" unless api_mode?
get "#{name}/:id", to: "#{name}#show"
post "#{name}", to: "#{name}#create"
get "#{name}/:id/edit", to: "#{name}#edit" unless api_mode?
put "#{name}/:id", to: "#{name}#update"
post "#{name}/:id", to: "#{name}#update" # for binary uploads
patch "#{name}/:id", to: "#{name}#update"
delete "#{name}/:id", to: "#{name}#delete"
end
|
ruby
|
def resources(name)
get "#{name}", to: "#{name}#index"
get "#{name}/new", to: "#{name}#new" unless api_mode?
get "#{name}/:id", to: "#{name}#show"
post "#{name}", to: "#{name}#create"
get "#{name}/:id/edit", to: "#{name}#edit" unless api_mode?
put "#{name}/:id", to: "#{name}#update"
post "#{name}/:id", to: "#{name}#update" # for binary uploads
patch "#{name}/:id", to: "#{name}#update"
delete "#{name}/:id", to: "#{name}#delete"
end
|
[
"def",
"resources",
"(",
"name",
")",
"get",
"\"#{name}\"",
",",
"to",
":",
"\"#{name}#index\"",
"get",
"\"#{name}/new\"",
",",
"to",
":",
"\"#{name}#new\"",
"unless",
"api_mode?",
"get",
"\"#{name}/:id\"",
",",
"to",
":",
"\"#{name}#show\"",
"post",
"\"#{name}\"",
",",
"to",
":",
"\"#{name}#create\"",
"get",
"\"#{name}/:id/edit\"",
",",
"to",
":",
"\"#{name}#edit\"",
"unless",
"api_mode?",
"put",
"\"#{name}/:id\"",
",",
"to",
":",
"\"#{name}#update\"",
"post",
"\"#{name}/:id\"",
",",
"to",
":",
"\"#{name}#update\"",
"# for binary uploads",
"patch",
"\"#{name}/:id\"",
",",
"to",
":",
"\"#{name}#update\"",
"delete",
"\"#{name}/:id\"",
",",
"to",
":",
"\"#{name}#delete\"",
"end"
] |
resources macro expands to all the routes
|
[
"resources",
"macro",
"expands",
"to",
"all",
"the",
"routes"
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/router.rb#L60-L70
|
10,840
|
tongueroo/jets
|
lib/jets/router.rb
|
Jets.Router.all_paths
|
def all_paths
results = []
paths = routes.map(&:path)
paths.each do |p|
sub_paths = []
parts = p.split('/')
until parts.empty?
parts.pop
sub_path = parts.join('/')
sub_paths << sub_path unless sub_path == ''
end
results += sub_paths
end
@all_paths = (results + paths).sort.uniq
end
|
ruby
|
def all_paths
results = []
paths = routes.map(&:path)
paths.each do |p|
sub_paths = []
parts = p.split('/')
until parts.empty?
parts.pop
sub_path = parts.join('/')
sub_paths << sub_path unless sub_path == ''
end
results += sub_paths
end
@all_paths = (results + paths).sort.uniq
end
|
[
"def",
"all_paths",
"results",
"=",
"[",
"]",
"paths",
"=",
"routes",
".",
"map",
"(",
":path",
")",
"paths",
".",
"each",
"do",
"|",
"p",
"|",
"sub_paths",
"=",
"[",
"]",
"parts",
"=",
"p",
".",
"split",
"(",
"'/'",
")",
"until",
"parts",
".",
"empty?",
"parts",
".",
"pop",
"sub_path",
"=",
"parts",
".",
"join",
"(",
"'/'",
")",
"sub_paths",
"<<",
"sub_path",
"unless",
"sub_path",
"==",
"''",
"end",
"results",
"+=",
"sub_paths",
"end",
"@all_paths",
"=",
"(",
"results",
"+",
"paths",
")",
".",
"sort",
".",
"uniq",
"end"
] |
Useful for creating API Gateway Resources
|
[
"Useful",
"for",
"creating",
"API",
"Gateway",
"Resources"
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/router.rb#L94-L108
|
10,841
|
tongueroo/jets
|
lib/jets/router.rb
|
Jets.Router.ordered_routes
|
def ordered_routes
length = Proc.new { |r| r.path.length * -1 }
capture_routes = routes.select { |r| r.path.include?(':') }.sort_by(&length)
wildcard_routes = routes.select { |r| r.path.include?('*') }.sort_by(&length)
simple_routes = (routes - capture_routes - wildcard_routes).sort_by(&length)
simple_routes + capture_routes + wildcard_routes
end
|
ruby
|
def ordered_routes
length = Proc.new { |r| r.path.length * -1 }
capture_routes = routes.select { |r| r.path.include?(':') }.sort_by(&length)
wildcard_routes = routes.select { |r| r.path.include?('*') }.sort_by(&length)
simple_routes = (routes - capture_routes - wildcard_routes).sort_by(&length)
simple_routes + capture_routes + wildcard_routes
end
|
[
"def",
"ordered_routes",
"length",
"=",
"Proc",
".",
"new",
"{",
"|",
"r",
"|",
"r",
".",
"path",
".",
"length",
"*",
"-",
"1",
"}",
"capture_routes",
"=",
"routes",
".",
"select",
"{",
"|",
"r",
"|",
"r",
".",
"path",
".",
"include?",
"(",
"':'",
")",
"}",
".",
"sort_by",
"(",
"length",
")",
"wildcard_routes",
"=",
"routes",
".",
"select",
"{",
"|",
"r",
"|",
"r",
".",
"path",
".",
"include?",
"(",
"'*'",
")",
"}",
".",
"sort_by",
"(",
"length",
")",
"simple_routes",
"=",
"(",
"routes",
"-",
"capture_routes",
"-",
"wildcard_routes",
")",
".",
"sort_by",
"(",
"length",
")",
"simple_routes",
"+",
"capture_routes",
"+",
"wildcard_routes",
"end"
] |
Useful for RouterMatcher
Precedence:
1. Routes with no captures get highest precedence: posts/new
2. Then consider the routes with captures: post/:id
3. Last consider the routes with wildcards: *catchall
Within these 2 groups we consider the routes with the longest path first
since posts/:id and posts/:id/edit can both match.
|
[
"Useful",
"for",
"RouterMatcher"
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/router.rb#L119-L125
|
10,842
|
tongueroo/jets
|
lib/jets/controller/middleware/local.rb
|
Jets::Controller::Middleware.Local.routes_table
|
def routes_table
routes = Jets::Router.routes
return "Your routes table is empty." if routes.empty?
text = "Verb | Path | Controller#action\n"
text << "--- | --- | ---\n"
routes.each do |route|
text << "#{route.method} | #{route.path} | #{route.to}\n"
end
html = Kramdown::Document.new(text).to_html
puts html
html
end
|
ruby
|
def routes_table
routes = Jets::Router.routes
return "Your routes table is empty." if routes.empty?
text = "Verb | Path | Controller#action\n"
text << "--- | --- | ---\n"
routes.each do |route|
text << "#{route.method} | #{route.path} | #{route.to}\n"
end
html = Kramdown::Document.new(text).to_html
puts html
html
end
|
[
"def",
"routes_table",
"routes",
"=",
"Jets",
"::",
"Router",
".",
"routes",
"return",
"\"Your routes table is empty.\"",
"if",
"routes",
".",
"empty?",
"text",
"=",
"\"Verb | Path | Controller#action\\n\"",
"text",
"<<",
"\"--- | --- | ---\\n\"",
"routes",
".",
"each",
"do",
"|",
"route",
"|",
"text",
"<<",
"\"#{route.method} | #{route.path} | #{route.to}\\n\"",
"end",
"html",
"=",
"Kramdown",
"::",
"Document",
".",
"new",
"(",
"text",
")",
".",
"to_html",
"puts",
"html",
"html",
"end"
] |
Show pretty route table for user to help with debugging in non-production mode
|
[
"Show",
"pretty",
"route",
"table",
"for",
"user",
"to",
"help",
"with",
"debugging",
"in",
"non",
"-",
"production",
"mode"
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/controller/middleware/local.rb#L105-L118
|
10,843
|
tongueroo/jets
|
lib/jets/resource/api_gateway/cors.rb
|
Jets::Resource::ApiGateway.Cors.cors_headers
|
def cors_headers
rack = Jets::Controller::Middleware::Cors.new(Jets.application)
rack.cors_headers(true)
end
|
ruby
|
def cors_headers
rack = Jets::Controller::Middleware::Cors.new(Jets.application)
rack.cors_headers(true)
end
|
[
"def",
"cors_headers",
"rack",
"=",
"Jets",
"::",
"Controller",
"::",
"Middleware",
"::",
"Cors",
".",
"new",
"(",
"Jets",
".",
"application",
")",
"rack",
".",
"cors_headers",
"(",
"true",
")",
"end"
] |
Always the pre-flight headers in this case
|
[
"Always",
"the",
"pre",
"-",
"flight",
"headers",
"in",
"this",
"case"
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/resource/api_gateway/cors.rb#L48-L51
|
10,844
|
tongueroo/jets
|
lib/jets/rack_server.rb
|
Jets.RackServer.serve
|
def serve
# Note, looks like stopping jets server with Ctrl-C sends the TERM signal
# down to the sub bin/rackup command cleans up the child process fine.
Bundler.with_clean_env do
args = ''
# only forward the host option, port is always 9292 for simplicity
if @options[:host]
args << " --host #{@options[:host]}"
else
args << " --host 127.0.0.1" # using the default localhost is not starting up https://stackoverflow.com/questions/4356646/address-family-not-supported-by-protocol-family
end
command = "cd #{rack_project} && bin/rackup#{args}" # leads to the same wrapper rack scripts
puts "=> #{command}".color(:green)
system(command)
end
end
|
ruby
|
def serve
# Note, looks like stopping jets server with Ctrl-C sends the TERM signal
# down to the sub bin/rackup command cleans up the child process fine.
Bundler.with_clean_env do
args = ''
# only forward the host option, port is always 9292 for simplicity
if @options[:host]
args << " --host #{@options[:host]}"
else
args << " --host 127.0.0.1" # using the default localhost is not starting up https://stackoverflow.com/questions/4356646/address-family-not-supported-by-protocol-family
end
command = "cd #{rack_project} && bin/rackup#{args}" # leads to the same wrapper rack scripts
puts "=> #{command}".color(:green)
system(command)
end
end
|
[
"def",
"serve",
"# Note, looks like stopping jets server with Ctrl-C sends the TERM signal",
"# down to the sub bin/rackup command cleans up the child process fine.",
"Bundler",
".",
"with_clean_env",
"do",
"args",
"=",
"''",
"# only forward the host option, port is always 9292 for simplicity",
"if",
"@options",
"[",
":host",
"]",
"args",
"<<",
"\" --host #{@options[:host]}\"",
"else",
"args",
"<<",
"\" --host 127.0.0.1\"",
"# using the default localhost is not starting up https://stackoverflow.com/questions/4356646/address-family-not-supported-by-protocol-family",
"end",
"command",
"=",
"\"cd #{rack_project} && bin/rackup#{args}\"",
"# leads to the same wrapper rack scripts",
"puts",
"\"=> #{command}\"",
".",
"color",
"(",
":green",
")",
"system",
"(",
"command",
")",
"end",
"end"
] |
Runs in the child process
|
[
"Runs",
"in",
"the",
"child",
"process"
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/rack_server.rb#L34-L51
|
10,845
|
tongueroo/jets
|
lib/jets/rack_server.rb
|
Jets.RackServer.wait_for_socket
|
def wait_for_socket
return unless Jets.rack?
retries = 0
max_retries = 30 # 15 seconds at a delay of 0.5s
delay = 0.5
if ENV['C9_USER'] # overrides for local testing
max_retries = 3
delay = 3
end
begin
server = TCPSocket.new('localhost', 9292)
server.close
rescue Errno::ECONNREFUSED
puts "Unable to connect to localhost:9292. Delay for #{delay} and will try to connect again." if ENV['JETS_DEBUG']
sleep(delay)
retries += 1
if retries < max_retries
retry
else
puts "Giving up on trying to connect to localhost:9292"
return false
end
end
puts "Connected to localhost:9292 successfully"
true
end
|
ruby
|
def wait_for_socket
return unless Jets.rack?
retries = 0
max_retries = 30 # 15 seconds at a delay of 0.5s
delay = 0.5
if ENV['C9_USER'] # overrides for local testing
max_retries = 3
delay = 3
end
begin
server = TCPSocket.new('localhost', 9292)
server.close
rescue Errno::ECONNREFUSED
puts "Unable to connect to localhost:9292. Delay for #{delay} and will try to connect again." if ENV['JETS_DEBUG']
sleep(delay)
retries += 1
if retries < max_retries
retry
else
puts "Giving up on trying to connect to localhost:9292"
return false
end
end
puts "Connected to localhost:9292 successfully"
true
end
|
[
"def",
"wait_for_socket",
"return",
"unless",
"Jets",
".",
"rack?",
"retries",
"=",
"0",
"max_retries",
"=",
"30",
"# 15 seconds at a delay of 0.5s",
"delay",
"=",
"0.5",
"if",
"ENV",
"[",
"'C9_USER'",
"]",
"# overrides for local testing",
"max_retries",
"=",
"3",
"delay",
"=",
"3",
"end",
"begin",
"server",
"=",
"TCPSocket",
".",
"new",
"(",
"'localhost'",
",",
"9292",
")",
"server",
".",
"close",
"rescue",
"Errno",
"::",
"ECONNREFUSED",
"puts",
"\"Unable to connect to localhost:9292. Delay for #{delay} and will try to connect again.\"",
"if",
"ENV",
"[",
"'JETS_DEBUG'",
"]",
"sleep",
"(",
"delay",
")",
"retries",
"+=",
"1",
"if",
"retries",
"<",
"max_retries",
"retry",
"else",
"puts",
"\"Giving up on trying to connect to localhost:9292\"",
"return",
"false",
"end",
"end",
"puts",
"\"Connected to localhost:9292 successfully\"",
"true",
"end"
] |
blocks until rack server is up
|
[
"blocks",
"until",
"rack",
"server",
"is",
"up"
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/rack_server.rb#L54-L80
|
10,846
|
tongueroo/jets
|
lib/jets/logger.rb
|
Jets.Logger.add
|
def add(severity, message = nil, progname = nil)
# Taken from Logger#add source
# https://ruby-doc.org/stdlib-2.5.1/libdoc/logger/rdoc/Logger.html#method-i-add
if message.nil?
if block_given?
message = yield
else
message = progname
progname = @progname
end
end
# Put the message in the Jets::IO.buffer which will get flushed to CloudWatch.
# No need to include timestamp as CloudWatch already has a timestamp.
IO.buffer << message
super # original logical
end
|
ruby
|
def add(severity, message = nil, progname = nil)
# Taken from Logger#add source
# https://ruby-doc.org/stdlib-2.5.1/libdoc/logger/rdoc/Logger.html#method-i-add
if message.nil?
if block_given?
message = yield
else
message = progname
progname = @progname
end
end
# Put the message in the Jets::IO.buffer which will get flushed to CloudWatch.
# No need to include timestamp as CloudWatch already has a timestamp.
IO.buffer << message
super # original logical
end
|
[
"def",
"add",
"(",
"severity",
",",
"message",
"=",
"nil",
",",
"progname",
"=",
"nil",
")",
"# Taken from Logger#add source",
"# https://ruby-doc.org/stdlib-2.5.1/libdoc/logger/rdoc/Logger.html#method-i-add",
"if",
"message",
".",
"nil?",
"if",
"block_given?",
"message",
"=",
"yield",
"else",
"message",
"=",
"progname",
"progname",
"=",
"@progname",
"end",
"end",
"# Put the message in the Jets::IO.buffer which will get flushed to CloudWatch.",
"# No need to include timestamp as CloudWatch already has a timestamp.",
"IO",
".",
"buffer",
"<<",
"message",
"super",
"# original logical",
"end"
] |
Only need to override the add method as the other calls all lead to it.
|
[
"Only",
"need",
"to",
"override",
"the",
"add",
"method",
"as",
"the",
"other",
"calls",
"all",
"lead",
"to",
"it",
"."
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/logger.rb#L6-L22
|
10,847
|
tongueroo/jets
|
lib/jets/commands/markdown/page.rb
|
Jets::Commands::Markdown.Page.long_description
|
def long_description
text = @command.long_description
return "" if text.nil? # empty description
lines = text.split("\n")
lines.map do |line|
# In the CLI help, we use 2 spaces to designate commands
# In Markdown we need 4 spaces.
line.sub(/^ \b/, ' ')
end.join("\n")
end
|
ruby
|
def long_description
text = @command.long_description
return "" if text.nil? # empty description
lines = text.split("\n")
lines.map do |line|
# In the CLI help, we use 2 spaces to designate commands
# In Markdown we need 4 spaces.
line.sub(/^ \b/, ' ')
end.join("\n")
end
|
[
"def",
"long_description",
"text",
"=",
"@command",
".",
"long_description",
"return",
"\"\"",
"if",
"text",
".",
"nil?",
"# empty description",
"lines",
"=",
"text",
".",
"split",
"(",
"\"\\n\"",
")",
"lines",
".",
"map",
"do",
"|",
"line",
"|",
"# In the CLI help, we use 2 spaces to designate commands",
"# In Markdown we need 4 spaces.",
"line",
".",
"sub",
"(",
"/",
"\\b",
"/",
",",
"' '",
")",
"end",
".",
"join",
"(",
"\"\\n\"",
")",
"end"
] |
Use command's long description as main description
|
[
"Use",
"command",
"s",
"long",
"description",
"as",
"main",
"description"
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/commands/markdown/page.rb#L46-L56
|
10,848
|
tongueroo/jets
|
lib/jets/rdoc.rb
|
Jets.Rdoc.options
|
def options
exclude = %w[
docs
spec
vendor
core.rb
.js
templates
commands
internal
support
Dockerfile
Dockerfile.base
Gemfile
Gemfile.lock
Guardfile
LICENSE
Procfile
Rakefile
bin
]
exclude = exclude.map { |word| ['-x', word] }.flatten
["-m", "README.md", "--markup", "tomdoc"] + exclude
end
|
ruby
|
def options
exclude = %w[
docs
spec
vendor
core.rb
.js
templates
commands
internal
support
Dockerfile
Dockerfile.base
Gemfile
Gemfile.lock
Guardfile
LICENSE
Procfile
Rakefile
bin
]
exclude = exclude.map { |word| ['-x', word] }.flatten
["-m", "README.md", "--markup", "tomdoc"] + exclude
end
|
[
"def",
"options",
"exclude",
"=",
"%w[",
"docs",
"spec",
"vendor",
"core.rb",
".js",
"templates",
"commands",
"internal",
"support",
"Dockerfile",
"Dockerfile.base",
"Gemfile",
"Gemfile.lock",
"Guardfile",
"LICENSE",
"Procfile",
"Rakefile",
"bin",
"]",
"exclude",
"=",
"exclude",
".",
"map",
"{",
"|",
"word",
"|",
"[",
"'-x'",
",",
"word",
"]",
"}",
".",
"flatten",
"[",
"\"-m\"",
",",
"\"README.md\"",
",",
"\"--markup\"",
",",
"\"tomdoc\"",
"]",
"+",
"exclude",
"end"
] |
Use for both jets.gemspec and rake rdoc task
|
[
"Use",
"for",
"both",
"jets",
".",
"gemspec",
"and",
"rake",
"rdoc",
"task"
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/rdoc.rb#L4-L27
|
10,849
|
tongueroo/jets
|
lib/jets/middleware/default_stack.rb
|
Jets::Middleware.DefaultStack.use_webpacker
|
def use_webpacker(middleware)
return unless Jets.webpacker? # checks for local development if webpacker installed
# Different check for middleware because we need webpacker helpers for url helpers.
# But we dont want to actually serve via webpacker middleware when running on AWS.
# By this time the url helpers are serving assets out of s3.
return if File.exist?("#{Jets.root}/config/disable-webpacker-middleware.txt") # created as part of `jets deploy`
require "jets/controller/middleware/webpacker_setup"
middleware.use Webpacker::DevServerProxy
end
|
ruby
|
def use_webpacker(middleware)
return unless Jets.webpacker? # checks for local development if webpacker installed
# Different check for middleware because we need webpacker helpers for url helpers.
# But we dont want to actually serve via webpacker middleware when running on AWS.
# By this time the url helpers are serving assets out of s3.
return if File.exist?("#{Jets.root}/config/disable-webpacker-middleware.txt") # created as part of `jets deploy`
require "jets/controller/middleware/webpacker_setup"
middleware.use Webpacker::DevServerProxy
end
|
[
"def",
"use_webpacker",
"(",
"middleware",
")",
"return",
"unless",
"Jets",
".",
"webpacker?",
"# checks for local development if webpacker installed",
"# Different check for middleware because we need webpacker helpers for url helpers.",
"# But we dont want to actually serve via webpacker middleware when running on AWS.",
"# By this time the url helpers are serving assets out of s3.",
"return",
"if",
"File",
".",
"exist?",
"(",
"\"#{Jets.root}/config/disable-webpacker-middleware.txt\"",
")",
"# created as part of `jets deploy`",
"require",
"\"jets/controller/middleware/webpacker_setup\"",
"middleware",
".",
"use",
"Webpacker",
"::",
"DevServerProxy",
"end"
] |
Written as method to easily not include webpacker for case when either
webpacker not installed at all or disabled upon `jets deploy`.
|
[
"Written",
"as",
"method",
"to",
"easily",
"not",
"include",
"webpacker",
"for",
"case",
"when",
"either",
"webpacker",
"not",
"installed",
"at",
"all",
"or",
"disabled",
"upon",
"jets",
"deploy",
"."
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/middleware/default_stack.rb#L30-L38
|
10,850
|
tongueroo/jets
|
lib/jets/aws_info.rb
|
Jets.AwsInfo.account
|
def account
return '123456789' if test?
# ensure region set, required for sts.get_caller_identity.account to work
ENV['AWS_REGION'] ||= region
begin
sts.get_caller_identity.account
rescue Aws::Errors::MissingCredentialsError
puts "INFO: You're missing AWS credentials. Only local services are currently available"
end
end
|
ruby
|
def account
return '123456789' if test?
# ensure region set, required for sts.get_caller_identity.account to work
ENV['AWS_REGION'] ||= region
begin
sts.get_caller_identity.account
rescue Aws::Errors::MissingCredentialsError
puts "INFO: You're missing AWS credentials. Only local services are currently available"
end
end
|
[
"def",
"account",
"return",
"'123456789'",
"if",
"test?",
"# ensure region set, required for sts.get_caller_identity.account to work",
"ENV",
"[",
"'AWS_REGION'",
"]",
"||=",
"region",
"begin",
"sts",
".",
"get_caller_identity",
".",
"account",
"rescue",
"Aws",
"::",
"Errors",
"::",
"MissingCredentialsError",
"puts",
"\"INFO: You're missing AWS credentials. Only local services are currently available\"",
"end",
"end"
] |
aws sts get-caller-identity
|
[
"aws",
"sts",
"get",
"-",
"caller",
"-",
"identity"
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/aws_info.rb#L50-L59
|
10,851
|
tongueroo/jets
|
lib/jets/commands/deploy.rb
|
Jets::Commands.Deploy.check_route_connected_functions
|
def check_route_connected_functions
return if Jets::Router.all_routes_valid
puts "Deploy fail: The jets application contain invalid routes.".color(:red)
puts "Please double check the routes below map to valid controllers:"
Jets::Router.invalid_routes.each do |route|
puts " /#{route.path} => #{route.controller_name}##{route.action_name}"
end
exit 1
end
|
ruby
|
def check_route_connected_functions
return if Jets::Router.all_routes_valid
puts "Deploy fail: The jets application contain invalid routes.".color(:red)
puts "Please double check the routes below map to valid controllers:"
Jets::Router.invalid_routes.each do |route|
puts " /#{route.path} => #{route.controller_name}##{route.action_name}"
end
exit 1
end
|
[
"def",
"check_route_connected_functions",
"return",
"if",
"Jets",
"::",
"Router",
".",
"all_routes_valid",
"puts",
"\"Deploy fail: The jets application contain invalid routes.\"",
".",
"color",
"(",
":red",
")",
"puts",
"\"Please double check the routes below map to valid controllers:\"",
"Jets",
"::",
"Router",
".",
"invalid_routes",
".",
"each",
"do",
"|",
"route",
"|",
"puts",
"\" /#{route.path} => #{route.controller_name}##{route.action_name}\"",
"end",
"exit",
"1",
"end"
] |
Checks that all routes are validate and have corresponding lambda functions
|
[
"Checks",
"that",
"all",
"routes",
"are",
"validate",
"and",
"have",
"corresponding",
"lambda",
"functions"
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/commands/deploy.rb#L67-L76
|
10,852
|
tongueroo/jets
|
lib/jets/commands/deploy.rb
|
Jets::Commands.Deploy.minimal_rollback_complete?
|
def minimal_rollback_complete?
stack = find_stack(stack_name)
return false unless stack
return false unless stack.stack_status == 'ROLLBACK_COMPLETE'
# Finally check if all the minimal resources in the parent template have been deleted
resp = cfn.describe_stack_resources(stack_name: stack_name)
resource_statuses = resp.stack_resources.map(&:resource_status).uniq
resource_statuses == ['DELETE_COMPLETE']
end
|
ruby
|
def minimal_rollback_complete?
stack = find_stack(stack_name)
return false unless stack
return false unless stack.stack_status == 'ROLLBACK_COMPLETE'
# Finally check if all the minimal resources in the parent template have been deleted
resp = cfn.describe_stack_resources(stack_name: stack_name)
resource_statuses = resp.stack_resources.map(&:resource_status).uniq
resource_statuses == ['DELETE_COMPLETE']
end
|
[
"def",
"minimal_rollback_complete?",
"stack",
"=",
"find_stack",
"(",
"stack_name",
")",
"return",
"false",
"unless",
"stack",
"return",
"false",
"unless",
"stack",
".",
"stack_status",
"==",
"'ROLLBACK_COMPLETE'",
"# Finally check if all the minimal resources in the parent template have been deleted",
"resp",
"=",
"cfn",
".",
"describe_stack_resources",
"(",
"stack_name",
":",
"stack_name",
")",
"resource_statuses",
"=",
"resp",
".",
"stack_resources",
".",
"map",
"(",
":resource_status",
")",
".",
"uniq",
"resource_statuses",
"==",
"[",
"'DELETE_COMPLETE'",
"]",
"end"
] |
Checks for a few things before deciding to delete the parent stack
* Parent stack status status is ROLLBACK_COMPLETE
* Parent resources are in the DELETE_COMPLETE state
|
[
"Checks",
"for",
"a",
"few",
"things",
"before",
"deciding",
"to",
"delete",
"the",
"parent",
"stack"
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/commands/deploy.rb#L98-L108
|
10,853
|
tongueroo/jets
|
lib/jets/resource/iam/class_role.rb
|
Jets::Resource::Iam.ClassRole.all_classes
|
def all_classes
klass = @app_class.constantize
all_classes = []
while klass != Object
all_classes << klass
klass = klass.superclass
end
all_classes.reverse
end
|
ruby
|
def all_classes
klass = @app_class.constantize
all_classes = []
while klass != Object
all_classes << klass
klass = klass.superclass
end
all_classes.reverse
end
|
[
"def",
"all_classes",
"klass",
"=",
"@app_class",
".",
"constantize",
"all_classes",
"=",
"[",
"]",
"while",
"klass",
"!=",
"Object",
"all_classes",
"<<",
"klass",
"klass",
"=",
"klass",
".",
"superclass",
"end",
"all_classes",
".",
"reverse",
"end"
] |
Class heirachry in top to down order
|
[
"Class",
"heirachry",
"in",
"top",
"to",
"down",
"order"
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/resource/iam/class_role.rb#L63-L71
|
10,854
|
tongueroo/jets
|
lib/jets/lambda/function_constructor.rb
|
Jets::Lambda.FunctionConstructor.adjust_tasks
|
def adjust_tasks(klass)
class_name = @code_path.to_s.sub(/.*\/functions\//,'').sub(/\.rb$/, '')
class_name = class_name.classify
klass.tasks.each do |task|
task.class_name = class_name
task.type = "function"
end
end
|
ruby
|
def adjust_tasks(klass)
class_name = @code_path.to_s.sub(/.*\/functions\//,'').sub(/\.rb$/, '')
class_name = class_name.classify
klass.tasks.each do |task|
task.class_name = class_name
task.type = "function"
end
end
|
[
"def",
"adjust_tasks",
"(",
"klass",
")",
"class_name",
"=",
"@code_path",
".",
"to_s",
".",
"sub",
"(",
"/",
"\\/",
"\\/",
"/",
",",
"''",
")",
".",
"sub",
"(",
"/",
"\\.",
"/",
",",
"''",
")",
"class_name",
"=",
"class_name",
".",
"classify",
"klass",
".",
"tasks",
".",
"each",
"do",
"|",
"task",
"|",
"task",
".",
"class_name",
"=",
"class_name",
"task",
".",
"type",
"=",
"\"function\"",
"end",
"end"
] |
For anonymous classes method_added during task registration contains ""
for the class name. We adjust it here.
|
[
"For",
"anonymous",
"classes",
"method_added",
"during",
"task",
"registration",
"contains",
"for",
"the",
"class",
"name",
".",
"We",
"adjust",
"it",
"here",
"."
] |
46943a519224067e58aa3e2d5656e3ca083150f9
|
https://github.com/tongueroo/jets/blob/46943a519224067e58aa3e2d5656e3ca083150f9/lib/jets/lambda/function_constructor.rb#L45-L52
|
10,855
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/section.rb
|
GitHubChangelogGenerator.Section.generate_content
|
def generate_content
content = ""
if @issues.any?
content += "#{@prefix}\n\n" unless @options[:simple_list] || @prefix.blank?
@issues.each do |issue|
merge_string = get_string_for_issue(issue)
content += "- " unless @body_only
content += "#{merge_string}\n"
end
content += "\n"
end
content
end
|
ruby
|
def generate_content
content = ""
if @issues.any?
content += "#{@prefix}\n\n" unless @options[:simple_list] || @prefix.blank?
@issues.each do |issue|
merge_string = get_string_for_issue(issue)
content += "- " unless @body_only
content += "#{merge_string}\n"
end
content += "\n"
end
content
end
|
[
"def",
"generate_content",
"content",
"=",
"\"\"",
"if",
"@issues",
".",
"any?",
"content",
"+=",
"\"#{@prefix}\\n\\n\"",
"unless",
"@options",
"[",
":simple_list",
"]",
"||",
"@prefix",
".",
"blank?",
"@issues",
".",
"each",
"do",
"|",
"issue",
"|",
"merge_string",
"=",
"get_string_for_issue",
"(",
"issue",
")",
"content",
"+=",
"\"- \"",
"unless",
"@body_only",
"content",
"+=",
"\"#{merge_string}\\n\"",
"end",
"content",
"+=",
"\"\\n\"",
"end",
"content",
"end"
] |
Returns the content of a section.
@return [String] Generate section content
|
[
"Returns",
"the",
"content",
"of",
"a",
"section",
"."
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/section.rb#L24-L37
|
10,856
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/section.rb
|
GitHubChangelogGenerator.Section.get_string_for_issue
|
def get_string_for_issue(issue)
encapsulated_title = encapsulate_string issue["title"]
title_with_number = "#{encapsulated_title} [\\##{issue['number']}](#{issue['html_url']})"
title_with_number = "#{title_with_number}#{line_labels_for(issue)}" if @options[:issue_line_labels].present?
line = issue_line_with_user(title_with_number, issue)
issue_line_with_body(line, issue)
end
|
ruby
|
def get_string_for_issue(issue)
encapsulated_title = encapsulate_string issue["title"]
title_with_number = "#{encapsulated_title} [\\##{issue['number']}](#{issue['html_url']})"
title_with_number = "#{title_with_number}#{line_labels_for(issue)}" if @options[:issue_line_labels].present?
line = issue_line_with_user(title_with_number, issue)
issue_line_with_body(line, issue)
end
|
[
"def",
"get_string_for_issue",
"(",
"issue",
")",
"encapsulated_title",
"=",
"encapsulate_string",
"issue",
"[",
"\"title\"",
"]",
"title_with_number",
"=",
"\"#{encapsulated_title} [\\\\##{issue['number']}](#{issue['html_url']})\"",
"title_with_number",
"=",
"\"#{title_with_number}#{line_labels_for(issue)}\"",
"if",
"@options",
"[",
":issue_line_labels",
"]",
".",
"present?",
"line",
"=",
"issue_line_with_user",
"(",
"title_with_number",
",",
"issue",
")",
"issue_line_with_body",
"(",
"line",
",",
"issue",
")",
"end"
] |
Parse issue and generate single line formatted issue line.
Example output:
- Add coveralls integration [\#223](https://github.com/github-changelog-generator/github-changelog-generator/pull/223) (@github-changelog-generator)
@param [Hash] issue Fetched issue from GitHub
@return [String] Markdown-formatted single issue
|
[
"Parse",
"issue",
"and",
"generate",
"single",
"line",
"formatted",
"issue",
"line",
"."
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/section.rb#L48-L55
|
10,857
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/section.rb
|
GitHubChangelogGenerator.Section.encapsulate_string
|
def encapsulate_string(string)
string = string.gsub('\\', '\\\\')
ENCAPSULATED_CHARACTERS.each do |char|
string = string.gsub(char, "\\#{char}")
end
string
end
|
ruby
|
def encapsulate_string(string)
string = string.gsub('\\', '\\\\')
ENCAPSULATED_CHARACTERS.each do |char|
string = string.gsub(char, "\\#{char}")
end
string
end
|
[
"def",
"encapsulate_string",
"(",
"string",
")",
"string",
"=",
"string",
".",
"gsub",
"(",
"'\\\\'",
",",
"'\\\\\\\\'",
")",
"ENCAPSULATED_CHARACTERS",
".",
"each",
"do",
"|",
"char",
"|",
"string",
"=",
"string",
".",
"gsub",
"(",
"char",
",",
"\"\\\\#{char}\"",
")",
"end",
"string",
"end"
] |
Encapsulate characters to make Markdown look as expected.
@param [String] string
@return [String] encapsulated input string
|
[
"Encapsulate",
"characters",
"to",
"make",
"Markdown",
"look",
"as",
"expected",
"."
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/section.rb#L94-L102
|
10,858
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/generator_fetcher.rb
|
GitHubChangelogGenerator.Generator.fetch_tags_dates
|
def fetch_tags_dates(tags)
print "Fetching tag dates...\r" if options[:verbose]
i = 0
tags.each do |tag|
get_time_of_tag(tag)
i += 1
end
puts "Fetching tags dates: #{i}/#{tags.count}" if options[:verbose]
end
|
ruby
|
def fetch_tags_dates(tags)
print "Fetching tag dates...\r" if options[:verbose]
i = 0
tags.each do |tag|
get_time_of_tag(tag)
i += 1
end
puts "Fetching tags dates: #{i}/#{tags.count}" if options[:verbose]
end
|
[
"def",
"fetch_tags_dates",
"(",
"tags",
")",
"print",
"\"Fetching tag dates...\\r\"",
"if",
"options",
"[",
":verbose",
"]",
"i",
"=",
"0",
"tags",
".",
"each",
"do",
"|",
"tag",
"|",
"get_time_of_tag",
"(",
"tag",
")",
"i",
"+=",
"1",
"end",
"puts",
"\"Fetching tags dates: #{i}/#{tags.count}\"",
"if",
"options",
"[",
":verbose",
"]",
"end"
] |
Async fetching of all tags dates
|
[
"Async",
"fetching",
"of",
"all",
"tags",
"dates"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/generator_fetcher.rb#L17-L25
|
10,859
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/generator_fetcher.rb
|
GitHubChangelogGenerator.Generator.detect_actual_closed_dates
|
def detect_actual_closed_dates(issues)
print "Fetching closed dates for issues...\r" if options[:verbose]
i = 0
issues.each do |issue|
find_closed_date_by_commit(issue)
i += 1
end
puts "Fetching closed dates for issues: #{i}/#{issues.count}" if options[:verbose]
end
|
ruby
|
def detect_actual_closed_dates(issues)
print "Fetching closed dates for issues...\r" if options[:verbose]
i = 0
issues.each do |issue|
find_closed_date_by_commit(issue)
i += 1
end
puts "Fetching closed dates for issues: #{i}/#{issues.count}" if options[:verbose]
end
|
[
"def",
"detect_actual_closed_dates",
"(",
"issues",
")",
"print",
"\"Fetching closed dates for issues...\\r\"",
"if",
"options",
"[",
":verbose",
"]",
"i",
"=",
"0",
"issues",
".",
"each",
"do",
"|",
"issue",
"|",
"find_closed_date_by_commit",
"(",
"issue",
")",
"i",
"+=",
"1",
"end",
"puts",
"\"Fetching closed dates for issues: #{i}/#{issues.count}\"",
"if",
"options",
"[",
":verbose",
"]",
"end"
] |
Find correct closed dates, if issues was closed by commits
|
[
"Find",
"correct",
"closed",
"dates",
"if",
"issues",
"was",
"closed",
"by",
"commits"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/generator_fetcher.rb#L28-L37
|
10,860
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/generator_fetcher.rb
|
GitHubChangelogGenerator.Generator.add_first_occurring_tag_to_prs
|
def add_first_occurring_tag_to_prs(tags, prs)
total = prs.count
prs_left = associate_tagged_prs(tags, prs, total)
prs_left = associate_release_branch_prs(prs_left, total)
prs_left = associate_rebase_comment_prs(tags, prs_left, total) if prs_left.any?
# PRs in prs_left will be untagged, not in release branch, and not
# rebased. They should not be included in the changelog as they probably
# have been merged to a branch other than the release branch.
@pull_requests -= prs_left
Helper.log.info "Associating PRs with tags: #{total}/#{total}"
end
|
ruby
|
def add_first_occurring_tag_to_prs(tags, prs)
total = prs.count
prs_left = associate_tagged_prs(tags, prs, total)
prs_left = associate_release_branch_prs(prs_left, total)
prs_left = associate_rebase_comment_prs(tags, prs_left, total) if prs_left.any?
# PRs in prs_left will be untagged, not in release branch, and not
# rebased. They should not be included in the changelog as they probably
# have been merged to a branch other than the release branch.
@pull_requests -= prs_left
Helper.log.info "Associating PRs with tags: #{total}/#{total}"
end
|
[
"def",
"add_first_occurring_tag_to_prs",
"(",
"tags",
",",
"prs",
")",
"total",
"=",
"prs",
".",
"count",
"prs_left",
"=",
"associate_tagged_prs",
"(",
"tags",
",",
"prs",
",",
"total",
")",
"prs_left",
"=",
"associate_release_branch_prs",
"(",
"prs_left",
",",
"total",
")",
"prs_left",
"=",
"associate_rebase_comment_prs",
"(",
"tags",
",",
"prs_left",
",",
"total",
")",
"if",
"prs_left",
".",
"any?",
"# PRs in prs_left will be untagged, not in release branch, and not",
"# rebased. They should not be included in the changelog as they probably",
"# have been merged to a branch other than the release branch.",
"@pull_requests",
"-=",
"prs_left",
"Helper",
".",
"log",
".",
"info",
"\"Associating PRs with tags: #{total}/#{total}\"",
"end"
] |
Adds a key "first_occurring_tag" to each PR with a value of the oldest
tag that a PR's merge commit occurs in in the git history. This should
indicate the release of each PR by git's history regardless of dates and
divergent branches.
@param [Array] tags The tags sorted by time, newest to oldest.
@param [Array] prs The PRs to discover the tags of.
@return [Nil] No return; PRs are updated in-place.
|
[
"Adds",
"a",
"key",
"first_occurring_tag",
"to",
"each",
"PR",
"with",
"a",
"value",
"of",
"the",
"oldest",
"tag",
"that",
"a",
"PR",
"s",
"merge",
"commit",
"occurs",
"in",
"in",
"the",
"git",
"history",
".",
"This",
"should",
"indicate",
"the",
"release",
"of",
"each",
"PR",
"by",
"git",
"s",
"history",
"regardless",
"of",
"dates",
"and",
"divergent",
"branches",
"."
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/generator_fetcher.rb#L47-L58
|
10,861
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/generator_fetcher.rb
|
GitHubChangelogGenerator.Generator.associate_tagged_prs
|
def associate_tagged_prs(tags, prs, total)
@fetcher.fetch_tag_shas_async(tags)
i = 0
prs.reject do |pr|
found = false
# XXX Wish I could use merge_commit_sha, but gcg doesn't currently
# fetch that. See
# https://developer.github.com/v3/pulls/#get-a-single-pull-request vs.
# https://developer.github.com/v3/pulls/#list-pull-requests
if pr["events"] && (event = pr["events"].find { |e| e["event"] == "merged" })
# Iterate tags.reverse (oldest to newest) to find first tag of each PR.
if (oldest_tag = tags.reverse.find { |tag| tag["shas_in_tag"].include?(event["commit_id"]) })
pr["first_occurring_tag"] = oldest_tag["name"]
found = true
i += 1
print("Associating PRs with tags: #{i}/#{total}\r") if @options[:verbose]
end
else
# Either there were no events or no merged event. Github's api can be
# weird like that apparently. Check for a rebased comment before erroring.
no_events_pr = associate_rebase_comment_prs(tags, [pr], total)
raise StandardError, "No merge sha found for PR #{pr['number']} via the GitHub API" unless no_events_pr.empty?
found = true
i += 1
print("Associating PRs with tags: #{i}/#{total}\r") if @options[:verbose]
end
found
end
end
|
ruby
|
def associate_tagged_prs(tags, prs, total)
@fetcher.fetch_tag_shas_async(tags)
i = 0
prs.reject do |pr|
found = false
# XXX Wish I could use merge_commit_sha, but gcg doesn't currently
# fetch that. See
# https://developer.github.com/v3/pulls/#get-a-single-pull-request vs.
# https://developer.github.com/v3/pulls/#list-pull-requests
if pr["events"] && (event = pr["events"].find { |e| e["event"] == "merged" })
# Iterate tags.reverse (oldest to newest) to find first tag of each PR.
if (oldest_tag = tags.reverse.find { |tag| tag["shas_in_tag"].include?(event["commit_id"]) })
pr["first_occurring_tag"] = oldest_tag["name"]
found = true
i += 1
print("Associating PRs with tags: #{i}/#{total}\r") if @options[:verbose]
end
else
# Either there were no events or no merged event. Github's api can be
# weird like that apparently. Check for a rebased comment before erroring.
no_events_pr = associate_rebase_comment_prs(tags, [pr], total)
raise StandardError, "No merge sha found for PR #{pr['number']} via the GitHub API" unless no_events_pr.empty?
found = true
i += 1
print("Associating PRs with tags: #{i}/#{total}\r") if @options[:verbose]
end
found
end
end
|
[
"def",
"associate_tagged_prs",
"(",
"tags",
",",
"prs",
",",
"total",
")",
"@fetcher",
".",
"fetch_tag_shas_async",
"(",
"tags",
")",
"i",
"=",
"0",
"prs",
".",
"reject",
"do",
"|",
"pr",
"|",
"found",
"=",
"false",
"# XXX Wish I could use merge_commit_sha, but gcg doesn't currently",
"# fetch that. See",
"# https://developer.github.com/v3/pulls/#get-a-single-pull-request vs.",
"# https://developer.github.com/v3/pulls/#list-pull-requests",
"if",
"pr",
"[",
"\"events\"",
"]",
"&&",
"(",
"event",
"=",
"pr",
"[",
"\"events\"",
"]",
".",
"find",
"{",
"|",
"e",
"|",
"e",
"[",
"\"event\"",
"]",
"==",
"\"merged\"",
"}",
")",
"# Iterate tags.reverse (oldest to newest) to find first tag of each PR.",
"if",
"(",
"oldest_tag",
"=",
"tags",
".",
"reverse",
".",
"find",
"{",
"|",
"tag",
"|",
"tag",
"[",
"\"shas_in_tag\"",
"]",
".",
"include?",
"(",
"event",
"[",
"\"commit_id\"",
"]",
")",
"}",
")",
"pr",
"[",
"\"first_occurring_tag\"",
"]",
"=",
"oldest_tag",
"[",
"\"name\"",
"]",
"found",
"=",
"true",
"i",
"+=",
"1",
"print",
"(",
"\"Associating PRs with tags: #{i}/#{total}\\r\"",
")",
"if",
"@options",
"[",
":verbose",
"]",
"end",
"else",
"# Either there were no events or no merged event. Github's api can be",
"# weird like that apparently. Check for a rebased comment before erroring.",
"no_events_pr",
"=",
"associate_rebase_comment_prs",
"(",
"tags",
",",
"[",
"pr",
"]",
",",
"total",
")",
"raise",
"StandardError",
",",
"\"No merge sha found for PR #{pr['number']} via the GitHub API\"",
"unless",
"no_events_pr",
".",
"empty?",
"found",
"=",
"true",
"i",
"+=",
"1",
"print",
"(",
"\"Associating PRs with tags: #{i}/#{total}\\r\"",
")",
"if",
"@options",
"[",
":verbose",
"]",
"end",
"found",
"end",
"end"
] |
Associate merged PRs by the merge SHA contained in each tag. If the
merge_commit_sha is not found in any tag's history, skip association.
@param [Array] tags The tags sorted by time, newest to oldest.
@param [Array] prs The PRs to associate.
@return [Array] PRs without their merge_commit_sha in a tag.
|
[
"Associate",
"merged",
"PRs",
"by",
"the",
"merge",
"SHA",
"contained",
"in",
"each",
"tag",
".",
"If",
"the",
"merge_commit_sha",
"is",
"not",
"found",
"in",
"any",
"tag",
"s",
"history",
"skip",
"association",
"."
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/generator_fetcher.rb#L66-L96
|
10,862
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/generator_fetcher.rb
|
GitHubChangelogGenerator.Generator.set_date_from_event
|
def set_date_from_event(event, issue)
if event["commit_id"].nil?
issue["actual_date"] = issue["closed_at"]
else
begin
commit = @fetcher.fetch_commit(event["commit_id"])
issue["actual_date"] = commit["commit"]["author"]["date"]
# issue['actual_date'] = commit['author']['date']
rescue StandardError
puts "Warning: Can't fetch commit #{event['commit_id']}. It is probably referenced from another repo."
issue["actual_date"] = issue["closed_at"]
end
end
end
|
ruby
|
def set_date_from_event(event, issue)
if event["commit_id"].nil?
issue["actual_date"] = issue["closed_at"]
else
begin
commit = @fetcher.fetch_commit(event["commit_id"])
issue["actual_date"] = commit["commit"]["author"]["date"]
# issue['actual_date'] = commit['author']['date']
rescue StandardError
puts "Warning: Can't fetch commit #{event['commit_id']}. It is probably referenced from another repo."
issue["actual_date"] = issue["closed_at"]
end
end
end
|
[
"def",
"set_date_from_event",
"(",
"event",
",",
"issue",
")",
"if",
"event",
"[",
"\"commit_id\"",
"]",
".",
"nil?",
"issue",
"[",
"\"actual_date\"",
"]",
"=",
"issue",
"[",
"\"closed_at\"",
"]",
"else",
"begin",
"commit",
"=",
"@fetcher",
".",
"fetch_commit",
"(",
"event",
"[",
"\"commit_id\"",
"]",
")",
"issue",
"[",
"\"actual_date\"",
"]",
"=",
"commit",
"[",
"\"commit\"",
"]",
"[",
"\"author\"",
"]",
"[",
"\"date\"",
"]",
"# issue['actual_date'] = commit['author']['date']",
"rescue",
"StandardError",
"puts",
"\"Warning: Can't fetch commit #{event['commit_id']}. It is probably referenced from another repo.\"",
"issue",
"[",
"\"actual_date\"",
"]",
"=",
"issue",
"[",
"\"closed_at\"",
"]",
"end",
"end",
"end"
] |
Set closed date from this issue
@param [Hash] event
@param [Hash] issue
|
[
"Set",
"closed",
"date",
"from",
"this",
"issue"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/generator_fetcher.rb#L177-L191
|
10,863
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/octo_fetcher.rb
|
GitHubChangelogGenerator.OctoFetcher.calculate_pages
|
def calculate_pages(client, method, request_options)
# Makes the first API call so that we can call last_response
check_github_response do
client.send(method, user_project, DEFAULT_REQUEST_OPTIONS.merge(request_options))
end
last_response = client.last_response
if (last_pg = last_response.rels[:last])
querystring_as_hash(last_pg.href)["page"].to_i
else
1
end
end
|
ruby
|
def calculate_pages(client, method, request_options)
# Makes the first API call so that we can call last_response
check_github_response do
client.send(method, user_project, DEFAULT_REQUEST_OPTIONS.merge(request_options))
end
last_response = client.last_response
if (last_pg = last_response.rels[:last])
querystring_as_hash(last_pg.href)["page"].to_i
else
1
end
end
|
[
"def",
"calculate_pages",
"(",
"client",
",",
"method",
",",
"request_options",
")",
"# Makes the first API call so that we can call last_response",
"check_github_response",
"do",
"client",
".",
"send",
"(",
"method",
",",
"user_project",
",",
"DEFAULT_REQUEST_OPTIONS",
".",
"merge",
"(",
"request_options",
")",
")",
"end",
"last_response",
"=",
"client",
".",
"last_response",
"if",
"(",
"last_pg",
"=",
"last_response",
".",
"rels",
"[",
":last",
"]",
")",
"querystring_as_hash",
"(",
"last_pg",
".",
"href",
")",
"[",
"\"page\"",
"]",
".",
"to_i",
"else",
"1",
"end",
"end"
] |
Returns the number of pages for a API call
@return [Integer] number of pages for this API call in total
|
[
"Returns",
"the",
"number",
"of",
"pages",
"for",
"a",
"API",
"call"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/octo_fetcher.rb#L91-L104
|
10,864
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/octo_fetcher.rb
|
GitHubChangelogGenerator.OctoFetcher.github_fetch_tags
|
def github_fetch_tags
tags = []
page_i = 0
count_pages = calculate_pages(@client, "tags", {})
iterate_pages(@client, "tags") do |new_tags|
page_i += PER_PAGE_NUMBER
print_in_same_line("Fetching tags... #{page_i}/#{count_pages * PER_PAGE_NUMBER}")
tags.concat(new_tags)
end
print_empty_line
if tags.count == 0
Helper.log.warn "Warning: Can't find any tags in repo. \
Make sure, that you push tags to remote repo via 'git push --tags'"
else
Helper.log.info "Found #{tags.count} tags"
end
# tags are a Sawyer::Resource. Convert to hash
tags.map { |resource| stringify_keys_deep(resource.to_hash) }
end
|
ruby
|
def github_fetch_tags
tags = []
page_i = 0
count_pages = calculate_pages(@client, "tags", {})
iterate_pages(@client, "tags") do |new_tags|
page_i += PER_PAGE_NUMBER
print_in_same_line("Fetching tags... #{page_i}/#{count_pages * PER_PAGE_NUMBER}")
tags.concat(new_tags)
end
print_empty_line
if tags.count == 0
Helper.log.warn "Warning: Can't find any tags in repo. \
Make sure, that you push tags to remote repo via 'git push --tags'"
else
Helper.log.info "Found #{tags.count} tags"
end
# tags are a Sawyer::Resource. Convert to hash
tags.map { |resource| stringify_keys_deep(resource.to_hash) }
end
|
[
"def",
"github_fetch_tags",
"tags",
"=",
"[",
"]",
"page_i",
"=",
"0",
"count_pages",
"=",
"calculate_pages",
"(",
"@client",
",",
"\"tags\"",
",",
"{",
"}",
")",
"iterate_pages",
"(",
"@client",
",",
"\"tags\"",
")",
"do",
"|",
"new_tags",
"|",
"page_i",
"+=",
"PER_PAGE_NUMBER",
"print_in_same_line",
"(",
"\"Fetching tags... #{page_i}/#{count_pages * PER_PAGE_NUMBER}\"",
")",
"tags",
".",
"concat",
"(",
"new_tags",
")",
"end",
"print_empty_line",
"if",
"tags",
".",
"count",
"==",
"0",
"Helper",
".",
"log",
".",
"warn",
"\"Warning: Can't find any tags in repo. \\\nMake sure, that you push tags to remote repo via 'git push --tags'\"",
"else",
"Helper",
".",
"log",
".",
"info",
"\"Found #{tags.count} tags\"",
"end",
"# tags are a Sawyer::Resource. Convert to hash",
"tags",
".",
"map",
"{",
"|",
"resource",
"|",
"stringify_keys_deep",
"(",
"resource",
".",
"to_hash",
")",
"}",
"end"
] |
Fill input array with tags
@return [Array <Hash>] array of tags in repo
|
[
"Fill",
"input",
"array",
"with",
"tags"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/octo_fetcher.rb#L109-L129
|
10,865
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/octo_fetcher.rb
|
GitHubChangelogGenerator.OctoFetcher.fetch_events_async
|
def fetch_events_async(issues)
i = 0
threads = []
issues.each_slice(MAX_THREAD_NUMBER) do |issues_slice|
issues_slice.each do |issue|
threads << Thread.new do
issue["events"] = []
iterate_pages(@client, "issue_events", issue["number"]) do |new_event|
issue["events"].concat(new_event)
end
issue["events"] = issue["events"].map { |event| stringify_keys_deep(event.to_hash) }
print_in_same_line("Fetching events for issues and PR: #{i + 1}/#{issues.count}")
i += 1
end
end
threads.each(&:join)
threads = []
end
# to clear line from prev print
print_empty_line
Helper.log.info "Fetching events for issues and PR: #{i}"
end
|
ruby
|
def fetch_events_async(issues)
i = 0
threads = []
issues.each_slice(MAX_THREAD_NUMBER) do |issues_slice|
issues_slice.each do |issue|
threads << Thread.new do
issue["events"] = []
iterate_pages(@client, "issue_events", issue["number"]) do |new_event|
issue["events"].concat(new_event)
end
issue["events"] = issue["events"].map { |event| stringify_keys_deep(event.to_hash) }
print_in_same_line("Fetching events for issues and PR: #{i + 1}/#{issues.count}")
i += 1
end
end
threads.each(&:join)
threads = []
end
# to clear line from prev print
print_empty_line
Helper.log.info "Fetching events for issues and PR: #{i}"
end
|
[
"def",
"fetch_events_async",
"(",
"issues",
")",
"i",
"=",
"0",
"threads",
"=",
"[",
"]",
"issues",
".",
"each_slice",
"(",
"MAX_THREAD_NUMBER",
")",
"do",
"|",
"issues_slice",
"|",
"issues_slice",
".",
"each",
"do",
"|",
"issue",
"|",
"threads",
"<<",
"Thread",
".",
"new",
"do",
"issue",
"[",
"\"events\"",
"]",
"=",
"[",
"]",
"iterate_pages",
"(",
"@client",
",",
"\"issue_events\"",
",",
"issue",
"[",
"\"number\"",
"]",
")",
"do",
"|",
"new_event",
"|",
"issue",
"[",
"\"events\"",
"]",
".",
"concat",
"(",
"new_event",
")",
"end",
"issue",
"[",
"\"events\"",
"]",
"=",
"issue",
"[",
"\"events\"",
"]",
".",
"map",
"{",
"|",
"event",
"|",
"stringify_keys_deep",
"(",
"event",
".",
"to_hash",
")",
"}",
"print_in_same_line",
"(",
"\"Fetching events for issues and PR: #{i + 1}/#{issues.count}\"",
")",
"i",
"+=",
"1",
"end",
"end",
"threads",
".",
"each",
"(",
":join",
")",
"threads",
"=",
"[",
"]",
"end",
"# to clear line from prev print",
"print_empty_line",
"Helper",
".",
"log",
".",
"info",
"\"Fetching events for issues and PR: #{i}\"",
"end"
] |
Fetch event for all issues and add them to 'events'
@param [Array] issues
@return [Void]
|
[
"Fetch",
"event",
"for",
"all",
"issues",
"and",
"add",
"them",
"to",
"events"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/octo_fetcher.rb#L187-L211
|
10,866
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/octo_fetcher.rb
|
GitHubChangelogGenerator.OctoFetcher.fetch_comments_async
|
def fetch_comments_async(prs)
threads = []
prs.each_slice(MAX_THREAD_NUMBER) do |prs_slice|
prs_slice.each do |pr|
threads << Thread.new do
pr["comments"] = []
iterate_pages(@client, "issue_comments", pr["number"]) do |new_comment|
pr["comments"].concat(new_comment)
end
pr["comments"] = pr["comments"].map { |comment| stringify_keys_deep(comment.to_hash) }
end
end
threads.each(&:join)
threads = []
end
nil
end
|
ruby
|
def fetch_comments_async(prs)
threads = []
prs.each_slice(MAX_THREAD_NUMBER) do |prs_slice|
prs_slice.each do |pr|
threads << Thread.new do
pr["comments"] = []
iterate_pages(@client, "issue_comments", pr["number"]) do |new_comment|
pr["comments"].concat(new_comment)
end
pr["comments"] = pr["comments"].map { |comment| stringify_keys_deep(comment.to_hash) }
end
end
threads.each(&:join)
threads = []
end
nil
end
|
[
"def",
"fetch_comments_async",
"(",
"prs",
")",
"threads",
"=",
"[",
"]",
"prs",
".",
"each_slice",
"(",
"MAX_THREAD_NUMBER",
")",
"do",
"|",
"prs_slice",
"|",
"prs_slice",
".",
"each",
"do",
"|",
"pr",
"|",
"threads",
"<<",
"Thread",
".",
"new",
"do",
"pr",
"[",
"\"comments\"",
"]",
"=",
"[",
"]",
"iterate_pages",
"(",
"@client",
",",
"\"issue_comments\"",
",",
"pr",
"[",
"\"number\"",
"]",
")",
"do",
"|",
"new_comment",
"|",
"pr",
"[",
"\"comments\"",
"]",
".",
"concat",
"(",
"new_comment",
")",
"end",
"pr",
"[",
"\"comments\"",
"]",
"=",
"pr",
"[",
"\"comments\"",
"]",
".",
"map",
"{",
"|",
"comment",
"|",
"stringify_keys_deep",
"(",
"comment",
".",
"to_hash",
")",
"}",
"end",
"end",
"threads",
".",
"each",
"(",
":join",
")",
"threads",
"=",
"[",
"]",
"end",
"nil",
"end"
] |
Fetch comments for PRs and add them to "comments"
@param [Array] prs The array of PRs.
@return [Void] No return; PRs are updated in-place.
|
[
"Fetch",
"comments",
"for",
"PRs",
"and",
"add",
"them",
"to",
"comments"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/octo_fetcher.rb#L217-L234
|
10,867
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/octo_fetcher.rb
|
GitHubChangelogGenerator.OctoFetcher.fetch_date_of_tag
|
def fetch_date_of_tag(tag)
commit_data = fetch_commit(tag["commit"]["sha"])
commit_data = stringify_keys_deep(commit_data.to_hash)
commit_data["commit"]["committer"]["date"]
end
|
ruby
|
def fetch_date_of_tag(tag)
commit_data = fetch_commit(tag["commit"]["sha"])
commit_data = stringify_keys_deep(commit_data.to_hash)
commit_data["commit"]["committer"]["date"]
end
|
[
"def",
"fetch_date_of_tag",
"(",
"tag",
")",
"commit_data",
"=",
"fetch_commit",
"(",
"tag",
"[",
"\"commit\"",
"]",
"[",
"\"sha\"",
"]",
")",
"commit_data",
"=",
"stringify_keys_deep",
"(",
"commit_data",
".",
"to_hash",
")",
"commit_data",
"[",
"\"commit\"",
"]",
"[",
"\"committer\"",
"]",
"[",
"\"date\"",
"]",
"end"
] |
Fetch tag time from repo
@param [Hash] tag GitHub data item about a Tag
@return [Time] time of specified tag
|
[
"Fetch",
"tag",
"time",
"from",
"repo"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/octo_fetcher.rb#L241-L246
|
10,868
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/octo_fetcher.rb
|
GitHubChangelogGenerator.OctoFetcher.fetch_compare
|
def fetch_compare(older, newer)
unless @compares["#{older}...#{newer}"]
compare_data = check_github_response { @client.compare(user_project, older, newer || "HEAD") }
raise StandardError, "Sha #{older} and sha #{newer} are not related; please file a github-changelog-generator issues and describe how to replicate this issue." if compare_data["status"] == "diverged"
@compares["#{older}...#{newer}"] = stringify_keys_deep(compare_data.to_hash)
end
@compares["#{older}...#{newer}"]
end
|
ruby
|
def fetch_compare(older, newer)
unless @compares["#{older}...#{newer}"]
compare_data = check_github_response { @client.compare(user_project, older, newer || "HEAD") }
raise StandardError, "Sha #{older} and sha #{newer} are not related; please file a github-changelog-generator issues and describe how to replicate this issue." if compare_data["status"] == "diverged"
@compares["#{older}...#{newer}"] = stringify_keys_deep(compare_data.to_hash)
end
@compares["#{older}...#{newer}"]
end
|
[
"def",
"fetch_compare",
"(",
"older",
",",
"newer",
")",
"unless",
"@compares",
"[",
"\"#{older}...#{newer}\"",
"]",
"compare_data",
"=",
"check_github_response",
"{",
"@client",
".",
"compare",
"(",
"user_project",
",",
"older",
",",
"newer",
"||",
"\"HEAD\"",
")",
"}",
"raise",
"StandardError",
",",
"\"Sha #{older} and sha #{newer} are not related; please file a github-changelog-generator issues and describe how to replicate this issue.\"",
"if",
"compare_data",
"[",
"\"status\"",
"]",
"==",
"\"diverged\"",
"@compares",
"[",
"\"#{older}...#{newer}\"",
"]",
"=",
"stringify_keys_deep",
"(",
"compare_data",
".",
"to_hash",
")",
"end",
"@compares",
"[",
"\"#{older}...#{newer}\"",
"]",
"end"
] |
Fetch and cache comparison between two github refs
@param [String] older The older sha/tag/branch.
@param [String] newer The newer sha/tag/branch.
@return [Hash] Github api response for comparison.
|
[
"Fetch",
"and",
"cache",
"comparison",
"between",
"two",
"github",
"refs"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/octo_fetcher.rb#L253-L261
|
10,869
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/octo_fetcher.rb
|
GitHubChangelogGenerator.OctoFetcher.fetch_commit
|
def fetch_commit(commit_id)
found = commits.find do |commit|
commit["sha"] == commit_id
end
if found
stringify_keys_deep(found.to_hash)
else
# cache miss; don't add to @commits because unsure of order.
check_github_response do
commit = @client.commit(user_project, commit_id)
commit = stringify_keys_deep(commit.to_hash)
commit
end
end
end
|
ruby
|
def fetch_commit(commit_id)
found = commits.find do |commit|
commit["sha"] == commit_id
end
if found
stringify_keys_deep(found.to_hash)
else
# cache miss; don't add to @commits because unsure of order.
check_github_response do
commit = @client.commit(user_project, commit_id)
commit = stringify_keys_deep(commit.to_hash)
commit
end
end
end
|
[
"def",
"fetch_commit",
"(",
"commit_id",
")",
"found",
"=",
"commits",
".",
"find",
"do",
"|",
"commit",
"|",
"commit",
"[",
"\"sha\"",
"]",
"==",
"commit_id",
"end",
"if",
"found",
"stringify_keys_deep",
"(",
"found",
".",
"to_hash",
")",
"else",
"# cache miss; don't add to @commits because unsure of order.",
"check_github_response",
"do",
"commit",
"=",
"@client",
".",
"commit",
"(",
"user_project",
",",
"commit_id",
")",
"commit",
"=",
"stringify_keys_deep",
"(",
"commit",
".",
"to_hash",
")",
"commit",
"end",
"end",
"end"
] |
Fetch commit for specified event
@param [String] commit_id the SHA of a commit to fetch
@return [Hash]
|
[
"Fetch",
"commit",
"for",
"specified",
"event"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/octo_fetcher.rb#L267-L281
|
10,870
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/octo_fetcher.rb
|
GitHubChangelogGenerator.OctoFetcher.fetch_tag_shas_async
|
def fetch_tag_shas_async(tags)
i = 0
threads = []
print_in_same_line("Fetching SHAs for tags: #{i}/#{tags.count}\r") if @options[:verbose]
tags.each_slice(MAX_THREAD_NUMBER) do |tags_slice|
tags_slice.each do |tag|
threads << Thread.new do
# Use oldest commit because comparing two arbitrary tags may be diverged
commits_in_tag = fetch_compare(oldest_commit["sha"], tag["name"])
tag["shas_in_tag"] = commits_in_tag["commits"].collect { |commit| commit["sha"] }
print_in_same_line("Fetching SHAs for tags: #{i + 1}/#{tags.count}") if @options[:verbose]
i += 1
end
end
threads.each(&:join)
threads = []
end
# to clear line from prev print
print_empty_line
Helper.log.info "Fetching SHAs for tags: #{i}"
nil
end
|
ruby
|
def fetch_tag_shas_async(tags)
i = 0
threads = []
print_in_same_line("Fetching SHAs for tags: #{i}/#{tags.count}\r") if @options[:verbose]
tags.each_slice(MAX_THREAD_NUMBER) do |tags_slice|
tags_slice.each do |tag|
threads << Thread.new do
# Use oldest commit because comparing two arbitrary tags may be diverged
commits_in_tag = fetch_compare(oldest_commit["sha"], tag["name"])
tag["shas_in_tag"] = commits_in_tag["commits"].collect { |commit| commit["sha"] }
print_in_same_line("Fetching SHAs for tags: #{i + 1}/#{tags.count}") if @options[:verbose]
i += 1
end
end
threads.each(&:join)
threads = []
end
# to clear line from prev print
print_empty_line
Helper.log.info "Fetching SHAs for tags: #{i}"
nil
end
|
[
"def",
"fetch_tag_shas_async",
"(",
"tags",
")",
"i",
"=",
"0",
"threads",
"=",
"[",
"]",
"print_in_same_line",
"(",
"\"Fetching SHAs for tags: #{i}/#{tags.count}\\r\"",
")",
"if",
"@options",
"[",
":verbose",
"]",
"tags",
".",
"each_slice",
"(",
"MAX_THREAD_NUMBER",
")",
"do",
"|",
"tags_slice",
"|",
"tags_slice",
".",
"each",
"do",
"|",
"tag",
"|",
"threads",
"<<",
"Thread",
".",
"new",
"do",
"# Use oldest commit because comparing two arbitrary tags may be diverged",
"commits_in_tag",
"=",
"fetch_compare",
"(",
"oldest_commit",
"[",
"\"sha\"",
"]",
",",
"tag",
"[",
"\"name\"",
"]",
")",
"tag",
"[",
"\"shas_in_tag\"",
"]",
"=",
"commits_in_tag",
"[",
"\"commits\"",
"]",
".",
"collect",
"{",
"|",
"commit",
"|",
"commit",
"[",
"\"sha\"",
"]",
"}",
"print_in_same_line",
"(",
"\"Fetching SHAs for tags: #{i + 1}/#{tags.count}\"",
")",
"if",
"@options",
"[",
":verbose",
"]",
"i",
"+=",
"1",
"end",
"end",
"threads",
".",
"each",
"(",
":join",
")",
"threads",
"=",
"[",
"]",
"end",
"# to clear line from prev print",
"print_empty_line",
"Helper",
".",
"log",
".",
"info",
"\"Fetching SHAs for tags: #{i}\"",
"nil",
"end"
] |
Fetch all SHAs occurring in or before a given tag and add them to
"shas_in_tag"
@param [Array] tags The array of tags.
@return [Nil] No return; tags are updated in-place.
|
[
"Fetch",
"all",
"SHAs",
"occurring",
"in",
"or",
"before",
"a",
"given",
"tag",
"and",
"add",
"them",
"to",
"shas_in_tag"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/octo_fetcher.rb#L312-L336
|
10,871
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/octo_fetcher.rb
|
GitHubChangelogGenerator.OctoFetcher.check_github_response
|
def check_github_response
Retriable.retriable(retry_options) do
yield
end
rescue MovedPermanentlyError => e
fail_with_message(e, "The repository has moved, update your configuration")
rescue Octokit::Forbidden => e
fail_with_message(e, "Exceeded retry limit")
rescue Octokit::Unauthorized => e
fail_with_message(e, "Error: wrong GitHub token")
end
|
ruby
|
def check_github_response
Retriable.retriable(retry_options) do
yield
end
rescue MovedPermanentlyError => e
fail_with_message(e, "The repository has moved, update your configuration")
rescue Octokit::Forbidden => e
fail_with_message(e, "Exceeded retry limit")
rescue Octokit::Unauthorized => e
fail_with_message(e, "Error: wrong GitHub token")
end
|
[
"def",
"check_github_response",
"Retriable",
".",
"retriable",
"(",
"retry_options",
")",
"do",
"yield",
"end",
"rescue",
"MovedPermanentlyError",
"=>",
"e",
"fail_with_message",
"(",
"e",
",",
"\"The repository has moved, update your configuration\"",
")",
"rescue",
"Octokit",
"::",
"Forbidden",
"=>",
"e",
"fail_with_message",
"(",
"e",
",",
"\"Exceeded retry limit\"",
")",
"rescue",
"Octokit",
"::",
"Unauthorized",
"=>",
"e",
"fail_with_message",
"(",
"e",
",",
"\"Error: wrong GitHub token\"",
")",
"end"
] |
This is wrapper with rescue block
@return [Object] returns exactly the same, what you put in the block, but wrap it with begin-rescue block
|
[
"This",
"is",
"wrapper",
"with",
"rescue",
"block"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/octo_fetcher.rb#L396-L406
|
10,872
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/generator_tags.rb
|
GitHubChangelogGenerator.Generator.fetch_and_filter_tags
|
def fetch_and_filter_tags
since_tag
due_tag
all_tags = @fetcher.get_all_tags
fetch_tags_dates(all_tags) # Creates a Hash @tag_times_hash
all_sorted_tags = sort_tags_by_date(all_tags)
@sorted_tags = filter_excluded_tags(all_sorted_tags)
@filtered_tags = get_filtered_tags(@sorted_tags)
# Because we need to properly create compare links, we need a sorted list
# of all filtered tags (including the excluded ones). We'll exclude those
# tags from section headers inside the mapping function.
section_tags = get_filtered_tags(all_sorted_tags)
@tag_section_mapping = build_tag_section_mapping(section_tags, @filtered_tags)
@filtered_tags
end
|
ruby
|
def fetch_and_filter_tags
since_tag
due_tag
all_tags = @fetcher.get_all_tags
fetch_tags_dates(all_tags) # Creates a Hash @tag_times_hash
all_sorted_tags = sort_tags_by_date(all_tags)
@sorted_tags = filter_excluded_tags(all_sorted_tags)
@filtered_tags = get_filtered_tags(@sorted_tags)
# Because we need to properly create compare links, we need a sorted list
# of all filtered tags (including the excluded ones). We'll exclude those
# tags from section headers inside the mapping function.
section_tags = get_filtered_tags(all_sorted_tags)
@tag_section_mapping = build_tag_section_mapping(section_tags, @filtered_tags)
@filtered_tags
end
|
[
"def",
"fetch_and_filter_tags",
"since_tag",
"due_tag",
"all_tags",
"=",
"@fetcher",
".",
"get_all_tags",
"fetch_tags_dates",
"(",
"all_tags",
")",
"# Creates a Hash @tag_times_hash",
"all_sorted_tags",
"=",
"sort_tags_by_date",
"(",
"all_tags",
")",
"@sorted_tags",
"=",
"filter_excluded_tags",
"(",
"all_sorted_tags",
")",
"@filtered_tags",
"=",
"get_filtered_tags",
"(",
"@sorted_tags",
")",
"# Because we need to properly create compare links, we need a sorted list",
"# of all filtered tags (including the excluded ones). We'll exclude those",
"# tags from section headers inside the mapping function.",
"section_tags",
"=",
"get_filtered_tags",
"(",
"all_sorted_tags",
")",
"@tag_section_mapping",
"=",
"build_tag_section_mapping",
"(",
"section_tags",
",",
"@filtered_tags",
")",
"@filtered_tags",
"end"
] |
fetch, filter tags, fetch dates and sort them in time order
|
[
"fetch",
"filter",
"tags",
"fetch",
"dates",
"and",
"sort",
"them",
"in",
"time",
"order"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/generator_tags.rb#L6-L25
|
10,873
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/generator_tags.rb
|
GitHubChangelogGenerator.Generator.get_time_of_tag
|
def get_time_of_tag(tag_name)
raise ChangelogGeneratorError, "tag_name is nil" if tag_name.nil?
name_of_tag = tag_name.fetch("name")
time_for_tag_name = @tag_times_hash[name_of_tag]
return time_for_tag_name if time_for_tag_name
@fetcher.fetch_date_of_tag(tag_name).tap do |time_string|
@tag_times_hash[name_of_tag] = time_string
end
end
|
ruby
|
def get_time_of_tag(tag_name)
raise ChangelogGeneratorError, "tag_name is nil" if tag_name.nil?
name_of_tag = tag_name.fetch("name")
time_for_tag_name = @tag_times_hash[name_of_tag]
return time_for_tag_name if time_for_tag_name
@fetcher.fetch_date_of_tag(tag_name).tap do |time_string|
@tag_times_hash[name_of_tag] = time_string
end
end
|
[
"def",
"get_time_of_tag",
"(",
"tag_name",
")",
"raise",
"ChangelogGeneratorError",
",",
"\"tag_name is nil\"",
"if",
"tag_name",
".",
"nil?",
"name_of_tag",
"=",
"tag_name",
".",
"fetch",
"(",
"\"name\"",
")",
"time_for_tag_name",
"=",
"@tag_times_hash",
"[",
"name_of_tag",
"]",
"return",
"time_for_tag_name",
"if",
"time_for_tag_name",
"@fetcher",
".",
"fetch_date_of_tag",
"(",
"tag_name",
")",
".",
"tap",
"do",
"|",
"time_string",
"|",
"@tag_times_hash",
"[",
"name_of_tag",
"]",
"=",
"time_string",
"end",
"end"
] |
Returns date for given GitHub Tag hash
Memoize the date by tag name.
@param [Hash] tag_name
@return [Time] time of specified tag
|
[
"Returns",
"date",
"for",
"given",
"GitHub",
"Tag",
"hash"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/generator_tags.rb#L68-L78
|
10,874
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/generator_tags.rb
|
GitHubChangelogGenerator.Generator.detect_link_tag_time
|
def detect_link_tag_time(newer_tag)
# if tag is nil - set current time
newer_tag_time = newer_tag.nil? ? Time.new : get_time_of_tag(newer_tag)
# if it's future release tag - set this value
if newer_tag.nil? && options[:future_release]
newer_tag_name = options[:future_release]
newer_tag_link = options[:future_release]
else
# put unreleased label if there is no name for the tag
newer_tag_name = newer_tag.nil? ? options[:unreleased_label] : newer_tag["name"]
newer_tag_link = newer_tag.nil? ? "HEAD" : newer_tag_name
end
[newer_tag_link, newer_tag_name, newer_tag_time]
end
|
ruby
|
def detect_link_tag_time(newer_tag)
# if tag is nil - set current time
newer_tag_time = newer_tag.nil? ? Time.new : get_time_of_tag(newer_tag)
# if it's future release tag - set this value
if newer_tag.nil? && options[:future_release]
newer_tag_name = options[:future_release]
newer_tag_link = options[:future_release]
else
# put unreleased label if there is no name for the tag
newer_tag_name = newer_tag.nil? ? options[:unreleased_label] : newer_tag["name"]
newer_tag_link = newer_tag.nil? ? "HEAD" : newer_tag_name
end
[newer_tag_link, newer_tag_name, newer_tag_time]
end
|
[
"def",
"detect_link_tag_time",
"(",
"newer_tag",
")",
"# if tag is nil - set current time",
"newer_tag_time",
"=",
"newer_tag",
".",
"nil?",
"?",
"Time",
".",
"new",
":",
"get_time_of_tag",
"(",
"newer_tag",
")",
"# if it's future release tag - set this value",
"if",
"newer_tag",
".",
"nil?",
"&&",
"options",
"[",
":future_release",
"]",
"newer_tag_name",
"=",
"options",
"[",
":future_release",
"]",
"newer_tag_link",
"=",
"options",
"[",
":future_release",
"]",
"else",
"# put unreleased label if there is no name for the tag",
"newer_tag_name",
"=",
"newer_tag",
".",
"nil?",
"?",
"options",
"[",
":unreleased_label",
"]",
":",
"newer_tag",
"[",
"\"name\"",
"]",
"newer_tag_link",
"=",
"newer_tag",
".",
"nil?",
"?",
"\"HEAD\"",
":",
"newer_tag_name",
"end",
"[",
"newer_tag_link",
",",
"newer_tag_name",
",",
"newer_tag_time",
"]",
"end"
] |
Detect link, name and time for specified tag.
@param [Hash] newer_tag newer tag. Can be nil, if it's Unreleased section.
@return [Array] link, name and time of the tag
|
[
"Detect",
"link",
"name",
"and",
"time",
"for",
"specified",
"tag",
"."
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/generator_tags.rb#L84-L98
|
10,875
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/reader.rb
|
GitHubChangelogGenerator.Reader.parse_heading
|
def parse_heading(heading)
captures = { "version" => nil, "url" => nil, "date" => nil }
@heading_structures.each do |regexp|
matches = Regexp.new(regexp).match(heading)
if matches
captures.merge!(Hash[matches.names.zip(matches.captures)])
break
end
end
captures
end
|
ruby
|
def parse_heading(heading)
captures = { "version" => nil, "url" => nil, "date" => nil }
@heading_structures.each do |regexp|
matches = Regexp.new(regexp).match(heading)
if matches
captures.merge!(Hash[matches.names.zip(matches.captures)])
break
end
end
captures
end
|
[
"def",
"parse_heading",
"(",
"heading",
")",
"captures",
"=",
"{",
"\"version\"",
"=>",
"nil",
",",
"\"url\"",
"=>",
"nil",
",",
"\"date\"",
"=>",
"nil",
"}",
"@heading_structures",
".",
"each",
"do",
"|",
"regexp",
"|",
"matches",
"=",
"Regexp",
".",
"new",
"(",
"regexp",
")",
".",
"match",
"(",
"heading",
")",
"if",
"matches",
"captures",
".",
"merge!",
"(",
"Hash",
"[",
"matches",
".",
"names",
".",
"zip",
"(",
"matches",
".",
"captures",
")",
"]",
")",
"break",
"end",
"end",
"captures",
"end"
] |
Parse a single heading and return a Hash
The following heading structures are currently valid:
- ## [v1.0.2](https://github.com/zanui/chef-thumbor/tree/v1.0.1) (2015-03-24)
- ## [v1.0.2](https://github.com/zanui/chef-thumbor/tree/v1.0.1)
- ## v1.0.2 (2015-03-24)
- ## v1.0.2
@param [String] heading Heading from the ChangeLog File
@return [Hash] Returns a structured Hash with version, url and date
|
[
"Parse",
"a",
"single",
"heading",
"and",
"return",
"a",
"Hash"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/reader.rb#L53-L65
|
10,876
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/reader.rb
|
GitHubChangelogGenerator.Reader.parse
|
def parse(data)
sections = data.split(/^## .+?$/)
headings = data.scan(/^## .+?$/)
headings.each_with_index.map do |heading, index|
section = parse_heading(heading)
section["content"] = sections.at(index + 1)
section
end
end
|
ruby
|
def parse(data)
sections = data.split(/^## .+?$/)
headings = data.scan(/^## .+?$/)
headings.each_with_index.map do |heading, index|
section = parse_heading(heading)
section["content"] = sections.at(index + 1)
section
end
end
|
[
"def",
"parse",
"(",
"data",
")",
"sections",
"=",
"data",
".",
"split",
"(",
"/",
"/",
")",
"headings",
"=",
"data",
".",
"scan",
"(",
"/",
"/",
")",
"headings",
".",
"each_with_index",
".",
"map",
"do",
"|",
"heading",
",",
"index",
"|",
"section",
"=",
"parse_heading",
"(",
"heading",
")",
"section",
"[",
"\"content\"",
"]",
"=",
"sections",
".",
"at",
"(",
"index",
"+",
"1",
")",
"section",
"end",
"end"
] |
Parse the given ChangeLog data into a list of Hashes
@param [String] data File data from the ChangeLog.md
@return [Array<Hash>] Parsed data, e.g. [{ 'version' => ..., 'url' => ..., 'date' => ..., 'content' => ...}, ...]
|
[
"Parse",
"the",
"given",
"ChangeLog",
"data",
"into",
"a",
"list",
"of",
"Hashes"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/reader.rb#L71-L80
|
10,877
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/generator_processor.rb
|
GitHubChangelogGenerator.Generator.find_issues_to_add
|
def find_issues_to_add(all_issues, tag_name)
all_issues.select do |issue|
if issue["milestone"].nil?
false
else
# check, that this milestone in tag list:
milestone_is_tag = @filtered_tags.find do |tag|
tag["name"] == issue["milestone"]["title"]
end
if milestone_is_tag.nil?
false
else
issue["milestone"]["title"] == tag_name
end
end
end
end
|
ruby
|
def find_issues_to_add(all_issues, tag_name)
all_issues.select do |issue|
if issue["milestone"].nil?
false
else
# check, that this milestone in tag list:
milestone_is_tag = @filtered_tags.find do |tag|
tag["name"] == issue["milestone"]["title"]
end
if milestone_is_tag.nil?
false
else
issue["milestone"]["title"] == tag_name
end
end
end
end
|
[
"def",
"find_issues_to_add",
"(",
"all_issues",
",",
"tag_name",
")",
"all_issues",
".",
"select",
"do",
"|",
"issue",
"|",
"if",
"issue",
"[",
"\"milestone\"",
"]",
".",
"nil?",
"false",
"else",
"# check, that this milestone in tag list:",
"milestone_is_tag",
"=",
"@filtered_tags",
".",
"find",
"do",
"|",
"tag",
"|",
"tag",
"[",
"\"name\"",
"]",
"==",
"issue",
"[",
"\"milestone\"",
"]",
"[",
"\"title\"",
"]",
"end",
"if",
"milestone_is_tag",
".",
"nil?",
"false",
"else",
"issue",
"[",
"\"milestone\"",
"]",
"[",
"\"title\"",
"]",
"==",
"tag_name",
"end",
"end",
"end",
"end"
] |
Add all issues, that should be in that tag, according milestone
@param [Array] all_issues
@param [String] tag_name
@return [Array] issues with milestone #tag_name
|
[
"Add",
"all",
"issues",
"that",
"should",
"be",
"in",
"that",
"tag",
"according",
"milestone"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/generator_processor.rb#L47-L64
|
10,878
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/generator_processor.rb
|
GitHubChangelogGenerator.Generator.filter_array_by_labels
|
def filter_array_by_labels(all_issues)
filtered_issues = include_issues_by_labels(all_issues)
filtered_issues = exclude_issues_by_labels(filtered_issues)
exclude_issues_without_labels(filtered_issues)
end
|
ruby
|
def filter_array_by_labels(all_issues)
filtered_issues = include_issues_by_labels(all_issues)
filtered_issues = exclude_issues_by_labels(filtered_issues)
exclude_issues_without_labels(filtered_issues)
end
|
[
"def",
"filter_array_by_labels",
"(",
"all_issues",
")",
"filtered_issues",
"=",
"include_issues_by_labels",
"(",
"all_issues",
")",
"filtered_issues",
"=",
"exclude_issues_by_labels",
"(",
"filtered_issues",
")",
"exclude_issues_without_labels",
"(",
"filtered_issues",
")",
"end"
] |
General filtered function
@param [Array] all_issues PRs or issues
@return [Array] filtered issues
|
[
"General",
"filtered",
"function"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/generator_processor.rb#L186-L190
|
10,879
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/entry.rb
|
GitHubChangelogGenerator.Entry.generate_entry_for_tag
|
def generate_entry_for_tag(pull_requests, issues, newer_tag_name, newer_tag_link, newer_tag_time, older_tag_name) # rubocop:disable Metrics/ParameterLists
github_site = @options[:github_site] || "https://github.com"
project_url = "#{github_site}/#{@options[:user]}/#{@options[:project]}"
create_sections
@content = generate_header(newer_tag_name, newer_tag_link, newer_tag_time, older_tag_name, project_url)
@content += generate_body(pull_requests, issues)
@content
end
|
ruby
|
def generate_entry_for_tag(pull_requests, issues, newer_tag_name, newer_tag_link, newer_tag_time, older_tag_name) # rubocop:disable Metrics/ParameterLists
github_site = @options[:github_site] || "https://github.com"
project_url = "#{github_site}/#{@options[:user]}/#{@options[:project]}"
create_sections
@content = generate_header(newer_tag_name, newer_tag_link, newer_tag_time, older_tag_name, project_url)
@content += generate_body(pull_requests, issues)
@content
end
|
[
"def",
"generate_entry_for_tag",
"(",
"pull_requests",
",",
"issues",
",",
"newer_tag_name",
",",
"newer_tag_link",
",",
"newer_tag_time",
",",
"older_tag_name",
")",
"# rubocop:disable Metrics/ParameterLists",
"github_site",
"=",
"@options",
"[",
":github_site",
"]",
"||",
"\"https://github.com\"",
"project_url",
"=",
"\"#{github_site}/#{@options[:user]}/#{@options[:project]}\"",
"create_sections",
"@content",
"=",
"generate_header",
"(",
"newer_tag_name",
",",
"newer_tag_link",
",",
"newer_tag_time",
",",
"older_tag_name",
",",
"project_url",
")",
"@content",
"+=",
"generate_body",
"(",
"pull_requests",
",",
"issues",
")",
"@content",
"end"
] |
Generates log entry with header and body
@param [Array] pull_requests List or PR's in new section
@param [Array] issues List of issues in new section
@param [String] newer_tag_name Name of the newer tag. Could be nil for `Unreleased` section.
@param [String] newer_tag_link Name of the newer tag. Could be "HEAD" for `Unreleased` section.
@param [Time] newer_tag_time Time of the newer tag
@param [Hash, nil] older_tag_name Older tag, used for the links. Could be nil for last tag.
@return [String] Ready and parsed section content.
|
[
"Generates",
"log",
"entry",
"with",
"header",
"and",
"body"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/entry.rb#L32-L41
|
10,880
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/entry.rb
|
GitHubChangelogGenerator.Entry.generate_header
|
def generate_header(newer_tag_name, newer_tag_link, newer_tag_time, older_tag_name, project_url)
header = ""
# Generate date string:
time_string = newer_tag_time.strftime(@options[:date_format])
# Generate tag name and link
release_url = if @options[:release_url]
format(@options[:release_url], newer_tag_link)
else
"#{project_url}/tree/#{newer_tag_link}"
end
header += if newer_tag_name.equal?(@options[:unreleased_label])
"## [#{newer_tag_name}](#{release_url})\n\n"
else
"## [#{newer_tag_name}](#{release_url}) (#{time_string})\n\n"
end
if @options[:compare_link] && older_tag_name
# Generate compare link
header += "[Full Changelog](#{project_url}/compare/#{older_tag_name}...#{newer_tag_link})\n\n"
end
header
end
|
ruby
|
def generate_header(newer_tag_name, newer_tag_link, newer_tag_time, older_tag_name, project_url)
header = ""
# Generate date string:
time_string = newer_tag_time.strftime(@options[:date_format])
# Generate tag name and link
release_url = if @options[:release_url]
format(@options[:release_url], newer_tag_link)
else
"#{project_url}/tree/#{newer_tag_link}"
end
header += if newer_tag_name.equal?(@options[:unreleased_label])
"## [#{newer_tag_name}](#{release_url})\n\n"
else
"## [#{newer_tag_name}](#{release_url}) (#{time_string})\n\n"
end
if @options[:compare_link] && older_tag_name
# Generate compare link
header += "[Full Changelog](#{project_url}/compare/#{older_tag_name}...#{newer_tag_link})\n\n"
end
header
end
|
[
"def",
"generate_header",
"(",
"newer_tag_name",
",",
"newer_tag_link",
",",
"newer_tag_time",
",",
"older_tag_name",
",",
"project_url",
")",
"header",
"=",
"\"\"",
"# Generate date string:",
"time_string",
"=",
"newer_tag_time",
".",
"strftime",
"(",
"@options",
"[",
":date_format",
"]",
")",
"# Generate tag name and link",
"release_url",
"=",
"if",
"@options",
"[",
":release_url",
"]",
"format",
"(",
"@options",
"[",
":release_url",
"]",
",",
"newer_tag_link",
")",
"else",
"\"#{project_url}/tree/#{newer_tag_link}\"",
"end",
"header",
"+=",
"if",
"newer_tag_name",
".",
"equal?",
"(",
"@options",
"[",
":unreleased_label",
"]",
")",
"\"## [#{newer_tag_name}](#{release_url})\\n\\n\"",
"else",
"\"## [#{newer_tag_name}](#{release_url}) (#{time_string})\\n\\n\"",
"end",
"if",
"@options",
"[",
":compare_link",
"]",
"&&",
"older_tag_name",
"# Generate compare link",
"header",
"+=",
"\"[Full Changelog](#{project_url}/compare/#{older_tag_name}...#{newer_tag_link})\\n\\n\"",
"end",
"header",
"end"
] |
Generates header text for an entry.
@param [String] newer_tag_name The name of a newer tag
@param [String] newer_tag_link Used for URL generation. Could be same as #newer_tag_name or some specific value, like HEAD
@param [Time] newer_tag_time Time when the newer tag was created
@param [String] older_tag_name The name of an older tag; used for URLs.
@param [String] project_url URL for the current project.
@return [String] Header text content.
|
[
"Generates",
"header",
"text",
"for",
"an",
"entry",
"."
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/entry.rb#L87-L111
|
10,881
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/entry.rb
|
GitHubChangelogGenerator.Entry.sort_into_sections
|
def sort_into_sections(pull_requests, issues)
if @options[:issues]
unmapped_issues = sort_labeled_issues(issues)
add_unmapped_section(unmapped_issues)
end
if @options[:pulls]
unmapped_pull_requests = sort_labeled_issues(pull_requests)
add_unmapped_section(unmapped_pull_requests)
end
nil
end
|
ruby
|
def sort_into_sections(pull_requests, issues)
if @options[:issues]
unmapped_issues = sort_labeled_issues(issues)
add_unmapped_section(unmapped_issues)
end
if @options[:pulls]
unmapped_pull_requests = sort_labeled_issues(pull_requests)
add_unmapped_section(unmapped_pull_requests)
end
nil
end
|
[
"def",
"sort_into_sections",
"(",
"pull_requests",
",",
"issues",
")",
"if",
"@options",
"[",
":issues",
"]",
"unmapped_issues",
"=",
"sort_labeled_issues",
"(",
"issues",
")",
"add_unmapped_section",
"(",
"unmapped_issues",
")",
"end",
"if",
"@options",
"[",
":pulls",
"]",
"unmapped_pull_requests",
"=",
"sort_labeled_issues",
"(",
"pull_requests",
")",
"add_unmapped_section",
"(",
"unmapped_pull_requests",
")",
"end",
"nil",
"end"
] |
Sorts issues and PRs into entry sections by labels and lack of labels.
@param [Array] pull_requests
@param [Array] issues
@return [Nil]
|
[
"Sorts",
"issues",
"and",
"PRs",
"into",
"entry",
"sections",
"by",
"labels",
"and",
"lack",
"of",
"labels",
"."
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/entry.rb#L143-L153
|
10,882
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/entry.rb
|
GitHubChangelogGenerator.Entry.sort_labeled_issues
|
def sort_labeled_issues(issues)
sorted_issues = []
issues.each do |issue|
label_names = issue["labels"].collect { |l| l["name"] }
# Add PRs in the order of the @sections array. This will either be the
# default sections followed by any --add-sections sections in
# user-defined order, or --configure-sections in user-defined order.
# Ignore the order of the issue labels from github which cannot be
# controled by the user.
@sections.each do |section|
unless (section.labels & label_names).empty?
section.issues << issue
sorted_issues << issue
break
end
end
end
issues - sorted_issues
end
|
ruby
|
def sort_labeled_issues(issues)
sorted_issues = []
issues.each do |issue|
label_names = issue["labels"].collect { |l| l["name"] }
# Add PRs in the order of the @sections array. This will either be the
# default sections followed by any --add-sections sections in
# user-defined order, or --configure-sections in user-defined order.
# Ignore the order of the issue labels from github which cannot be
# controled by the user.
@sections.each do |section|
unless (section.labels & label_names).empty?
section.issues << issue
sorted_issues << issue
break
end
end
end
issues - sorted_issues
end
|
[
"def",
"sort_labeled_issues",
"(",
"issues",
")",
"sorted_issues",
"=",
"[",
"]",
"issues",
".",
"each",
"do",
"|",
"issue",
"|",
"label_names",
"=",
"issue",
"[",
"\"labels\"",
"]",
".",
"collect",
"{",
"|",
"l",
"|",
"l",
"[",
"\"name\"",
"]",
"}",
"# Add PRs in the order of the @sections array. This will either be the",
"# default sections followed by any --add-sections sections in",
"# user-defined order, or --configure-sections in user-defined order.",
"# Ignore the order of the issue labels from github which cannot be",
"# controled by the user.",
"@sections",
".",
"each",
"do",
"|",
"section",
"|",
"unless",
"(",
"section",
".",
"labels",
"&",
"label_names",
")",
".",
"empty?",
"section",
".",
"issues",
"<<",
"issue",
"sorted_issues",
"<<",
"issue",
"break",
"end",
"end",
"end",
"issues",
"-",
"sorted_issues",
"end"
] |
Iterates through sections and sorts labeled issues into them based on
the label mapping. Returns any unmapped or unlabeled issues.
@param [Array] issues Issues or pull requests.
@return [Array] Issues that were not mapped into any sections.
|
[
"Iterates",
"through",
"sections",
"and",
"sorts",
"labeled",
"issues",
"into",
"them",
"based",
"on",
"the",
"label",
"mapping",
".",
"Returns",
"any",
"unmapped",
"or",
"unlabeled",
"issues",
"."
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/entry.rb#L160-L179
|
10,883
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/parser_file.rb
|
GitHubChangelogGenerator.ParserFile.extract_pair
|
def extract_pair(line)
key, value = line.split("=", 2)
[key.tr("-", "_").to_sym, value.gsub(/[\n\r]+/, "")]
end
|
ruby
|
def extract_pair(line)
key, value = line.split("=", 2)
[key.tr("-", "_").to_sym, value.gsub(/[\n\r]+/, "")]
end
|
[
"def",
"extract_pair",
"(",
"line",
")",
"key",
",",
"value",
"=",
"line",
".",
"split",
"(",
"\"=\"",
",",
"2",
")",
"[",
"key",
".",
"tr",
"(",
"\"-\"",
",",
"\"_\"",
")",
".",
"to_sym",
",",
"value",
".",
"gsub",
"(",
"/",
"\\n",
"\\r",
"/",
",",
"\"\"",
")",
"]",
"end"
] |
Returns a the option name as a symbol and its string value sans newlines.
@param line [String] unparsed line from config file
@return [Array<Symbol, String>]
|
[
"Returns",
"a",
"the",
"option",
"name",
"as",
"a",
"symbol",
"and",
"its",
"string",
"value",
"sans",
"newlines",
"."
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/parser_file.rb#L66-L69
|
10,884
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator.rb
|
GitHubChangelogGenerator.ChangelogGenerator.run
|
def run
log = @generator.compound_changelog
if @options.write_to_file?
output_filename = @options[:output].to_s
File.open(output_filename, "wb") { |file| file.write(log) }
puts "Done!"
puts "Generated log placed in #{Dir.pwd}/#{output_filename}"
else
puts log
end
end
|
ruby
|
def run
log = @generator.compound_changelog
if @options.write_to_file?
output_filename = @options[:output].to_s
File.open(output_filename, "wb") { |file| file.write(log) }
puts "Done!"
puts "Generated log placed in #{Dir.pwd}/#{output_filename}"
else
puts log
end
end
|
[
"def",
"run",
"log",
"=",
"@generator",
".",
"compound_changelog",
"if",
"@options",
".",
"write_to_file?",
"output_filename",
"=",
"@options",
"[",
":output",
"]",
".",
"to_s",
"File",
".",
"open",
"(",
"output_filename",
",",
"\"wb\"",
")",
"{",
"|",
"file",
"|",
"file",
".",
"write",
"(",
"log",
")",
"}",
"puts",
"\"Done!\"",
"puts",
"\"Generated log placed in #{Dir.pwd}/#{output_filename}\"",
"else",
"puts",
"log",
"end",
"end"
] |
Class, responsible for whole changelog generation cycle
@return initialised instance of ChangelogGenerator
The entry point of this script to generate changelog
@raise (ChangelogGeneratorError) Is thrown when one of specified tags was not found in list of tags.
|
[
"Class",
"responsible",
"for",
"whole",
"changelog",
"generation",
"cycle"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator.rb#L34-L45
|
10,885
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/generator.rb
|
GitHubChangelogGenerator.Generator.generate_entry_between_tags
|
def generate_entry_between_tags(older_tag, newer_tag)
filtered_issues, filtered_pull_requests = filter_issues_for_tags(newer_tag, older_tag)
if newer_tag.nil? && filtered_issues.empty? && filtered_pull_requests.empty?
# do not generate empty unreleased section
return ""
end
newer_tag_link, newer_tag_name, newer_tag_time = detect_link_tag_time(newer_tag)
# If the older tag is nil, go back in time from the latest tag and find
# the SHA for the first commit.
older_tag_name =
if older_tag.nil?
@fetcher.oldest_commit["sha"]
else
older_tag["name"]
end
Entry.new(options).generate_entry_for_tag(filtered_pull_requests, filtered_issues, newer_tag_name, newer_tag_link, newer_tag_time, older_tag_name)
end
|
ruby
|
def generate_entry_between_tags(older_tag, newer_tag)
filtered_issues, filtered_pull_requests = filter_issues_for_tags(newer_tag, older_tag)
if newer_tag.nil? && filtered_issues.empty? && filtered_pull_requests.empty?
# do not generate empty unreleased section
return ""
end
newer_tag_link, newer_tag_name, newer_tag_time = detect_link_tag_time(newer_tag)
# If the older tag is nil, go back in time from the latest tag and find
# the SHA for the first commit.
older_tag_name =
if older_tag.nil?
@fetcher.oldest_commit["sha"]
else
older_tag["name"]
end
Entry.new(options).generate_entry_for_tag(filtered_pull_requests, filtered_issues, newer_tag_name, newer_tag_link, newer_tag_time, older_tag_name)
end
|
[
"def",
"generate_entry_between_tags",
"(",
"older_tag",
",",
"newer_tag",
")",
"filtered_issues",
",",
"filtered_pull_requests",
"=",
"filter_issues_for_tags",
"(",
"newer_tag",
",",
"older_tag",
")",
"if",
"newer_tag",
".",
"nil?",
"&&",
"filtered_issues",
".",
"empty?",
"&&",
"filtered_pull_requests",
".",
"empty?",
"# do not generate empty unreleased section",
"return",
"\"\"",
"end",
"newer_tag_link",
",",
"newer_tag_name",
",",
"newer_tag_time",
"=",
"detect_link_tag_time",
"(",
"newer_tag",
")",
"# If the older tag is nil, go back in time from the latest tag and find",
"# the SHA for the first commit.",
"older_tag_name",
"=",
"if",
"older_tag",
".",
"nil?",
"@fetcher",
".",
"oldest_commit",
"[",
"\"sha\"",
"]",
"else",
"older_tag",
"[",
"\"name\"",
"]",
"end",
"Entry",
".",
"new",
"(",
"options",
")",
".",
"generate_entry_for_tag",
"(",
"filtered_pull_requests",
",",
"filtered_issues",
",",
"newer_tag_name",
",",
"newer_tag_link",
",",
"newer_tag_time",
",",
"older_tag_name",
")",
"end"
] |
Generate log only between 2 specified tags
@param [String] older_tag all issues before this tag date will be excluded. May be nil, if it's first tag
@param [String] newer_tag all issue after this tag will be excluded. May be nil for unreleased section
|
[
"Generate",
"log",
"only",
"between",
"2",
"specified",
"tags"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/generator.rb#L73-L93
|
10,886
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/generator.rb
|
GitHubChangelogGenerator.Generator.filter_issues_for_tags
|
def filter_issues_for_tags(newer_tag, older_tag)
filtered_pull_requests = filter_by_tag(@pull_requests, newer_tag)
filtered_issues = delete_by_time(@issues, "actual_date", older_tag, newer_tag)
newer_tag_name = newer_tag.nil? ? nil : newer_tag["name"]
if options[:filter_issues_by_milestone]
# delete excess irrelevant issues (according milestones). Issue #22.
filtered_issues = filter_by_milestone(filtered_issues, newer_tag_name, @issues)
filtered_pull_requests = filter_by_milestone(filtered_pull_requests, newer_tag_name, @pull_requests)
end
[filtered_issues, filtered_pull_requests]
end
|
ruby
|
def filter_issues_for_tags(newer_tag, older_tag)
filtered_pull_requests = filter_by_tag(@pull_requests, newer_tag)
filtered_issues = delete_by_time(@issues, "actual_date", older_tag, newer_tag)
newer_tag_name = newer_tag.nil? ? nil : newer_tag["name"]
if options[:filter_issues_by_milestone]
# delete excess irrelevant issues (according milestones). Issue #22.
filtered_issues = filter_by_milestone(filtered_issues, newer_tag_name, @issues)
filtered_pull_requests = filter_by_milestone(filtered_pull_requests, newer_tag_name, @pull_requests)
end
[filtered_issues, filtered_pull_requests]
end
|
[
"def",
"filter_issues_for_tags",
"(",
"newer_tag",
",",
"older_tag",
")",
"filtered_pull_requests",
"=",
"filter_by_tag",
"(",
"@pull_requests",
",",
"newer_tag",
")",
"filtered_issues",
"=",
"delete_by_time",
"(",
"@issues",
",",
"\"actual_date\"",
",",
"older_tag",
",",
"newer_tag",
")",
"newer_tag_name",
"=",
"newer_tag",
".",
"nil?",
"?",
"nil",
":",
"newer_tag",
"[",
"\"name\"",
"]",
"if",
"options",
"[",
":filter_issues_by_milestone",
"]",
"# delete excess irrelevant issues (according milestones). Issue #22.",
"filtered_issues",
"=",
"filter_by_milestone",
"(",
"filtered_issues",
",",
"newer_tag_name",
",",
"@issues",
")",
"filtered_pull_requests",
"=",
"filter_by_milestone",
"(",
"filtered_pull_requests",
",",
"newer_tag_name",
",",
"@pull_requests",
")",
"end",
"[",
"filtered_issues",
",",
"filtered_pull_requests",
"]",
"end"
] |
Filters issues and pull requests based on, respectively, `actual_date`
and `merged_at` timestamp fields. `actual_date` is the detected form of
`closed_at` based on merge event SHA commit times.
@return [Array] filtered issues and pull requests
|
[
"Filters",
"issues",
"and",
"pull",
"requests",
"based",
"on",
"respectively",
"actual_date",
"and",
"merged_at",
"timestamp",
"fields",
".",
"actual_date",
"is",
"the",
"detected",
"form",
"of",
"closed_at",
"based",
"on",
"merge",
"event",
"SHA",
"commit",
"times",
"."
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/generator.rb#L100-L112
|
10,887
|
github-changelog-generator/github-changelog-generator
|
lib/github_changelog_generator/generator/generator.rb
|
GitHubChangelogGenerator.Generator.generate_entries_for_all_tags
|
def generate_entries_for_all_tags
puts "Generating entry..." if options[:verbose]
entries = generate_unreleased_entry
@tag_section_mapping.each_pair do |_tag_section, left_right_tags|
older_tag, newer_tag = left_right_tags
entries += generate_entry_between_tags(older_tag, newer_tag)
end
entries
end
|
ruby
|
def generate_entries_for_all_tags
puts "Generating entry..." if options[:verbose]
entries = generate_unreleased_entry
@tag_section_mapping.each_pair do |_tag_section, left_right_tags|
older_tag, newer_tag = left_right_tags
entries += generate_entry_between_tags(older_tag, newer_tag)
end
entries
end
|
[
"def",
"generate_entries_for_all_tags",
"puts",
"\"Generating entry...\"",
"if",
"options",
"[",
":verbose",
"]",
"entries",
"=",
"generate_unreleased_entry",
"@tag_section_mapping",
".",
"each_pair",
"do",
"|",
"_tag_section",
",",
"left_right_tags",
"|",
"older_tag",
",",
"newer_tag",
"=",
"left_right_tags",
"entries",
"+=",
"generate_entry_between_tags",
"(",
"older_tag",
",",
"newer_tag",
")",
"end",
"entries",
"end"
] |
The full cycle of generation for whole project
@return [String] All entries in the changelog
|
[
"The",
"full",
"cycle",
"of",
"generation",
"for",
"whole",
"project"
] |
f18c64b5cc0d7473b059275b88385ac11ca8b564
|
https://github.com/github-changelog-generator/github-changelog-generator/blob/f18c64b5cc0d7473b059275b88385ac11ca8b564/lib/github_changelog_generator/generator/generator.rb#L116-L127
|
10,888
|
hanami/hanami
|
lib/hanami/environment.rb
|
Hanami.Environment.to_options
|
def to_options
@options.merge(
environment: environment,
env_config: env_config,
apps_path: apps_path,
rackup: rackup,
host: host,
port: port
)
end
|
ruby
|
def to_options
@options.merge(
environment: environment,
env_config: env_config,
apps_path: apps_path,
rackup: rackup,
host: host,
port: port
)
end
|
[
"def",
"to_options",
"@options",
".",
"merge",
"(",
"environment",
":",
"environment",
",",
"env_config",
":",
"env_config",
",",
"apps_path",
":",
"apps_path",
",",
"rackup",
":",
"rackup",
",",
"host",
":",
"host",
",",
"port",
":",
"port",
")",
"end"
] |
Serialize the most relevant settings into a Hash
@return [::Hash]
@since 0.1.0
@api private
|
[
"Serialize",
"the",
"most",
"relevant",
"settings",
"into",
"a",
"Hash"
] |
8c6e5147e92ef869b25379448572da3698eacfdc
|
https://github.com/hanami/hanami/blob/8c6e5147e92ef869b25379448572da3698eacfdc/lib/hanami/environment.rb#L456-L465
|
10,889
|
hanami/hanami
|
lib/hanami/application_configuration.rb
|
Hanami.ApplicationConfiguration.root
|
def root(value = nil)
if value
@root = value
else
Utils::Kernel.Pathname(@root || Dir.pwd).realpath
end
end
|
ruby
|
def root(value = nil)
if value
@root = value
else
Utils::Kernel.Pathname(@root || Dir.pwd).realpath
end
end
|
[
"def",
"root",
"(",
"value",
"=",
"nil",
")",
"if",
"value",
"@root",
"=",
"value",
"else",
"Utils",
"::",
"Kernel",
".",
"Pathname",
"(",
"@root",
"||",
"Dir",
".",
"pwd",
")",
".",
"realpath",
"end",
"end"
] |
The root of the application
By default it returns the current directory, for this reason, **all the
commands must be executed from the top level directory of the project**.
If for some reason, that constraint above cannot be satisfied, please
configure the root directory, so that commands can be executed from
everywhere.
This is part of a DSL, for this reason when this method is called with
an argument, it will set the corresponding instance variable. When
called without, it will return the already set value, or the default.
@overload root(value)
Sets the given value
@param value [String,Pathname,#to_pathname] The root directory of the app
@overload root
Gets the value
@return [Pathname]
@raise [Errno::ENOENT] if the path cannot be found
@since 0.1.0
@see http://www.ruby-doc.org/core/Dir.html#method-c-pwd
@example Getting the value
require 'hanami'
module Bookshelf
class Application < Hanami::Application
end
end
Bookshelf::Application.configuration.root # => #<Pathname:/path/to/root>
@example Setting the value
require 'hanami'
module Bookshelf
class Application < Hanami::Application
configure do
root '/path/to/another/root'
end
end
end
|
[
"The",
"root",
"of",
"the",
"application"
] |
8c6e5147e92ef869b25379448572da3698eacfdc
|
https://github.com/hanami/hanami/blob/8c6e5147e92ef869b25379448572da3698eacfdc/lib/hanami/application_configuration.rb#L151-L157
|
10,890
|
hanami/hanami
|
lib/hanami/application_configuration.rb
|
Hanami.ApplicationConfiguration.routes
|
def routes(path = nil, &blk)
if path or block_given?
@routes = Config::Routes.new(root, path, &blk)
else
@routes
end
end
|
ruby
|
def routes(path = nil, &blk)
if path or block_given?
@routes = Config::Routes.new(root, path, &blk)
else
@routes
end
end
|
[
"def",
"routes",
"(",
"path",
"=",
"nil",
",",
"&",
"blk",
")",
"if",
"path",
"or",
"block_given?",
"@routes",
"=",
"Config",
"::",
"Routes",
".",
"new",
"(",
"root",
",",
"path",
",",
"blk",
")",
"else",
"@routes",
"end",
"end"
] |
Application routes.
Specify a set of routes for the application, by passing a block, or a
relative path where to find the file that describes them.
By default it's `nil`.
This is part of a DSL, for this reason when this method is called with
an argument, it will set the corresponding instance variable. When
called without, it will return the already set value, or the default.
@overload routes(blk)
Specify a set of routes in the given block
@param blk [Proc] the routes definitions
@overload routes(path)
Specify a relative path where to find the routes file
@param path [String] the relative path
@overload routes
Gets the value
@return [Hanami::Config::Routes] the set of routes
@since 0.1.0
@see http://rdoc.info/gems/hanami-router/Hanami/Router
@example Getting the value
require 'hanami'
module Bookshelf
class Application < Hanami::Application
end
end
Bookshelf::Application.configuration.routes
# => nil
@example Setting the value, by passing a block
require 'hanami'
module Bookshelf
class Application < Hanami::Application
configure do
routes do
get '/', to: 'dashboard#index'
resources :books
end
end
end
end
Bookshelf::Application.configuration.routes
# => #<Hanami::Config::Routes:0x007ff50a991388 @blk=#<Proc:0x007ff50a991338@(irb):4>, @path=#<Pathname:.>>
@example Setting the value, by passing a relative path
require 'hanami'
module Bookshelf
class Application < Hanami::Application
configure do
routes 'config/routes'
end
end
end
Bookshelf::Application.configuration.routes
# => #<Hanami::Config::Routes:0x007ff50a991388 @blk=nil, @path=#<Pathname:config/routes.rb>>
|
[
"Application",
"routes",
"."
] |
8c6e5147e92ef869b25379448572da3698eacfdc
|
https://github.com/hanami/hanami/blob/8c6e5147e92ef869b25379448572da3698eacfdc/lib/hanami/application_configuration.rb#L583-L589
|
10,891
|
hanami/hanami
|
lib/hanami/application_configuration.rb
|
Hanami.ApplicationConfiguration.port
|
def port(value = nil)
if value
@port = Integer(value)
else
return @port if defined?(@port)
return @env.port unless @env.default_port?
return DEFAULT_SSL_PORT if force_ssl
@env.port
end
end
|
ruby
|
def port(value = nil)
if value
@port = Integer(value)
else
return @port if defined?(@port)
return @env.port unless @env.default_port?
return DEFAULT_SSL_PORT if force_ssl
@env.port
end
end
|
[
"def",
"port",
"(",
"value",
"=",
"nil",
")",
"if",
"value",
"@port",
"=",
"Integer",
"(",
"value",
")",
"else",
"return",
"@port",
"if",
"defined?",
"(",
"@port",
")",
"return",
"@env",
".",
"port",
"unless",
"@env",
".",
"default_port?",
"return",
"DEFAULT_SSL_PORT",
"if",
"force_ssl",
"@env",
".",
"port",
"end",
"end"
] |
The URI port for this application.
This is used by the router helpers to generate absolute URLs.
By default this value is `2300`.
This is part of a DSL, for this reason when this method is called with
an argument, it will set the corresponding instance variable. When
called without, it will return the already set value, or the default.
@overload port(value)
Sets the given value
@param value [#to_int] the URI port
@raise [TypeError] if the given value cannot be coerced to Integer
@overload scheme
Gets the value
@return [String]
@since 0.1.0
@see http://en.wikipedia.org/wiki/URI_scheme
@example Getting the value
require 'hanami'
module Bookshelf
class Application < Hanami::Application
end
end
Bookshelf::Application.configuration.port # => 2300
@example Setting the value
require 'hanami'
module Bookshelf
class Application < Hanami::Application
configure do
port 8080
end
end
end
Bookshelf::Application.configuration.port # => 8080
|
[
"The",
"URI",
"port",
"for",
"this",
"application",
".",
"This",
"is",
"used",
"by",
"the",
"router",
"helpers",
"to",
"generate",
"absolute",
"URLs",
"."
] |
8c6e5147e92ef869b25379448572da3698eacfdc
|
https://github.com/hanami/hanami/blob/8c6e5147e92ef869b25379448572da3698eacfdc/lib/hanami/application_configuration.rb#L1003-L1012
|
10,892
|
hanami/hanami
|
lib/hanami/env.rb
|
Hanami.Env.load!
|
def load!(path)
return unless defined?(Dotenv::Parser)
contents = ::File.open(path, "rb:bom|utf-8", &:read)
parsed = Dotenv::Parser.call(contents)
parsed.each do |k, v|
next if @env.has_key?(k)
@env[k] = v
end
nil
end
|
ruby
|
def load!(path)
return unless defined?(Dotenv::Parser)
contents = ::File.open(path, "rb:bom|utf-8", &:read)
parsed = Dotenv::Parser.call(contents)
parsed.each do |k, v|
next if @env.has_key?(k)
@env[k] = v
end
nil
end
|
[
"def",
"load!",
"(",
"path",
")",
"return",
"unless",
"defined?",
"(",
"Dotenv",
"::",
"Parser",
")",
"contents",
"=",
"::",
"File",
".",
"open",
"(",
"path",
",",
"\"rb:bom|utf-8\"",
",",
":read",
")",
"parsed",
"=",
"Dotenv",
"::",
"Parser",
".",
"call",
"(",
"contents",
")",
"parsed",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"next",
"if",
"@env",
".",
"has_key?",
"(",
"k",
")",
"@env",
"[",
"k",
"]",
"=",
"v",
"end",
"nil",
"end"
] |
Loads a dotenv file and updates self
@param path [String, Pathname] the path to the dotenv file
@return void
@since 0.9.0
@api private
|
[
"Loads",
"a",
"dotenv",
"file",
"and",
"updates",
"self"
] |
8c6e5147e92ef869b25379448572da3698eacfdc
|
https://github.com/hanami/hanami/blob/8c6e5147e92ef869b25379448572da3698eacfdc/lib/hanami/env.rb#L55-L67
|
10,893
|
hanami/hanami
|
lib/hanami/hanamirc.rb
|
Hanami.Hanamirc.default_options
|
def default_options
@default_options ||= Utils::Hash.symbolize({
PROJECT_NAME => project_name,
TEST_KEY => DEFAULT_TEST_SUITE,
TEMPLATE_KEY => DEFAULT_TEMPLATE
}).freeze
end
|
ruby
|
def default_options
@default_options ||= Utils::Hash.symbolize({
PROJECT_NAME => project_name,
TEST_KEY => DEFAULT_TEST_SUITE,
TEMPLATE_KEY => DEFAULT_TEMPLATE
}).freeze
end
|
[
"def",
"default_options",
"@default_options",
"||=",
"Utils",
"::",
"Hash",
".",
"symbolize",
"(",
"{",
"PROJECT_NAME",
"=>",
"project_name",
",",
"TEST_KEY",
"=>",
"DEFAULT_TEST_SUITE",
",",
"TEMPLATE_KEY",
"=>",
"DEFAULT_TEMPLATE",
"}",
")",
".",
"freeze",
"end"
] |
Default values for writing the hanamirc file
@since 0.5.1
@api private
@see Hanami::Hanamirc#options
|
[
"Default",
"values",
"for",
"writing",
"the",
"hanamirc",
"file"
] |
8c6e5147e92ef869b25379448572da3698eacfdc
|
https://github.com/hanami/hanami/blob/8c6e5147e92ef869b25379448572da3698eacfdc/lib/hanami/hanamirc.rb#L95-L101
|
10,894
|
hanami/hanami
|
lib/hanami/hanamirc.rb
|
Hanami.Hanamirc.parse_file
|
def parse_file(path)
{}.tap do |hash|
File.readlines(path).each do |line|
key, value = line.split(SEPARATOR)
hash[key] = value.strip
end
end
end
|
ruby
|
def parse_file(path)
{}.tap do |hash|
File.readlines(path).each do |line|
key, value = line.split(SEPARATOR)
hash[key] = value.strip
end
end
end
|
[
"def",
"parse_file",
"(",
"path",
")",
"{",
"}",
".",
"tap",
"do",
"|",
"hash",
"|",
"File",
".",
"readlines",
"(",
"path",
")",
".",
"each",
"do",
"|",
"line",
"|",
"key",
",",
"value",
"=",
"line",
".",
"split",
"(",
"SEPARATOR",
")",
"hash",
"[",
"key",
"]",
"=",
"value",
".",
"strip",
"end",
"end",
"end"
] |
Read hanamirc file and parse it's values
@since 0.8.0
@api private
@return [Hash] hanamirc parsed values
|
[
"Read",
"hanamirc",
"file",
"and",
"parse",
"it",
"s",
"values"
] |
8c6e5147e92ef869b25379448572da3698eacfdc
|
https://github.com/hanami/hanami/blob/8c6e5147e92ef869b25379448572da3698eacfdc/lib/hanami/hanamirc.rb#L136-L143
|
10,895
|
hanami/hanami
|
lib/hanami/middleware_stack.rb
|
Hanami.MiddlewareStack.load!
|
def load!
load_default_stack
stack.each { |m, args, block| builder.use(load_middleware(m), *args, &block) }
builder.run routes
self
end
|
ruby
|
def load!
load_default_stack
stack.each { |m, args, block| builder.use(load_middleware(m), *args, &block) }
builder.run routes
self
end
|
[
"def",
"load!",
"load_default_stack",
"stack",
".",
"each",
"{",
"|",
"m",
",",
"args",
",",
"block",
"|",
"builder",
".",
"use",
"(",
"load_middleware",
"(",
"m",
")",
",",
"args",
",",
"block",
")",
"}",
"builder",
".",
"run",
"routes",
"self",
"end"
] |
Instantiate a middleware stack
@param configuration [Hanami::ApplicationConfiguration] the application's configuration
@return [Hanami::MiddlewareStack] the new stack
@since 0.1.0
@api private
@see Hanami::ApplicationConfiguration
Load the middleware stack
@return [Hanami::MiddlewareStack] the loaded middleware stack
@since 0.2.0
@api private
@see http://rdoc.info/gems/rack/Rack/Builder
|
[
"Instantiate",
"a",
"middleware",
"stack"
] |
8c6e5147e92ef869b25379448572da3698eacfdc
|
https://github.com/hanami/hanami/blob/8c6e5147e92ef869b25379448572da3698eacfdc/lib/hanami/middleware_stack.rb#L34-L40
|
10,896
|
hanami/hanami
|
lib/hanami/middleware_stack.rb
|
Hanami.MiddlewareStack.use
|
def use(middleware, *args, &blk)
stack.push [middleware, args, blk]
stack.uniq!
end
|
ruby
|
def use(middleware, *args, &blk)
stack.push [middleware, args, blk]
stack.uniq!
end
|
[
"def",
"use",
"(",
"middleware",
",",
"*",
"args",
",",
"&",
"blk",
")",
"stack",
".",
"push",
"[",
"middleware",
",",
"args",
",",
"blk",
"]",
"stack",
".",
"uniq!",
"end"
] |
Append a middleware to the stack.
@param middleware [Object] a Rack middleware
@param args [Array] optional arguments to pass to the Rack middleware
@param blk [Proc] an optional block to pass to the Rack middleware
@return [Array] the middleware that was added
@since 0.2.0
@see Hanami::MiddlewareStack#prepend
@example
# apps/web/application.rb
module Web
class Application < Hanami::Application
configure do
# ...
use MyRackMiddleware, foo: 'bar'
end
end
end
|
[
"Append",
"a",
"middleware",
"to",
"the",
"stack",
"."
] |
8c6e5147e92ef869b25379448572da3698eacfdc
|
https://github.com/hanami/hanami/blob/8c6e5147e92ef869b25379448572da3698eacfdc/lib/hanami/middleware_stack.rb#L77-L80
|
10,897
|
hanami/hanami
|
lib/hanami/middleware_stack.rb
|
Hanami.MiddlewareStack.prepend
|
def prepend(middleware, *args, &blk)
stack.unshift [middleware, args, blk]
stack.uniq!
end
|
ruby
|
def prepend(middleware, *args, &blk)
stack.unshift [middleware, args, blk]
stack.uniq!
end
|
[
"def",
"prepend",
"(",
"middleware",
",",
"*",
"args",
",",
"&",
"blk",
")",
"stack",
".",
"unshift",
"[",
"middleware",
",",
"args",
",",
"blk",
"]",
"stack",
".",
"uniq!",
"end"
] |
Prepend a middleware to the stack.
@param middleware [Object] a Rack middleware
@param args [Array] optional arguments to pass to the Rack middleware
@param blk [Proc] an optional block to pass to the Rack middleware
@return [Array] the middleware that was added
@since 0.6.0
@see Hanami::MiddlewareStack#use
@example
# apps/web/application.rb
module Web
class Application < Hanami::Application
configure do
# ...
prepend MyRackMiddleware, foo: 'bar'
end
end
end
|
[
"Prepend",
"a",
"middleware",
"to",
"the",
"stack",
"."
] |
8c6e5147e92ef869b25379448572da3698eacfdc
|
https://github.com/hanami/hanami/blob/8c6e5147e92ef869b25379448572da3698eacfdc/lib/hanami/middleware_stack.rb#L104-L107
|
10,898
|
hanami/hanami
|
lib/hanami/routes.rb
|
Hanami.Routes.path
|
def path(name, *args)
Utils::Escape::SafeString.new(@routes.path(name, *args))
end
|
ruby
|
def path(name, *args)
Utils::Escape::SafeString.new(@routes.path(name, *args))
end
|
[
"def",
"path",
"(",
"name",
",",
"*",
"args",
")",
"Utils",
"::",
"Escape",
"::",
"SafeString",
".",
"new",
"(",
"@routes",
".",
"path",
"(",
"name",
",",
"args",
")",
")",
"end"
] |
Initialize the factory
@param routes [Hanami::Router] a routes set
@return [Hanami::Routes] the factory
@since 0.1.0
@api private
Return a relative path for the given route name
@param name [Symbol] the route name
@param args [Array,nil] an optional set of arguments that is passed down
to the wrapped route set.
@return [Hanami::Utils::Escape::SafeString] the corresponding relative URL
@raise Hanami::Routing::InvalidRouteException
@since 0.1.0
@see http://rdoc.info/gems/hanami-router/Hanami/Router#path-instance_method
@example Basic example
require 'hanami'
module Web
class Application < Hanami::Application
configure do
routes do
get '/login', to: 'sessions#new', as: :login
end
end
end
end
Web.routes.path(:login)
# => '/login'
Web.routes.path(:login, return_to: '/dashboard')
# => '/login?return_to=%2Fdashboard'
@example Dynamic finders
require 'hanami'
module Web
class Application < Hanami::Application
configure do
routes do
get '/login', to: 'sessions#new', as: :login
end
end
end
end
Web.routes.login_path
# => '/login'
Web.routes.login_path(return_to: '/dashboard')
# => '/login?return_to=%2Fdashboard'
|
[
"Initialize",
"the",
"factory"
] |
8c6e5147e92ef869b25379448572da3698eacfdc
|
https://github.com/hanami/hanami/blob/8c6e5147e92ef869b25379448572da3698eacfdc/lib/hanami/routes.rb#L75-L77
|
10,899
|
hanami/hanami
|
lib/hanami/routes.rb
|
Hanami.Routes.url
|
def url(name, *args)
Utils::Escape::SafeString.new(@routes.url(name, *args))
end
|
ruby
|
def url(name, *args)
Utils::Escape::SafeString.new(@routes.url(name, *args))
end
|
[
"def",
"url",
"(",
"name",
",",
"*",
"args",
")",
"Utils",
"::",
"Escape",
"::",
"SafeString",
".",
"new",
"(",
"@routes",
".",
"url",
"(",
"name",
",",
"args",
")",
")",
"end"
] |
Return an absolute path for the given route name
@param name [Symbol] the route name
@param args [Array,nil] an optional set of arguments that is passed down
to the wrapped route set.
@return [Hanami::Utils::Escape::SafeString] the corresponding absolute URL
@raise Hanami::Routing::InvalidRouteException
@since 0.1.0
@see http://rdoc.info/gems/hanami-router/Hanami/Router#url-instance_method
@example Basic example
require 'hanami'
module Web
class Application < Hanami::Application
configure do
routes do
scheme 'https'
host 'bookshelf.org'
get '/login', to: 'sessions#new', as: :login
end
end
end
end
Web.routes.url(:login)
# => 'https://bookshelf.org/login'
Web.routes.url(:login, return_to: '/dashboard')
# => 'https://bookshelf.org/login?return_to=%2Fdashboard'
@example Dynamic finders
require 'hanami'
module Web
class Application < Hanami::Application
configure do
routes do
scheme 'https'
host 'bookshelf.org'
get '/login', to: 'sessions#new', as: :login
end
end
end
end
Web.routes.login_url
# => 'https://bookshelf.org/login'
Web.routes.login_url(return_to: '/dashboard')
# => 'https://bookshelf.org/login?return_to=%2Fdashboard'
|
[
"Return",
"an",
"absolute",
"path",
"for",
"the",
"given",
"route",
"name"
] |
8c6e5147e92ef869b25379448572da3698eacfdc
|
https://github.com/hanami/hanami/blob/8c6e5147e92ef869b25379448572da3698eacfdc/lib/hanami/routes.rb#L136-L138
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.