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
sequence | docstring
stringlengths 8
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 94
266
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
decidim/decidim | decidim-core/app/helpers/decidim/amendments_helper.rb | Decidim.AmendmentsHelper.allowed_to_promote? | def allowed_to_promote?(emendation)
return unless emendation.amendment.rejected? && emendation.created_by?(current_user)
return if promoted?(emendation)
true
end | ruby | def allowed_to_promote?(emendation)
return unless emendation.amendment.rejected? && emendation.created_by?(current_user)
return if promoted?(emendation)
true
end | [
"def",
"allowed_to_promote?",
"(",
"emendation",
")",
"return",
"unless",
"emendation",
".",
"amendment",
".",
"rejected?",
"&&",
"emendation",
".",
"created_by?",
"(",
"current_user",
")",
"return",
"if",
"promoted?",
"(",
"emendation",
")",
"true",
"end"
] | Checks if the user can promote the emendation | [
"Checks",
"if",
"the",
"user",
"can",
"promote",
"the",
"emendation"
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/amendments_helper.rb#L90-L95 | train |
decidim/decidim | decidim-core/app/helpers/decidim/amendments_helper.rb | Decidim.AmendmentsHelper.promoted? | def promoted?(emendation)
logs = Decidim::ActionLog.where(decidim_component_id: emendation.component)
.where(decidim_user_id: emendation.creator_author)
.where(action: "promote")
logs.select { |log| log.extra["promoted_from"] == emendation.id }.present?
end | ruby | def promoted?(emendation)
logs = Decidim::ActionLog.where(decidim_component_id: emendation.component)
.where(decidim_user_id: emendation.creator_author)
.where(action: "promote")
logs.select { |log| log.extra["promoted_from"] == emendation.id }.present?
end | [
"def",
"promoted?",
"(",
"emendation",
")",
"logs",
"=",
"Decidim",
"::",
"ActionLog",
".",
"where",
"(",
"decidim_component_id",
":",
"emendation",
".",
"component",
")",
".",
"where",
"(",
"decidim_user_id",
":",
"emendation",
".",
"creator_author",
")",
".",
"where",
"(",
"action",
":",
"\"promote\"",
")",
"logs",
".",
"select",
"{",
"|",
"log",
"|",
"log",
".",
"extra",
"[",
"\"promoted_from\"",
"]",
"==",
"emendation",
".",
"id",
"}",
".",
"present?",
"end"
] | Checks if the unique ActionLog created in the promote command exists. | [
"Checks",
"if",
"the",
"unique",
"ActionLog",
"created",
"in",
"the",
"promote",
"command",
"exists",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/amendments_helper.rb#L98-L104 | train |
decidim/decidim | decidim-core/app/helpers/decidim/amendments_helper.rb | Decidim.AmendmentsHelper.user_group_select_field | def user_group_select_field(form, name)
form.select(name,
current_user.user_groups.verified.map { |g| [g.name, g.id] },
selected: form.object.user_group_id.presence,
include_blank: current_user.name,
label: t("new.amendment_author", scope: "decidim.amendments"))
end | ruby | def user_group_select_field(form, name)
form.select(name,
current_user.user_groups.verified.map { |g| [g.name, g.id] },
selected: form.object.user_group_id.presence,
include_blank: current_user.name,
label: t("new.amendment_author", scope: "decidim.amendments"))
end | [
"def",
"user_group_select_field",
"(",
"form",
",",
"name",
")",
"form",
".",
"select",
"(",
"name",
",",
"current_user",
".",
"user_groups",
".",
"verified",
".",
"map",
"{",
"|",
"g",
"|",
"[",
"g",
".",
"name",
",",
"g",
".",
"id",
"]",
"}",
",",
"selected",
":",
"form",
".",
"object",
".",
"user_group_id",
".",
"presence",
",",
"include_blank",
":",
"current_user",
".",
"name",
",",
"label",
":",
"t",
"(",
"\"new.amendment_author\"",
",",
"scope",
":",
"\"decidim.amendments\"",
")",
")",
"end"
] | Renders a UserGroup select field in a form. | [
"Renders",
"a",
"UserGroup",
"select",
"field",
"in",
"a",
"form",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/amendments_helper.rb#L107-L113 | train |
decidim/decidim | decidim-core/app/helpers/decidim/amendments_helper.rb | Decidim.AmendmentsHelper.emendation_field_value | def emendation_field_value(form, original, key)
return params[:amendment][:emendation_params][key] if params[:amendment].present?
present(form.object.send(original)).send(key)
end | ruby | def emendation_field_value(form, original, key)
return params[:amendment][:emendation_params][key] if params[:amendment].present?
present(form.object.send(original)).send(key)
end | [
"def",
"emendation_field_value",
"(",
"form",
",",
"original",
",",
"key",
")",
"return",
"params",
"[",
":amendment",
"]",
"[",
":emendation_params",
"]",
"[",
"key",
"]",
"if",
"params",
"[",
":amendment",
"]",
".",
"present?",
"present",
"(",
"form",
".",
"object",
".",
"send",
"(",
"original",
")",
")",
".",
"send",
"(",
"key",
")",
"end"
] | Return the edited field value or presents the original attribute value in a form. | [
"Return",
"the",
"edited",
"field",
"value",
"or",
"presents",
"the",
"original",
"attribute",
"value",
"in",
"a",
"form",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/amendments_helper.rb#L116-L120 | train |
decidim/decidim | decidim-core/app/helpers/decidim/map_helper.rb | Decidim.MapHelper.static_map_link | def static_map_link(resource, options = {})
return unless resource.geocoded?
zoom = options[:zoom] || 17
latitude = resource.latitude
longitude = resource.longitude
map_url = "https://www.openstreetmap.org/?mlat=#{latitude}&mlon=#{longitude}#map=#{zoom}/#{latitude}/#{longitude}"
link_to map_url, target: "_blank" do
image_tag decidim.static_map_path(sgid: resource.to_sgid.to_s)
end
end | ruby | def static_map_link(resource, options = {})
return unless resource.geocoded?
zoom = options[:zoom] || 17
latitude = resource.latitude
longitude = resource.longitude
map_url = "https://www.openstreetmap.org/?mlat=#{latitude}&mlon=#{longitude}#map=#{zoom}/#{latitude}/#{longitude}"
link_to map_url, target: "_blank" do
image_tag decidim.static_map_path(sgid: resource.to_sgid.to_s)
end
end | [
"def",
"static_map_link",
"(",
"resource",
",",
"options",
"=",
"{",
"}",
")",
"return",
"unless",
"resource",
".",
"geocoded?",
"zoom",
"=",
"options",
"[",
":zoom",
"]",
"||",
"17",
"latitude",
"=",
"resource",
".",
"latitude",
"longitude",
"=",
"resource",
".",
"longitude",
"map_url",
"=",
"\"https://www.openstreetmap.org/?mlat=#{latitude}&mlon=#{longitude}#map=#{zoom}/#{latitude}/#{longitude}\"",
"link_to",
"map_url",
",",
"target",
":",
"\"_blank\"",
"do",
"image_tag",
"decidim",
".",
"static_map_path",
"(",
"sgid",
":",
"resource",
".",
"to_sgid",
".",
"to_s",
")",
"end",
"end"
] | Renders a link to openstreetmaps with the resource latitude and longitude.
The link's content is a static map image.
resource - A geolocalizable resource
options - An optional hash of options (default: { zoom: 17 })
* zoom: A number to represent the zoom value of the map | [
"Renders",
"a",
"link",
"to",
"openstreetmaps",
"with",
"the",
"resource",
"latitude",
"and",
"longitude",
".",
"The",
"link",
"s",
"content",
"is",
"a",
"static",
"map",
"image",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/map_helper.rb#L12-L24 | train |
decidim/decidim | decidim-core/app/helpers/decidim/attachments_helper.rb | Decidim.AttachmentsHelper.attachment_title | def attachment_title(attachment)
attachment.title.is_a?(Hash) ? translated_attribute(attachment.title) : attachment.title
end | ruby | def attachment_title(attachment)
attachment.title.is_a?(Hash) ? translated_attribute(attachment.title) : attachment.title
end | [
"def",
"attachment_title",
"(",
"attachment",
")",
"attachment",
".",
"title",
".",
"is_a?",
"(",
"Hash",
")",
"?",
"translated_attribute",
"(",
"attachment",
".",
"title",
")",
":",
"attachment",
".",
"title",
"end"
] | Renders the attachment's title.
Checks if the attachment's title is translated or not and use
the correct render method.
attachment - An Attachment object
Returns String. | [
"Renders",
"the",
"attachment",
"s",
"title",
".",
"Checks",
"if",
"the",
"attachment",
"s",
"title",
"is",
"translated",
"or",
"not",
"and",
"use",
"the",
"correct",
"render",
"method",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/attachments_helper.rb#L23-L25 | train |
decidim/decidim | decidim-core/app/helpers/decidim/replace_buttons_helper.rb | Decidim.ReplaceButtonsHelper.submit_tag | def submit_tag(text = "Save changes", options = {})
options = options.stringify_keys
content_tag :button, text, { "type" => "submit", "name" => "commit" }.update(options)
end | ruby | def submit_tag(text = "Save changes", options = {})
options = options.stringify_keys
content_tag :button, text, { "type" => "submit", "name" => "commit" }.update(options)
end | [
"def",
"submit_tag",
"(",
"text",
"=",
"\"Save changes\"",
",",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"options",
".",
"stringify_keys",
"content_tag",
":button",
",",
"text",
",",
"{",
"\"type\"",
"=>",
"\"submit\"",
",",
"\"name\"",
"=>",
"\"commit\"",
"}",
".",
"update",
"(",
"options",
")",
"end"
] | Overrides the submit tags to always be buttons instead of inputs.
Buttons are much more stylable and less prone to bugs.
value - The text of the button
options - Options to provide to the actual tag.
Returns a SafeString with the tag. | [
"Overrides",
"the",
"submit",
"tags",
"to",
"always",
"be",
"buttons",
"instead",
"of",
"inputs",
".",
"Buttons",
"are",
"much",
"more",
"stylable",
"and",
"less",
"prone",
"to",
"bugs",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/replace_buttons_helper.rb#L12-L16 | train |
decidim/decidim | decidim-core/app/services/decidim/traceability.rb | Decidim.Traceability.create | def create(klass, author, params, extra_log_info = {})
perform_action!(:create, klass, author, extra_log_info) do
klass.create(params)
end
end | ruby | def create(klass, author, params, extra_log_info = {})
perform_action!(:create, klass, author, extra_log_info) do
klass.create(params)
end
end | [
"def",
"create",
"(",
"klass",
",",
"author",
",",
"params",
",",
"extra_log_info",
"=",
"{",
"}",
")",
"perform_action!",
"(",
":create",
",",
"klass",
",",
"author",
",",
"extra_log_info",
")",
"do",
"klass",
".",
"create",
"(",
"params",
")",
"end",
"end"
] | Calls the `create` method to the given class and sets the author of the version.
klass - An ActiveRecord class that implements `Decidim::Traceable`
author - An object that implements `to_gid` or a String
params - a Hash with the attributes of the new resource
extra_log_info - a Hash with extra info that will be saved to the log
Returns an instance of `klass`. | [
"Calls",
"the",
"create",
"method",
"to",
"the",
"given",
"class",
"and",
"sets",
"the",
"author",
"of",
"the",
"version",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/services/decidim/traceability.rb#L31-L35 | train |
decidim/decidim | decidim-core/app/services/decidim/traceability.rb | Decidim.Traceability.create! | def create!(klass, author, params, extra_log_info = {})
perform_action!(:create, klass, author, extra_log_info) do
klass.create!(params)
end
end | ruby | def create!(klass, author, params, extra_log_info = {})
perform_action!(:create, klass, author, extra_log_info) do
klass.create!(params)
end
end | [
"def",
"create!",
"(",
"klass",
",",
"author",
",",
"params",
",",
"extra_log_info",
"=",
"{",
"}",
")",
"perform_action!",
"(",
":create",
",",
"klass",
",",
"author",
",",
"extra_log_info",
")",
"do",
"klass",
".",
"create!",
"(",
"params",
")",
"end",
"end"
] | Calls the `create!` method to the given class and sets the author of the version.
klass - An ActiveRecord class that implements `Decidim::Traceable`
author - An object that implements `to_gid` or a String
params - a Hash with the attributes of the new resource
extra_log_info - a Hash with extra info that will be saved to the log
Returns an instance of `klass`. | [
"Calls",
"the",
"create!",
"method",
"to",
"the",
"given",
"class",
"and",
"sets",
"the",
"author",
"of",
"the",
"version",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/services/decidim/traceability.rb#L45-L49 | train |
decidim/decidim | decidim-core/app/services/decidim/traceability.rb | Decidim.Traceability.perform_action! | def perform_action!(action, resource, author, extra_log_info = {})
PaperTrail.request(whodunnit: gid(author)) do
Decidim::ApplicationRecord.transaction do
result = block_given? ? yield : nil
loggable_resource = resource.is_a?(Class) ? result : resource
log(action, author, loggable_resource, extra_log_info)
return result
end
end
end | ruby | def perform_action!(action, resource, author, extra_log_info = {})
PaperTrail.request(whodunnit: gid(author)) do
Decidim::ApplicationRecord.transaction do
result = block_given? ? yield : nil
loggable_resource = resource.is_a?(Class) ? result : resource
log(action, author, loggable_resource, extra_log_info)
return result
end
end
end | [
"def",
"perform_action!",
"(",
"action",
",",
"resource",
",",
"author",
",",
"extra_log_info",
"=",
"{",
"}",
")",
"PaperTrail",
".",
"request",
"(",
"whodunnit",
":",
"gid",
"(",
"author",
")",
")",
"do",
"Decidim",
"::",
"ApplicationRecord",
".",
"transaction",
"do",
"result",
"=",
"block_given?",
"?",
"yield",
":",
"nil",
"loggable_resource",
"=",
"resource",
".",
"is_a?",
"(",
"Class",
")",
"?",
"result",
":",
"resource",
"log",
"(",
"action",
",",
"author",
",",
"loggable_resource",
",",
"extra_log_info",
")",
"return",
"result",
"end",
"end",
"end"
] | Performs the given block and sets the author of the action.
It also logs the action with the given `action` parameter.
The action and the logging are run inside a transaction.
action - a String or Symbol representing the action performed
resource - An ActiveRecord instance that implements `Decidim::Traceable`
author - An object that implements `to_gid` or a String
extra_log_info - a Hash with extra info that will be saved to the log
Returns whatever the given block returns. | [
"Performs",
"the",
"given",
"block",
"and",
"sets",
"the",
"author",
"of",
"the",
"action",
".",
"It",
"also",
"logs",
"the",
"action",
"with",
"the",
"given",
"action",
"parameter",
".",
"The",
"action",
"and",
"the",
"logging",
"are",
"run",
"inside",
"a",
"transaction",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/services/decidim/traceability.rb#L61-L70 | train |
decidim/decidim | decidim-core/app/services/decidim/traceability.rb | Decidim.Traceability.update! | def update!(resource, author, params, extra_log_info = {})
perform_action!(:update, resource, author, extra_log_info) do
resource.update!(params)
resource
end
end | ruby | def update!(resource, author, params, extra_log_info = {})
perform_action!(:update, resource, author, extra_log_info) do
resource.update!(params)
resource
end
end | [
"def",
"update!",
"(",
"resource",
",",
"author",
",",
"params",
",",
"extra_log_info",
"=",
"{",
"}",
")",
"perform_action!",
"(",
":update",
",",
"resource",
",",
"author",
",",
"extra_log_info",
")",
"do",
"resource",
".",
"update!",
"(",
"params",
")",
"resource",
"end",
"end"
] | Updates the `resource` with `update!` and sets the author of the version.
resource - An ActiveRecord instance that implements `Decidim::Traceable`
author - An object that implements `to_gid` or a String
params - a Hash with the attributes to update to the resource
extra_log_info - a Hash with extra info that will be saved to the log
Returns the updated `resource`. | [
"Updates",
"the",
"resource",
"with",
"update!",
"and",
"sets",
"the",
"author",
"of",
"the",
"version",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/services/decidim/traceability.rb#L80-L85 | train |
decidim/decidim | decidim-core/app/helpers/decidim/application_helper.rb | Decidim.ApplicationHelper.html_truncate | def html_truncate(text, options = {})
options[:max_length] = options.delete(:length) || options[:max_length]
options[:tail] = options.delete(:separator) || options[:tail] || "..."
options[:count_tags] ||= false
options[:count_tail] ||= false
options[:tail_before_final_tag] ||= true
Truncato.truncate(text, options)
end | ruby | def html_truncate(text, options = {})
options[:max_length] = options.delete(:length) || options[:max_length]
options[:tail] = options.delete(:separator) || options[:tail] || "..."
options[:count_tags] ||= false
options[:count_tail] ||= false
options[:tail_before_final_tag] ||= true
Truncato.truncate(text, options)
end | [
"def",
"html_truncate",
"(",
"text",
",",
"options",
"=",
"{",
"}",
")",
"options",
"[",
":max_length",
"]",
"=",
"options",
".",
"delete",
"(",
":length",
")",
"||",
"options",
"[",
":max_length",
"]",
"options",
"[",
":tail",
"]",
"=",
"options",
".",
"delete",
"(",
":separator",
")",
"||",
"options",
"[",
":tail",
"]",
"||",
"\"...\"",
"options",
"[",
":count_tags",
"]",
"||=",
"false",
"options",
"[",
":count_tail",
"]",
"||=",
"false",
"options",
"[",
":tail_before_final_tag",
"]",
"||=",
"true",
"Truncato",
".",
"truncate",
"(",
"text",
",",
"options",
")",
"end"
] | Truncates a given text respecting its HTML tags.
text - The String text to be truncated.
options - A Hash with the options to truncate the text (default: {}):
:length - An Integer number with the max length of the text.
:separator - A String to append to the text when it's being
truncated. See `truncato` gem for more options.
Returns a String. | [
"Truncates",
"a",
"given",
"text",
"respecting",
"its",
"HTML",
"tags",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/application_helper.rb#L20-L28 | train |
decidim/decidim | decidim-core/app/helpers/decidim/application_helper.rb | Decidim.ApplicationHelper.edit_link | def edit_link(link, action, subject, extra_context = {})
return unless current_user
return unless admin_allowed_to?(action, subject, extra_context)
return if content_for?(:edit_link)
content_for(:edit_link, link)
end | ruby | def edit_link(link, action, subject, extra_context = {})
return unless current_user
return unless admin_allowed_to?(action, subject, extra_context)
return if content_for?(:edit_link)
content_for(:edit_link, link)
end | [
"def",
"edit_link",
"(",
"link",
",",
"action",
",",
"subject",
",",
"extra_context",
"=",
"{",
"}",
")",
"return",
"unless",
"current_user",
"return",
"unless",
"admin_allowed_to?",
"(",
"action",
",",
"subject",
",",
"extra_context",
")",
"return",
"if",
"content_for?",
"(",
":edit_link",
")",
"content_for",
"(",
":edit_link",
",",
"link",
")",
"end"
] | Generates a link to be added to the global Edit link so admins
can easily manage data without having to look for it at the admin
panel when they're at a public page.
link - The String with the URL.
action - The Symbol action to check the permissions for.
subject - The Symbol subject to perform the action to.
extra_context - An optional Hash to check the permissions.
Returns nothing. | [
"Generates",
"a",
"link",
"to",
"be",
"added",
"to",
"the",
"global",
"Edit",
"link",
"so",
"admins",
"can",
"easily",
"manage",
"data",
"without",
"having",
"to",
"look",
"for",
"it",
"at",
"the",
"admin",
"panel",
"when",
"they",
"re",
"at",
"a",
"public",
"page",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/application_helper.rb#L49-L55 | train |
decidim/decidim | decidim-core/lib/decidim/participatory_space_manifest.rb | Decidim.ParticipatorySpaceManifest.context | def context(name = :public, &block)
name = name.to_sym
@contexts ||= {}
if block
context = ParticipatorySpaceContextManifest.new
context.instance_eval(&block)
@contexts[name] = context
end
@contexts.fetch(name)
end | ruby | def context(name = :public, &block)
name = name.to_sym
@contexts ||= {}
if block
context = ParticipatorySpaceContextManifest.new
context.instance_eval(&block)
@contexts[name] = context
end
@contexts.fetch(name)
end | [
"def",
"context",
"(",
"name",
"=",
":public",
",",
"&",
"block",
")",
"name",
"=",
"name",
".",
"to_sym",
"@contexts",
"||=",
"{",
"}",
"if",
"block",
"context",
"=",
"ParticipatorySpaceContextManifest",
".",
"new",
"context",
".",
"instance_eval",
"(",
"&",
"block",
")",
"@contexts",
"[",
"name",
"]",
"=",
"context",
"end",
"@contexts",
".",
"fetch",
"(",
"name",
")",
"end"
] | A context used to set the layout and behavior of a participatory space. Full documentation can
be found looking at the `ParticipatorySpaceContextManifest` class.
Example:
context(:public) do |context|
context.layout "layouts/decidim/some_layout"
end
context(:public).layout
# => "layouts/decidim/some_layout"
Returns Nothing. | [
"A",
"context",
"used",
"to",
"set",
"the",
"layout",
"and",
"behavior",
"of",
"a",
"participatory",
"space",
".",
"Full",
"documentation",
"can",
"be",
"found",
"looking",
"at",
"the",
"ParticipatorySpaceContextManifest",
"class",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/lib/decidim/participatory_space_manifest.rb#L62-L73 | train |
decidim/decidim | decidim-core/lib/decidim/friendly_dates.rb | Decidim.FriendlyDates.friendly_created_at | def friendly_created_at
current_datetime = Time.current
if created_at > current_datetime.beginning_of_day
I18n.l(created_at, format: :time_of_day)
elsif created_at > current_datetime.beginning_of_week
I18n.l(created_at, format: :day_of_week)
elsif created_at > current_datetime.beginning_of_year
I18n.l(created_at, format: :day_of_month)
else
I18n.l(created_at, format: :day_of_year)
end
end | ruby | def friendly_created_at
current_datetime = Time.current
if created_at > current_datetime.beginning_of_day
I18n.l(created_at, format: :time_of_day)
elsif created_at > current_datetime.beginning_of_week
I18n.l(created_at, format: :day_of_week)
elsif created_at > current_datetime.beginning_of_year
I18n.l(created_at, format: :day_of_month)
else
I18n.l(created_at, format: :day_of_year)
end
end | [
"def",
"friendly_created_at",
"current_datetime",
"=",
"Time",
".",
"current",
"if",
"created_at",
">",
"current_datetime",
".",
"beginning_of_day",
"I18n",
".",
"l",
"(",
"created_at",
",",
"format",
":",
":time_of_day",
")",
"elsif",
"created_at",
">",
"current_datetime",
".",
"beginning_of_week",
"I18n",
".",
"l",
"(",
"created_at",
",",
"format",
":",
":day_of_week",
")",
"elsif",
"created_at",
">",
"current_datetime",
".",
"beginning_of_year",
"I18n",
".",
"l",
"(",
"created_at",
",",
"format",
":",
":day_of_month",
")",
"else",
"I18n",
".",
"l",
"(",
"created_at",
",",
"format",
":",
":day_of_year",
")",
"end",
"end"
] | Returns the creation date in a friendly relative format. | [
"Returns",
"the",
"creation",
"date",
"in",
"a",
"friendly",
"relative",
"format",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/lib/decidim/friendly_dates.rb#L12-L24 | train |
decidim/decidim | decidim-core/app/queries/decidim/metric_manage.rb | Decidim.MetricManage.retrieve_participatory_spaces | def retrieve_participatory_spaces
Decidim.participatory_space_manifests.map do |space_manifest|
next unless space_manifest.name == :participatory_processes # Temporal limitation
space_manifest.participatory_spaces.call(@organization)
end.flatten.compact
end | ruby | def retrieve_participatory_spaces
Decidim.participatory_space_manifests.map do |space_manifest|
next unless space_manifest.name == :participatory_processes # Temporal limitation
space_manifest.participatory_spaces.call(@organization)
end.flatten.compact
end | [
"def",
"retrieve_participatory_spaces",
"Decidim",
".",
"participatory_space_manifests",
".",
"map",
"do",
"|",
"space_manifest",
"|",
"next",
"unless",
"space_manifest",
".",
"name",
"==",
":participatory_processes",
"space_manifest",
".",
"participatory_spaces",
".",
"call",
"(",
"@organization",
")",
"end",
".",
"flatten",
".",
"compact",
"end"
] | Search for all Participatory Space manifests and then all records available
Limited to ParticipatoryProcesses only | [
"Search",
"for",
"all",
"Participatory",
"Space",
"manifests",
"and",
"then",
"all",
"records",
"available",
"Limited",
"to",
"ParticipatoryProcesses",
"only"
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/queries/decidim/metric_manage.rb#L61-L66 | train |
decidim/decidim | decidim-core/app/helpers/decidim/localized_locales_helper.rb | Decidim.LocalizedLocalesHelper.localized_locales | def localized_locales(collection = Decidim.available_locales)
klass = Class.new do
def initialize(locale)
@locale = locale
end
def id
@locale.to_s
end
def name
I18n.with_locale(@locale) { I18n.t("name", scope: "locale") }
end
end
collection.map { |locale| klass.new(locale) }
end | ruby | def localized_locales(collection = Decidim.available_locales)
klass = Class.new do
def initialize(locale)
@locale = locale
end
def id
@locale.to_s
end
def name
I18n.with_locale(@locale) { I18n.t("name", scope: "locale") }
end
end
collection.map { |locale| klass.new(locale) }
end | [
"def",
"localized_locales",
"(",
"collection",
"=",
"Decidim",
".",
"available_locales",
")",
"klass",
"=",
"Class",
".",
"new",
"do",
"def",
"initialize",
"(",
"locale",
")",
"@locale",
"=",
"locale",
"end",
"def",
"id",
"@locale",
".",
"to_s",
"end",
"def",
"name",
"I18n",
".",
"with_locale",
"(",
"@locale",
")",
"{",
"I18n",
".",
"t",
"(",
"\"name\"",
",",
"scope",
":",
"\"locale\"",
")",
"}",
"end",
"end",
"collection",
".",
"map",
"{",
"|",
"locale",
"|",
"klass",
".",
"new",
"(",
"locale",
")",
"}",
"end"
] | Converts a given array of strings to an array of Objects representing
locales.
collection - an Array of Strings. By default it uses all the available
locales in Decidim, but you can passa nother collection of locales (for
example, the available locales for an organization) | [
"Converts",
"a",
"given",
"array",
"of",
"strings",
"to",
"an",
"array",
"of",
"Objects",
"representing",
"locales",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/localized_locales_helper.rb#L26-L42 | train |
decidim/decidim | decidim-core/app/middleware/decidim/current_organization.rb | Decidim.CurrentOrganization.call | def call(env)
organization = detect_current_organization(env)
if organization
env["decidim.current_organization"] = organization
@app.call(env)
else
organization = find_secondary_host_org(env)
return @app.call(env) unless organization
location = new_location_for(env, organization.host)
[301, { "Location" => location, "Content-Type" => "text/html", "Content-Length" => "0" }, []]
end
end | ruby | def call(env)
organization = detect_current_organization(env)
if organization
env["decidim.current_organization"] = organization
@app.call(env)
else
organization = find_secondary_host_org(env)
return @app.call(env) unless organization
location = new_location_for(env, organization.host)
[301, { "Location" => location, "Content-Type" => "text/html", "Content-Length" => "0" }, []]
end
end | [
"def",
"call",
"(",
"env",
")",
"organization",
"=",
"detect_current_organization",
"(",
"env",
")",
"if",
"organization",
"env",
"[",
"\"decidim.current_organization\"",
"]",
"=",
"organization",
"@app",
".",
"call",
"(",
"env",
")",
"else",
"organization",
"=",
"find_secondary_host_org",
"(",
"env",
")",
"return",
"@app",
".",
"call",
"(",
"env",
")",
"unless",
"organization",
"location",
"=",
"new_location_for",
"(",
"env",
",",
"organization",
".",
"host",
")",
"[",
"301",
",",
"{",
"\"Location\"",
"=>",
"location",
",",
"\"Content-Type\"",
"=>",
"\"text/html\"",
",",
"\"Content-Length\"",
"=>",
"\"0\"",
"}",
",",
"[",
"]",
"]",
"end",
"end"
] | Initializes the Rack Middleware.
app - The Rack application
Main entry point for a Rack Middleware.
env - A Hash. | [
"Initializes",
"the",
"Rack",
"Middleware",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/middleware/decidim/current_organization.rb#L17-L30 | train |
decidim/decidim | decidim-core/app/commands/decidim/destroy_account.rb | Decidim.DestroyAccount.call | def call
return broadcast(:invalid) unless @form.valid?
Decidim::User.transaction do
destroy_user_account!
destroy_user_identities
destroy_user_group_memberships
destroy_follows
end
broadcast(:ok)
end | ruby | def call
return broadcast(:invalid) unless @form.valid?
Decidim::User.transaction do
destroy_user_account!
destroy_user_identities
destroy_user_group_memberships
destroy_follows
end
broadcast(:ok)
end | [
"def",
"call",
"return",
"broadcast",
"(",
":invalid",
")",
"unless",
"@form",
".",
"valid?",
"Decidim",
"::",
"User",
".",
"transaction",
"do",
"destroy_user_account!",
"destroy_user_identities",
"destroy_user_group_memberships",
"destroy_follows",
"end",
"broadcast",
"(",
":ok",
")",
"end"
] | Destroy a user's account.
user - The user to be updated.
form - The form with the data. | [
"Destroy",
"a",
"user",
"s",
"account",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/commands/decidim/destroy_account.rb#L15-L26 | train |
decidim/decidim | decidim-core/app/services/decidim/action_authorizer.rb | Decidim.ActionAuthorizer.authorize | def authorize
raise AuthorizationError, "Missing data" unless component && action
AuthorizationStatusCollection.new(authorization_handlers, user, component, resource)
end | ruby | def authorize
raise AuthorizationError, "Missing data" unless component && action
AuthorizationStatusCollection.new(authorization_handlers, user, component, resource)
end | [
"def",
"authorize",
"raise",
"AuthorizationError",
",",
"\"Missing data\"",
"unless",
"component",
"&&",
"action",
"AuthorizationStatusCollection",
".",
"new",
"(",
"authorization_handlers",
",",
"user",
",",
"component",
",",
"resource",
")",
"end"
] | Initializes the ActionAuthorizer.
user - The user to authorize against.
action - The action to authenticate.
component - The component to authenticate against.
resource - The resource to authenticate against. Can be nil.
Authorize user to perform an action in the context of a component.
Returns:
:ok an empty hash - When there is no authorization handler related to the action.
result of authorization handler check - When there is an authorization handler related to the action. Check Decidim::Verifications::DefaultActionAuthorizer class docs. | [
"Initializes",
"the",
"ActionAuthorizer",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/services/decidim/action_authorizer.rb#L29-L33 | train |
decidim/decidim | decidim-core/app/commands/decidim/update_account.rb | Decidim.UpdateAccount.call | def call
return broadcast(:invalid) unless @form.valid?
update_personal_data
update_avatar
update_password
if @user.valid?
@user.save!
notify_followers
broadcast(:ok, @user.unconfirmed_email.present?)
else
@form.errors.add :avatar, @user.errors[:avatar] if @user.errors.has_key? :avatar
broadcast(:invalid)
end
end | ruby | def call
return broadcast(:invalid) unless @form.valid?
update_personal_data
update_avatar
update_password
if @user.valid?
@user.save!
notify_followers
broadcast(:ok, @user.unconfirmed_email.present?)
else
@form.errors.add :avatar, @user.errors[:avatar] if @user.errors.has_key? :avatar
broadcast(:invalid)
end
end | [
"def",
"call",
"return",
"broadcast",
"(",
":invalid",
")",
"unless",
"@form",
".",
"valid?",
"update_personal_data",
"update_avatar",
"update_password",
"if",
"@user",
".",
"valid?",
"@user",
".",
"save!",
"notify_followers",
"broadcast",
"(",
":ok",
",",
"@user",
".",
"unconfirmed_email",
".",
"present?",
")",
"else",
"@form",
".",
"errors",
".",
"add",
":avatar",
",",
"@user",
".",
"errors",
"[",
":avatar",
"]",
"if",
"@user",
".",
"errors",
".",
"has_key?",
":avatar",
"broadcast",
"(",
":invalid",
")",
"end",
"end"
] | Updates a user's account.
user - The user to be updated.
form - The form with the data. | [
"Updates",
"a",
"user",
"s",
"account",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/commands/decidim/update_account.rb#L15-L30 | train |
decidim/decidim | decidim-core/app/helpers/decidim/resource_helper.rb | Decidim.ResourceHelper.linked_resources_for | def linked_resources_for(resource, type, link_name)
linked_resources = resource.linked_resources(type, link_name).group_by { |linked_resource| linked_resource.class.name }
safe_join(linked_resources.map do |klass, resources|
resource_manifest = klass.constantize.resource_manifest
content_tag(:div, class: "section") do
i18n_name = "#{resource.class.name.demodulize.underscore}_#{resource_manifest.name}"
content_tag(:h3, I18n.t(i18n_name, scope: "decidim.resource_links.#{link_name}"), class: "section-heading") +
render(partial: resource_manifest.template, locals: { resources: resources })
end
end)
end | ruby | def linked_resources_for(resource, type, link_name)
linked_resources = resource.linked_resources(type, link_name).group_by { |linked_resource| linked_resource.class.name }
safe_join(linked_resources.map do |klass, resources|
resource_manifest = klass.constantize.resource_manifest
content_tag(:div, class: "section") do
i18n_name = "#{resource.class.name.demodulize.underscore}_#{resource_manifest.name}"
content_tag(:h3, I18n.t(i18n_name, scope: "decidim.resource_links.#{link_name}"), class: "section-heading") +
render(partial: resource_manifest.template, locals: { resources: resources })
end
end)
end | [
"def",
"linked_resources_for",
"(",
"resource",
",",
"type",
",",
"link_name",
")",
"linked_resources",
"=",
"resource",
".",
"linked_resources",
"(",
"type",
",",
"link_name",
")",
".",
"group_by",
"{",
"|",
"linked_resource",
"|",
"linked_resource",
".",
"class",
".",
"name",
"}",
"safe_join",
"(",
"linked_resources",
".",
"map",
"do",
"|",
"klass",
",",
"resources",
"|",
"resource_manifest",
"=",
"klass",
".",
"constantize",
".",
"resource_manifest",
"content_tag",
"(",
":div",
",",
"class",
":",
"\"section\"",
")",
"do",
"i18n_name",
"=",
"\"#{resource.class.name.demodulize.underscore}_#{resource_manifest.name}\"",
"content_tag",
"(",
":h3",
",",
"I18n",
".",
"t",
"(",
"i18n_name",
",",
"scope",
":",
"\"decidim.resource_links.#{link_name}\"",
")",
",",
"class",
":",
"\"section-heading\"",
")",
"+",
"render",
"(",
"partial",
":",
"resource_manifest",
".",
"template",
",",
"locals",
":",
"{",
"resources",
":",
"resources",
"}",
")",
"end",
"end",
")",
"end"
] | Renders a collection of linked resources for a resource.
resource - The resource to get the links from.
type - The String type fo the resources we want to render.
link_name - The String name of the link between the resources.
Example to render the proposals in a meeting view:
linked_resources_for(:meeting, :proposals, "proposals_from_meeting")
Returns nothing. | [
"Renders",
"a",
"collection",
"of",
"linked",
"resources",
"for",
"a",
"resource",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/resource_helper.rb#L17-L28 | train |
decidim/decidim | decidim-core/app/helpers/decidim/resource_helper.rb | Decidim.ResourceHelper.resource_title | def resource_title(resource)
title = resource.try(:title) || resource.try(:name) || resource.try(:subject) || "#{resource.model_name.human} ##{resource.id}"
title = translated_attribute(title) if title.is_a?(Hash)
title
end | ruby | def resource_title(resource)
title = resource.try(:title) || resource.try(:name) || resource.try(:subject) || "#{resource.model_name.human} ##{resource.id}"
title = translated_attribute(title) if title.is_a?(Hash)
title
end | [
"def",
"resource_title",
"(",
"resource",
")",
"title",
"=",
"resource",
".",
"try",
"(",
":title",
")",
"||",
"resource",
".",
"try",
"(",
":name",
")",
"||",
"resource",
".",
"try",
"(",
":subject",
")",
"||",
"\"#{resource.model_name.human} ##{resource.id}\"",
"title",
"=",
"translated_attribute",
"(",
"title",
")",
"if",
"title",
".",
"is_a?",
"(",
"Hash",
")",
"title",
"end"
] | Returns a descriptive title for the resource | [
"Returns",
"a",
"descriptive",
"title",
"for",
"the",
"resource"
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/resource_helper.rb#L74-L78 | train |
decidim/decidim | decidim-core/app/helpers/decidim/paginate_helper.rb | Decidim.PaginateHelper.decidim_paginate | def decidim_paginate(collection, paginate_params = {})
# Kaminari uses url_for to generate the url, but this doesn't play nice with our engine system
# and unless we remove these params they are added again as query string :(
default_params = {
participatory_process_id: nil,
component_id: nil
}
paginate collection, theme: "decidim", params: paginate_params.merge(default_params)
end | ruby | def decidim_paginate(collection, paginate_params = {})
# Kaminari uses url_for to generate the url, but this doesn't play nice with our engine system
# and unless we remove these params they are added again as query string :(
default_params = {
participatory_process_id: nil,
component_id: nil
}
paginate collection, theme: "decidim", params: paginate_params.merge(default_params)
end | [
"def",
"decidim_paginate",
"(",
"collection",
",",
"paginate_params",
"=",
"{",
"}",
")",
"default_params",
"=",
"{",
"participatory_process_id",
":",
"nil",
",",
"component_id",
":",
"nil",
"}",
"paginate",
"collection",
",",
"theme",
":",
"\"decidim\"",
",",
"params",
":",
"paginate_params",
".",
"merge",
"(",
"default_params",
")",
"end"
] | Displays pagination links for the given collection, setting the correct
theme. This mostly acts as a proxy for the underlying pagination engine.
collection - a collection of elements that need to be paginated
paginate_params - a Hash with options to delegate to the pagination helper. | [
"Displays",
"pagination",
"links",
"for",
"the",
"given",
"collection",
"setting",
"the",
"correct",
"theme",
".",
"This",
"mostly",
"acts",
"as",
"a",
"proxy",
"for",
"the",
"underlying",
"pagination",
"engine",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/helpers/decidim/paginate_helper.rb#L11-L20 | train |
decidim/decidim | decidim-core/app/models/decidim/action_log.rb | Decidim.ActionLog.participatory_space_lazy | def participatory_space_lazy(cache: true)
return if participatory_space_id.blank? || participatory_space_type.blank?
return resouce_lazy if participatory_space_id == resource_id && participatory_space_type == resource_type
self.class.lazy_relation(participatory_space_id, participatory_space_type, cache)
end | ruby | def participatory_space_lazy(cache: true)
return if participatory_space_id.blank? || participatory_space_type.blank?
return resouce_lazy if participatory_space_id == resource_id && participatory_space_type == resource_type
self.class.lazy_relation(participatory_space_id, participatory_space_type, cache)
end | [
"def",
"participatory_space_lazy",
"(",
"cache",
":",
"true",
")",
"return",
"if",
"participatory_space_id",
".",
"blank?",
"||",
"participatory_space_type",
".",
"blank?",
"return",
"resouce_lazy",
"if",
"participatory_space_id",
"==",
"resource_id",
"&&",
"participatory_space_type",
"==",
"resource_type",
"self",
".",
"class",
".",
"lazy_relation",
"(",
"participatory_space_id",
",",
"participatory_space_type",
",",
"cache",
")",
"end"
] | Lazy loads the `participatory_space` association through BatchLoader, can be used
as a regular object. | [
"Lazy",
"loads",
"the",
"participatory_space",
"association",
"through",
"BatchLoader",
"can",
"be",
"used",
"as",
"a",
"regular",
"object",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/models/decidim/action_log.rb#L79-L84 | train |
decidim/decidim | decidim-core/app/services/decidim/resource_search.rb | Decidim.ResourceSearch.search_scope_id | def search_scope_id
clean_scope_ids = if scope_id.is_a?(Hash)
scope_id.values
else
[scope_id].flatten
end
conditions = []
conditions << "decidim_scope_id IS NULL" if clean_scope_ids.delete("global")
conditions.concat(["? = ANY(decidim_scopes.part_of)"] * clean_scope_ids.count) if clean_scope_ids.any?
query.includes(:scope).references(:decidim_scopes).where(conditions.join(" OR "), *clean_scope_ids.map(&:to_i))
end | ruby | def search_scope_id
clean_scope_ids = if scope_id.is_a?(Hash)
scope_id.values
else
[scope_id].flatten
end
conditions = []
conditions << "decidim_scope_id IS NULL" if clean_scope_ids.delete("global")
conditions.concat(["? = ANY(decidim_scopes.part_of)"] * clean_scope_ids.count) if clean_scope_ids.any?
query.includes(:scope).references(:decidim_scopes).where(conditions.join(" OR "), *clean_scope_ids.map(&:to_i))
end | [
"def",
"search_scope_id",
"clean_scope_ids",
"=",
"if",
"scope_id",
".",
"is_a?",
"(",
"Hash",
")",
"scope_id",
".",
"values",
"else",
"[",
"scope_id",
"]",
".",
"flatten",
"end",
"conditions",
"=",
"[",
"]",
"conditions",
"<<",
"\"decidim_scope_id IS NULL\"",
"if",
"clean_scope_ids",
".",
"delete",
"(",
"\"global\"",
")",
"conditions",
".",
"concat",
"(",
"[",
"\"? = ANY(decidim_scopes.part_of)\"",
"]",
"*",
"clean_scope_ids",
".",
"count",
")",
"if",
"clean_scope_ids",
".",
"any?",
"query",
".",
"includes",
"(",
":scope",
")",
".",
"references",
"(",
":decidim_scopes",
")",
".",
"where",
"(",
"conditions",
".",
"join",
"(",
"\" OR \"",
")",
",",
"*",
"clean_scope_ids",
".",
"map",
"(",
"&",
":to_i",
")",
")",
"end"
] | Handles the scope_id filter. When we want to show only those that do not
have a scope_id set, we cannot pass an empty String or nil because Searchlight
will automatically filter out these params, so the method will not be used.
Instead, we need to pass a fake ID and then convert it inside. In this case,
in order to select those elements that do not have a scope_id set we use
`"global"` as parameter, and in the method we do the needed changes to search
properly. | [
"Handles",
"the",
"scope_id",
"filter",
".",
"When",
"we",
"want",
"to",
"show",
"only",
"those",
"that",
"do",
"not",
"have",
"a",
"scope_id",
"set",
"we",
"cannot",
"pass",
"an",
"empty",
"String",
"or",
"nil",
"because",
"Searchlight",
"will",
"automatically",
"filter",
"out",
"these",
"params",
"so",
"the",
"method",
"will",
"not",
"be",
"used",
".",
"Instead",
"we",
"need",
"to",
"pass",
"a",
"fake",
"ID",
"and",
"then",
"convert",
"it",
"inside",
".",
"In",
"this",
"case",
"in",
"order",
"to",
"select",
"those",
"elements",
"that",
"do",
"not",
"have",
"a",
"scope_id",
"set",
"we",
"use",
"global",
"as",
"parameter",
"and",
"in",
"the",
"method",
"we",
"do",
"the",
"needed",
"changes",
"to",
"search",
"properly",
"."
] | 6e2b14e559a63088669904e3c5c49a5180700cf7 | https://github.com/decidim/decidim/blob/6e2b14e559a63088669904e3c5c49a5180700cf7/decidim-core/app/services/decidim/resource_search.rb#L40-L52 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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'",
")",
"next",
"if",
"function_name",
".",
"include?",
"(",
"'jets-rack_controller'",
")",
"threads",
"<<",
"Thread",
".",
"new",
"do",
"warm",
"(",
"function_name",
")",
"end",
"end",
"threads",
".",
"each",
"{",
"|",
"t",
"|",
"t",
".",
"join",
"}",
"warm_public_controller_more",
"warm_rack_controller_more",
"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 | train |
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",
")",
"props",
"=",
"{",
"sql",
":",
"props",
"}",
"topic_props",
"=",
"{",
"topic_rule_payload",
":",
"props",
"}",
"elsif",
"props",
".",
"key?",
"(",
":topic_rule_payload",
")",
"topic_props",
"=",
"props",
"else",
"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 | train |
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",
"=",
"{",
"}",
"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 | train |
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 | train |
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",
"definition",
"=",
"\"#{definition}:*\"",
"unless",
"definition",
".",
"include?",
"(",
"':'",
")",
"@policy",
"[",
":statement",
"]",
"<<",
"{",
"action",
":",
"[",
"definition",
"]",
",",
"effect",
":",
"\"Allow\"",
",",
"resource",
":",
"\"*\"",
",",
"}",
"when",
"Hash",
"definition",
"=",
"definition",
".",
"stringify_keys",
"if",
"definition",
".",
"key?",
"(",
"\"Version\"",
")",
"@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 | train |
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 | train |
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 | train |
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\"",
"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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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",
"Bundler",
".",
"with_clean_env",
"do",
"args",
"=",
"''",
"if",
"@options",
"[",
":host",
"]",
"args",
"<<",
"\" --host #{@options[:host]}\"",
"else",
"args",
"<<",
"\" --host 127.0.0.1\"",
"end",
"command",
"=",
"\"cd #{rack_project} && bin/rackup#{args}\"",
"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 | train |
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",
"delay",
"=",
"0.5",
"if",
"ENV",
"[",
"'C9_USER'",
"]",
"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 | train |
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",
")",
"if",
"message",
".",
"nil?",
"if",
"block_given?",
"message",
"=",
"yield",
"else",
"message",
"=",
"progname",
"progname",
"=",
"@progname",
"end",
"end",
"IO",
".",
"buffer",
"<<",
"message",
"super",
"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 | train |
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?",
"lines",
"=",
"text",
".",
"split",
"(",
"\"\\n\"",
")",
"lines",
".",
"map",
"do",
"|",
"line",
"|",
"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 | train |
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 | train |
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?",
"return",
"if",
"File",
".",
"exist?",
"(",
"\"#{Jets.root}/config/disable-webpacker-middleware.txt\"",
")",
"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 | train |
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?",
"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 | train |
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 | train |
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'",
"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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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?",
"@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 | train |
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",
"if",
"pr",
"[",
"\"events\"",
"]",
"&&",
"(",
"event",
"=",
"pr",
"[",
"\"events\"",
"]",
".",
"find",
"{",
"|",
"e",
"|",
"e",
"[",
"\"event\"",
"]",
"==",
"\"merged\"",
"}",
")",
"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",
"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 | train |
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\"",
"]",
"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 | train |
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",
")",
"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 | train |
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. \\Make sure, that you push tags to remote repo via 'git push --tags'\"",
"else",
"Helper",
".",
"log",
".",
"info",
"\"Found #{tags.count} tags\"",
"end",
"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 | train |
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",
"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 | train |
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 | train |
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 | train |
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 | train |
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",
"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 | train |
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",
"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",
"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 | train |
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 | train |
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",
")",
"all_sorted_tags",
"=",
"sort_tags_by_date",
"(",
"all_tags",
")",
"@sorted_tags",
"=",
"filter_excluded_tags",
"(",
"all_sorted_tags",
")",
"@filtered_tags",
"=",
"get_filtered_tags",
"(",
"@sorted_tags",
")",
"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 | train |
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 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.