source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
katsuma/itunes-client
https://github.com/katsuma/itunes-client
lib/itunes/track.rb
Ruby
mit
48
master
3,358
# coding: utf-8 require 'json' require 'itunes/util' module Itunes class Track include Itunes::Util::Executor extend Itunes::Util::Executor ATTRIBUTES = [ :persistent_id, :name, :album, :artist, :track_count, :track_number, :year, :season_number, :ep...
github
katsuma/itunes-client
https://github.com/katsuma/itunes-client
lib/itunes/util/executor.rb
Ruby
mit
48
master
1,192
# coding: utf-8 module Itunes module Util module Executor def generate_script_from_template(template_path, args) body = '' script_name = "#{Time.now.to_i}.#{rand(1000)}.scpt" script_path = "#{script_tmp_dir}/#{script_name}" open("#{script_base_dir}/#{template_path}", 'r') do...
github
katsuma/itunes-client
https://github.com/katsuma/itunes-client
spec/spec_helper.rb
Ruby
mit
48
master
452
# coding: utf-8 require 'bundler' require 'fakefs/spec_helpers' require 'simplecov' require 'coveralls' Bundler.setup(:default, :development) RSpec.configure do |config| config.color = true config.tty = true #config.formatter = :documentation config.include FakeFS::SpecHelpers, fakefs: true end SimpleCov.fo...
github
katsuma/itunes-client
https://github.com/katsuma/itunes-client
spec/itunes/player_spec.rb
Ruby
mit
48
master
5,226
# coding: utf-8 require 'spec_helper' require 'itunes-client' include Itunes describe Player do describe '.add' do subject(:add) { Player.add(file_name) } let(:file_name) { './foo.wav' } let(:new_persistent_id) { 'foo' } before do FileUtils.rm_f(file_name) end context 'when existent...
github
katsuma/itunes-client
https://github.com/katsuma/itunes-client
spec/itunes/volume_spec.rb
Ruby
mit
48
master
1,036
require 'spec_helper' require 'itunes-client' include Itunes describe Volume do let(:level) { an_instance_of(Fixnum) } describe '.up' do it 'calls up.scpt' do expect(Volume).to receive(:execute_script).with('volume/up.scpt', level) Volume.up end end describe '.down' do it 'calls down...
github
katsuma/itunes-client
https://github.com/katsuma/itunes-client
spec/itunes/track_spec.rb
Ruby
mit
48
master
4,760
# coding: utf-8 require 'spec_helper' require 'itunes-client' include Itunes describe Track do let(:track) do Track.new(persistent_id: base_persistent_id, name: base_name, album: base_album) end let(:player) { Itunes::Player } let(:base_persistent_id) { 'foo' } let(:base_name) { 'base name' } let(:bas...
github
katsuma/itunes-client
https://github.com/katsuma/itunes-client
spec/itunes/util/executor_spec.rb
Ruby
mit
48
master
2,046
# coding: utf-8 require 'spec_helper' require 'itunes/util' describe Itunes::Util::Executor do class DummyClass include Itunes::Util::Executor end let!(:klass) { DummyClass.new } describe '#execute_script' do subject(:execute_script) { klass.execute_script(path, args) } let(:path) { 'foo.scpt' } ...
github
alphagov/publisher
https://github.com/alphagov/publisher
Rakefile
Ruby
mit
48
main
379
# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path("config/application", __dir__) require "rake" require "rake/testtask" if Rails.env.test? Rake.application.options.trace = true Rails.a...
github
alphagov/publisher
https://github.com/alphagov/publisher
Gemfile
Ruby
mit
48
main
1,687
source "https://rubygems.org" gem "rails", "8.1.3" gem "aws-sdk-s3", "~> 1" gem "bootsnap", require: false gem "bootstrap-kaminari-views" gem "csv" gem "dartsass-rails" gem "diffy" gem "dry-validation" gem "erb_lint" gem "erubis" gem "flipflop" gem "gds-api-adapters" gem "gds-sso" gem "google-apis-gmail_v1" gem "govs...
github
alphagov/publisher
https://github.com/alphagov/publisher
lib/csv_report_generator.rb
Ruby
mit
48
main
1,649
require "redis" require "redis-lock" class CsvReportGenerator def run! Redis.new.lock("publisher:report_generation_lock", life: 900) do presenters.each do |presenter| report = Report.new(presenter.report_name) Rails.logger.debug "Uploading #{report.filename} to S3" report.upload_to...
github
alphagov/publisher
https://github.com/alphagov/publisher
lib/working_days_calculator.rb
Ruby
mit
48
main
886
require "gds_api/calendars" class WorkingDaysCalculator def initialize(starting_from, in_division: :england_and_wales) @starting_from = starting_from @calendar_division = in_division end def after(how_many_days, skip_days: 0) days = (@starting_from.tomorrow..(@starting_from + how_many_days + skip_da...
github
alphagov/publisher
https://github.com/alphagov/publisher
lib/sidekiq_gds_sso_middleware.rb
Ruby
mit
48
main
705
require "sidekiq/web" class SidekiqGdsSsoMiddleware SIDEKIQ_SIGNON_PERMISSION = "sidekiq_admin".freeze def self.call(...) = new(...).call def initialize(env) @env = env @warden = env.fetch("warden") end def call status, headers, body = authenticated_sidekiq_request [status, headers, body]...
github
alphagov/publisher
https://github.com/alphagov/publisher
lib/tasks/local_transactions.rake
Ruby
mit
48
main
537
namespace :local_transactions do desc "Imports services and removes any old ones" task fetch_and_clean: :environment do Rake::Task["local_transactions:update_services"].invoke Rake::Task["local_transactions:remove_old_services"].invoke end desc "Import services from the service list CSV" task update_...
github
alphagov/publisher
https://github.com/alphagov/publisher
lib/tasks/publish_missed_scheduled_editions.rake
Ruby
mit
48
main
434
namespace :editions do desc "Publish editions missed in scheduled publishing" task publish_missed_scheduled_editions: :environment do scheduled_editions = Edition.scheduled_for_publishing.where("publish_at < ?", Time.zone.now) scheduled_editions.each do |edition| ScheduledPublisher.new.perform(editio...
github
alphagov/publisher
https://github.com/alphagov/publisher
lib/tasks/schema_tests.rake
Ruby
mit
48
main
281
require "rake/testtask" namespace :test do Rake::TestTask.new(schemas: "test:prepare") do |t| t.libs << "test" t.test_files = `grep -rlE "schema" test`.lines.map(&:chomp) end Rake::Task["test:schemas"].comment = "Test Publishing API presenters against schemas" end
github
alphagov/publisher
https://github.com/alphagov/publisher
lib/tasks/access_and_permissions.rake
Ruby
mit
48
main
2,506
require "csv" namespace :permissions do desc "Add an organisation to a document's access permissions list" task :add_organisation_access, %i[document_content_id org_content_id log_file] => :environment do |_, args| document = Artefact.find_by(id: args[:document_content_id]) if document.nil? message ...
github
alphagov/publisher
https://github.com/alphagov/publisher
lib/tasks/publishing_api.rake
Ruby
mit
48
main
1,628
namespace :publishing_api do desc "republish content" task republish_content: [:environment] do draft_editions = Edition.draft_in_publishing_api editions = Edition.published editions.each do |edition| RepublishWorker.perform_async(edition.id.to_s) end draft_editions.each do |draft_editio...
github
alphagov/publisher
https://github.com/alphagov/publisher
lib/tasks/create_popular_links_and_link_to_homepage.rake
Ruby
mit
48
main
1,037
desc "Create popular links and links to homepage" task create_popular_links_and_link_to_homepage: [:environment] do homepage_content_id = "f3bbdec2-0e62-4520-a7fd-6ffd5d36e03a".freeze popular_links = PopularLinksEdition.new(title: "Homepage popular links", link_items: [{ ur...
github
alphagov/publisher
https://github.com/alphagov/publisher
lib/tasks/orphaned_editions.rake
Ruby
mit
48
main
1,180
namespace :orphaned_editions do qualifying_edition_states = %w[ ready amends_needed fact_check_received fact_check draft in_review ].freeze desc "Report on editions having an artefact with the state 'archived'" task report: :environment do puts "Searching for orphaned editions..." ...
github
alphagov/publisher
https://github.com/alphagov/publisher
lib/tasks/requeue_editions_scheduled_for_publishing.rake
Ruby
mit
48
main
577
namespace :editions do desc "Re-queue editions scheduled for publishing" task requeue_scheduled_for_publishing: :environment do criteria = Edition.scheduled_for_publishing editions_scheduled_for_publishing_count = criteria.count puts " clearing scheduled publishing queue" ScheduledPublisher.dequeue...
github
alphagov/publisher
https://github.com/alphagov/publisher
config/application.rb
Ruby
mit
48
main
6,485
require_relative "boot" require "rails" # Pick the frameworks you want: require "active_model/railtie" require "active_record/railtie" require "active_job/railtie" require "action_controller/railtie" require "action_mailer/railtie" require "action_view/railtie" require "rails/test_unit/railtie" require "open-uri" req...
github
alphagov/publisher
https://github.com/alphagov/publisher
config/features.rb
Ruby
mit
48
main
1,159
Flipflop.configure do # Strategies will be used in the order listed here. strategy :cookie strategy :default if Rails.env.test? feature :feature_for_tests, default: true, description: "A feature only used by tests; not to be used for any actual features." end group "For all use...
github
alphagov/publisher
https://github.com/alphagov/publisher
config/routes.rb
Ruby
mit
48
main
7,415
require "sidekiq/web" Rails.application.routes.draw do get "/healthcheck/live", to: proc { [200, {}, %w[OK]] } get "/healthcheck/ready", to: GovukHealthcheck.rack_response( GovukHealthcheck::ActiveRecord, GovukHealthcheck::SidekiqRedis, ) get "/healthcheck/scheduled-publishing", to: "healthcheck#sched...
github
alphagov/publisher
https://github.com/alphagov/publisher
config/initializers/fact_check.rb
Ruby
mit
48
main
347
require "yaml" require "fact_check_config" config_file_path = Rails.root.join("config/fact_check.yml") config = YAML.safe_load( ERB.new(File.read(config_file_path)).result, ) Publisher::Application.fact_check_config = FactCheckConfig.new( config.fetch("reply_to_address"), config.fetch("subject_prefix"), conf...
github
alphagov/publisher
https://github.com/alphagov/publisher
config/initializers/dartsass.rb
Ruby
mit
48
main
358
APP_STYLESHEETS = { "application.scss" => "application.css", "legacy-application.scss" => "legacy-application.css", }.freeze all_stylesheets = APP_STYLESHEETS.merge(GovukPublishingComponents::Config.component_guide_stylesheet) Rails.application.config.dartsass.builds = all_stylesheets Rails.application.config.dart...
github
alphagov/publisher
https://github.com/alphagov/publisher
config/initializers/session_store.rb
Ruby
mit
48
main
235
# Be sure to restart your server when you modify this file. Rails.application.config.session_store( :cookie_store, key: "_publisher_session", secure: Rails.env.production? && !ENV["DISABLE_SECURE_COOKIES"], http_only: true, )
github
alphagov/publisher
https://github.com/alphagov/publisher
config/initializers/param_parsers.rb
Ruby
mit
48
main
231
# Turn off XML parsing: # https://groups.google.com/forum/#!topic/rubyonrails-security/61bkgvnSGTQ/discussion ActionDispatch::Request::DEFAULT_PARSERS.delete(Mime[:xml]) ActionDispatch::Request::DEFAULT_PARSERS.delete(Mime[:json])
github
alphagov/publisher
https://github.com/alphagov/publisher
config/initializers/inflections.rb
Ruby
mit
48
main
639
# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections # are locale specific, and you may define rules for as many different # locales as you wish. All of these examples are active by default: # ActiveSupport::Inflector.inflections(:en) do |inflec...
github
alphagov/publisher
https://github.com/alphagov/publisher
config/initializers/assets.rb
Ruby
mit
48
main
514
# Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. Rails.application.config.assets.version = "1.0" # Add additional assets to the asset load path. Rails.application.config.assets.paths << Rails.root.join("node_modules") # Precompil...
github
alphagov/publisher
https://github.com/alphagov/publisher
config/initializers/rack_query_parser.rb
Ruby
mit
48
main
227
# Increase params_limit from default of 4096 due to large simple smart answers exceeding this # Leave params_depth_limit as default 32 Rack::Utils.default_query_parser = Rack::QueryParser.make_default(32, params_limit: 10_000)
github
alphagov/publisher
https://github.com/alphagov/publisher
config/initializers/email_groups.rb
Ruby
mit
48
main
380
EMAIL_GROUPS = { business: [ENV.fetch("EMAIL_GROUP_BUSINESS", "publisher-alerts-business@digital.cabinet-office.gov.uk")], citizen: [ENV.fetch("EMAIL_GROUP_CITIZEN", "publisher-alerts-citizen@digital.cabinet-office.gov.uk")], force_publish_alerts: [ENV.fetch("EMAIL_GROUP_FORCE_PUBLISH_ALERTS", "mainstream-force-p...
github
alphagov/publisher
https://github.com/alphagov/publisher
config/initializers/edition_state_count_reporter.rb
Ruby
mit
48
main
398
require "state_count_reporter" module Publisher class Application # We can't simply assign this at initialisation time, because the # initialiser for the Statsd client may not have been loaded def edition_state_count_reporter @edition_state_count_reporter ||= StateCountReporter.new( Edition...
github
alphagov/publisher
https://github.com/alphagov/publisher
config/initializers/secrets_to_credentials.rb
Ruby
mit
48
main
508
# Rails 7 has begun to deprecate Rails.application.secrets in favour # of Rails.application.credentials, but that adds the burden of master key # administration without giving us any benefit (because our production # secrets are handled as env vars, not committed to our repo. Here we # load the config/secrets.YML value...
github
alphagov/publisher
https://github.com/alphagov/publisher
config/environments/test.rb
Ruby
mit
48
main
3,225
require "active_support/core_ext/integer/time" # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data the...
github
alphagov/publisher
https://github.com/alphagov/publisher
config/environments/development.rb
Ruby
mit
48
main
4,037
require "active_support/core_ext/integer/time" Rails.application.configure do # Before filter for Flipflop dashboard. Replace with a lambda or method name # defined in ApplicationController to implement access control. config.flipflop.dashboard_access_filter = nil # By default, when set to `nil`, strategy loa...
github
alphagov/publisher
https://github.com/alphagov/publisher
config/environments/production.rb
Ruby
mit
48
main
5,083
require "active_support/core_ext/integer/time" Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.enable_reloading = false # Eager load code on boot for better performance and memory savings (ignor...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/publications_helper.rb
Ruby
mit
48
main
590
module PublicationsHelper def status_class_for(publication) "factchecked" if publication.fact_checked? end def timestamp(time) return if time.nil? %(<time datetime="#{time.strftime('%Y-%m-%dT%H:%M:%SZ')}">#{time.strftime('%d/%m/%Y %H:%M')}</time>).html_safe end def content_tagger_url(edition) ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/common_components_helper.rb
Ruby
mit
48
main
837
module CommonComponentsHelper def header_for(tab_name) render "govuk_publishing_components/components/heading", { text: tab_name, heading_level: 2, margin_bottom: 5, } end def primary_button_for(model, url, text) form_for model, url:, method: :post do render "govuk_publishing_...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/footer_helper.rb
Ruby
mit
48
main
1,114
module FooterHelper def footer_items(is_editor: false) footer_items = [] footer_items << { title: "Reports, downtime and users", items: first_section(is_editor), } footer_items << { title: "Support and feedback", columns: 2, items: second_section, ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/form_helper.rb
Ruby
mit
48
main
1,087
module FormHelper def form_errors(errors, field_name) tag.div(id: "error-#{field_name.to_s.dasherize}") do tag.ul(class: %w[help-block error-block]) do safe_join(errors.map { |e| tag.li(e) }) end end end def form_group(form, field_name, label: nil, help: nil, attributes: {}, &block) ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/tabs_helper.rb
Ruby
mit
48
main
963
module TabsHelper # rubocop:disable Rails/HelperInstanceVariable def active_tab return @active_tab if @active_tab visited_tab = request.path.split("/").last tab_name = [visited_tab] & %w[metadata tagging history admin related_external_links unpublish] @active_tab = tab_name.blank? ? Edition::Tab["e...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/editions_helper.rb
Ruby
mit
48
main
4,492
module EditionsHelper EDITION_STATUS_TAG_COLOURS = { amends_needed: "red", archived: "blue", draft: "yellow", fact_check: "purple", fact_check_received: "pink", ready: "green", scheduled_for_publishing: "turquoise", published: "orange", in_review: "grey", }.freeze # edition tr...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/edition_activity_buttons_helper.rb
Ruby
mit
48
main
2,673
module EditionActivityButtonsHelper def build_review_button(edition, activity, title) check_method = "can_#{activity}?".to_sym enabled = edition.send(check_method) link_to title, "##{activity}_form", data: { toggle: "modal" }, class: "btn btn-info #{'disabled' unless e...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/paths_helper.rb
Ruby
mit
48
main
1,730
module PathsHelper def edition_front_end_path(edition) "#{preview_url(edition)}/#{edition.slug}" end def preview_edition_path(edition) path = edition_front_end_path(edition) if should_have_auth_bypass_id?(edition) path << "?token=#{jwt_token(edition)}" end path end def preview_ed...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/error_summary_helper.rb
Ruby
mit
48
main
2,153
module ErrorSummaryHelper def errors_to_display(edition) case edition.editionable when SimpleSmartAnswerEdition smart_answer_errors(edition) else edition_errors(edition) end end private def edition_errors(edition) top_level_errors(edition).map { |error, href| [error.message, href...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/base_helper.rb
Ruby
mit
48
main
1,944
module BaseHelper def publication_tab_list(presenter, options) state_names = { drafts: "Drafts", in_review: humanize_state("in_review"), amends_needed: "Amends needed", out_for_fact_check: humanize_state("out_for_fact_check"), fact_check_received: "Fact check received", ready: ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/application_helper.rb
Ruby
mit
48
main
1,040
module ApplicationHelper # Set class on active navigation items def nav_link(text, link) recognized = Rails.application.routes.recognize_path(link) if recognized[:controller] == params[:controller] && recognized[:action] == params[:action] tag.li(class: "active") do link_to(text, link) e...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/publications_table_helper.rb
Ruby
mit
48
main
1,477
module PublicationsTableHelper def reviewer(publication, current_user) if publication.state == "in_review" if publication.reviewer.present? publication.reviewer elsif current_user != publication.assigned_to && current_user.has_editor_permissions?(publication) render partial: "root/clai...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/important_note_helper.rb
Ruby
mit
48
main
240
module ImportantNoteHelper def important_notes(edition) edition.actions.reverse.select { |a| a.request_type == Action::IMPORTANT_NOTE } end def important_note_has_history?(edition) important_notes(edition).size > 1 end end
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/pagination_helper.rb
Ruby
mit
48
main
3,745
module PaginationHelper class << self LARGE_NUMBER_OF_PAGES = 6 def pagination_hash(current_page:, total_pages:, path:) return if total_pages == 1 self.current_page = current_page self.total_pages = total_pages self.path = normalise_path(path, current_page) previous_page = cur...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/downtimes_helper.rb
Ruby
mit
48
main
1,639
module DowntimesHelper def downtime_datetime(downtime) start_time = downtime.start_time end_time = downtime.end_time time_format = "%l:%M%P" date_format = "on %e %B" datetime_format = "#{time_format} #{date_format}" strings = if start_time.to_date == (end_time - 1.second).to_date ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/edition_activity_helper.rb
Ruby
mit
48
main
1,408
module EditionActivityHelper def edition_activities_fields(form, edition) activities_fields = Edition::ACTIONS.map do |activity, title| tag.div(**modal_attributes.merge(id: "#{activity}_form")) do edition_activity_fields(edition, title, activity, form, inline: true) end end activities...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/tagging_helper.rb
Ruby
mit
48
main
1,566
module TaggingHelper def tag_summary_rows(type, tagging_update_form_values, linkables, key_text) items = case type when "breadcrumb" breadcrumb(tagging_update_form_values.parent, linkables) when "browse_pages" browse_pages(tagging_update_form_values.mainstream_b...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/errors_helper.rb
Ruby
mit
48
main
320
module ErrorsHelper def errors_for(errors, attribute, use_full_message: true) return nil if errors.blank? errors.filter_map { |error| if error.attribute == attribute { text: use_full_message ? error.full_message : error.message, } end } .presence end end
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/navigation_items_helper.rb
Ruby
mit
48
main
782
module NavigationItemsHelper def navigation_items(is_editor: false, user_name: "", path: "") [ { text: "My content", href: my_content_path, active: path.end_with?(my_content_path) }, { text: "Find content", href: find_content_path, active: path.end_with?(find_content_path) }, ({ text: "Create ne...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/action_helper.rb
Ruby
mit
48
main
4,653
module ActionHelper def edition_actions(edition, update_events) actions = edition.actions.reject do |a| [Action::IMPORTANT_NOTE, Action::IMPORTANT_NOTE_RESOLVED].include?(a.request_type) end update_actions = update_events.select { |e| e.is_for_edition?(edition) }.map(&:to_action) actions.append(...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/tabbed_nav_helper.rb
Ruby
mit
48
main
3,183
module TabbedNavHelper def edition_nav_items(edition, current_user) nav_items = [] accessible_tabs(current_user, edition).each do |item| next if !edition.state.eql?("published") && item == "unpublish" nav_items << standard_nav_items(item, edition) end nav_items.flatten end def curr...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/legacy_action_helper.rb
Ruby
mit
48
main
3,300
module LegacyActionHelper def edition_actions(edition, update_events) actions = edition.actions.reject do |a| [Action::IMPORTANT_NOTE, Action::IMPORTANT_NOTE_RESOLVED].include?(a.request_type) end update_actions = update_events.select { |e| e.is_for_edition?(edition) }.map(&:to_action) actions.a...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/analytics_helper.rb
Ruby
mit
48
main
276
module AnalyticsHelper def track_analytics_data_on_load(title) { event: "page_view", page_view: { publishing_app: "publisher", user_created_at: current_user&.created_at&.to_date, document_type: title, }, }.to_json end end
github
alphagov/publisher
https://github.com/alphagov/publisher
app/helpers/editions_sidebar_buttons_helper.rb
Ruby
mit
48
main
7,168
# frozen_string_literal: true module EditionsSidebarButtonsHelper def sidebar_options_heading render "govuk_publishing_components/components/heading", { text: "Options", heading_level: 3, font_size: "s", padding: true, } end def sidebar_items_list(items) render "govuk_publish...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/middleware/maintenance_mode.rb
Ruby
mit
48
main
554
class MaintenanceMode def initialize(app) @app = app end def call(env) if maintenance_enabled? && !healthcheck_request?(env) return [503, { "Content-Type" => "text/html" }, [maintenance_page]] end @app.call(env) end private def healthcheck_request?(env) env.fetch("PATH_INFO").sta...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/services/link_check_report_creator.rb
Ruby
mit
48
main
1,563
class LinkCheckReportCreator include Rails.application.routes.url_helpers CALLBACK_HOST = Plek.find("publisher") class InvalidReport < RuntimeError def initialize(original_error) super original_error.message end end def initialize(edition:) @edition = edition end def call return ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/services/link_check_report_finder.rb
Ruby
mit
48
main
259
class LinkCheckReportFinder def initialize(report_id:) @report_id = report_id end def call link_check_report end private attr_reader :report_id def link_check_report @link_check_report ||= LinkCheckReport.find(report_id) end end
github
alphagov/publisher
https://github.com/alphagov/publisher
app/services/publishing_api_workflow_bypass_publisher.rb
Ruby
mit
48
main
1,005
class PublishingApiWorkflowBypassPublisher def initialize(artefact) @artefact = artefact end def self.call(artefact) new(artefact).call end def call return if artefact.nil? discard_draft if has_local_draft? republish_currently_live_edition if has_live_edition? put_draft_content if h...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/services/fact_check_manager_api_service.rb
Ruby
mit
48
main
1,974
class FactCheckManagerApiService extend WorkingDaysHelper SOURCE_APP = "publisher".freeze def self.request_fact_check(edition, requester, email_addresses) payload = build_post_payload(edition, requester, email_addresses) Services.fact_check_manager_api.post_fact_check(**payload) end def self.resend...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/services/edition_presenter_factory.rb
Ruby
mit
48
main
1,114
class EditionPresenterFactory class << self def get_presenter(edition) if edition.instance_of?(::PopularLinksEdition) presenter_class(edition.class.to_s).constantize.new(edition) else presenter_class(edition.editionable_class.to_s).constantize.new(edition) end end def pr...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/services/event_notifier_service.rb
Ruby
mit
48
main
1,438
class EventNotifierService def self.any_action(action, mailer: EventMailer) recipient_emails = (EMAIL_GROUPS[:citizen] + EMAIL_GROUPS[:business]).uniq emails = recipient_emails.map do |recipient_email| mailer.any_action(action, recipient_email) end emails.map(&:deliver_now) end def self.s...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/services/edition_link_extractor.rb
Ruby
mit
48
main
1,047
require "govspeak/link_extractor" class EditionLinkExtractor def initialize(edition:) @edition = edition end def call find_links_in_edition end private attr_reader :edition def website_root @website_root ||= Plek.website_root end def find_links_in_edition if has_parts? links_...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/services/update_service.rb
Ruby
mit
48
main
267
class UpdateService def self.call(edition, republish: false) presenter = EditionPresenterFactory.get_presenter(edition) payload = presenter.render_for_publishing_api(republish:) Services.publishing_api.put_content(edition.content_id, payload) end end
github
alphagov/publisher
https://github.com/alphagov/publisher
app/services/link_check_report_updater.rb
Ruby
mit
48
main
1,045
class LinkCheckReportUpdater def initialize(report:, payload:) @report = report @payload = payload end def call update_report! links = payload.fetch("links", []) update_links!(links) end private attr_reader :report, :payload def update_report! report.update!( status: payloa...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/services/unpublish_service.rb
Ruby
mit
48
main
1,955
class UnpublishService class << self def call(artefact, user, redirect_url = "") unpublish_in_publishing_api(artefact, redirect_url) update_artefact_in_shared_db artefact, user, redirect_url rescue StandardError => e Rails.logger.error "Encountered error #{e.message} while trying to unpublis...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/services/publish_service.rb
Ruby
mit
48
main
638
class PublishService GDS_ORGANISATION_ID = "af07d5a5-df63-4ddc-9383-6a666845ebe9".freeze class << self def call(edition, update_type = nil) publish_current_draft(edition, update_type) end private def publish_current_draft(edition, update_type) content_id = edition.artefact.content_id ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/constraints/allowed_content_types_constraint.rb
Ruby
mit
48
main
663
class AllowedContentTypesConstraint def initialize(allowed_content_types) @allowed_content_types = allowed_content_types end def matches?(request) request_path_parameters = "action_dispatch.request.path_parameters" if request.env[request_path_parameters] if request.env[request_path_parameters][...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/constraints/feature_constraint.rb
Ruby
mit
48
main
279
class FeatureConstraint def initialize(feature_name) @feature_name = feature_name end def matches?(request) if request.cookies.key?(@feature_name) request.cookies[@feature_name] == "1" else Flipflop.enabled?(@feature_name.to_sym) end end end
github
alphagov/publisher
https://github.com/alphagov/publisher
app/constraints/new_design_system_constraint.rb
Ruby
mit
48
main
358
class NewDesignSystemConstraint def matches?(request) allowed_content_types = [ AnswerEdition, HelpPageEdition, PlaceEdition, TransactionEdition, CompletedTransactionEdition, LocalTransactionEdition, GuideEdition, ] AllowedContentTypesConstraint.new(allowed_conte...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/filtered_editions_presenter.rb
Ruby
mit
48
main
3,320
# frozen_string_literal: true class FilteredEditionsPresenter include BaseHelper ITEMS_PER_PAGE = 20 attr_reader :search_text def initialize(user, states_filter: [], assigned_to_filter: nil, content_type_filter: nil, search_text: nil, paginate: false, page: nil) @user = user @states_filter = states_...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/organisation_content_presenter.rb
Ruby
mit
48
main
1,370
class OrganisationContentPresenter < CSVPresenter def initialize(scope = Artefact.where(owning_app: "publisher")) super(scope) self.column_headings = %i[ id name format slug state browse_pages organisations ] end private def artefact_contains_no_editions(art...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/primary_listing_presenter.rb
Ruby
mit
48
main
1,418
class PrimaryListingPresenter AVAILABLE_LISTS = %i[ draft amends_needed in_review fact_check fact_check_received ready scheduled_for_publishing published archived ].freeze # There's some discrepancy between the scope names and partial # names so we need a mapping (scope_name...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/editorial_progress_presenter.rb
Ruby
mit
48
main
476
class EditorialProgressPresenter < CSVPresenter include PathsHelper def initialize(scope = Edition.all) super(scope) self.column_headings = %i[ title slug preview_url state format version_number assigned_to sibling_in_progress panopticon_id ] end ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/all_content_workflow_presenter.rb
Ruby
mit
48
main
1,202
class AllContentWorkflowPresenter < CSVPresenter def initialize(scope) super(scope) self.column_headings = %i[ content_title content_created content_slug content_url current_status stage format current_assignee created_at version_number date_cr...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/content_workflow_presenter.rb
Ruby
mit
48
main
784
class ContentWorkflowPresenter < CSVPresenter def initialize(scope = Edition.published) super(scope) self.column_headings = %i[ content_title content_slug content_url current_status stage format current_assignee version_number created_at ] end priva...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/dates_report_presenter.rb
Ruby
mit
48
main
1,401
class DatesReportPresenter < CSVPresenter def initialize(start_date, end_date) start_date = start_date.beginning_of_day end_date = end_date.end_of_day scope = Edition.where(state: "published").or(Edition.where(state: "archived")) scope = scope.where("updated_at >= ?", start_date) scope = scope.whe...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/edition_churn_presenter.rb
Ruby
mit
48
main
433
class EditionChurnPresenter < CSVPresenter def initialize(scope = Edition.all) super(scope) self.column_headings = %i[ id panopticon_id name slug state editioned_on version_number ] end private def get_value(header, edition) case header when :name ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/all_urls_presenter.rb
Ruby
mit
48
main
564
class AllUrlsPresenter < OrganisationContentPresenter def build_csv(csv) csv << column_headings.collect { |ch| ch.to_s.humanize } scope.each do |item| csv << build_row(item) next unless item.latest_edition.respond_to? :parts item.latest_edition.parts.each do |part| csv << build_row...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/csv_presenter.rb
Ruby
mit
48
main
884
require "csv" class CSVPresenter def initialize(scope) self.scope = scope self.column_headings ||= [] end def to_csv CSV.generate do |csv| build_csv(csv) end end def write_csv(path) CSV.open(File.join(path, "#{report_name}.csv"), "wb") do |csv| build_csv(csv) end end ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/all_edition_churn_presenter.rb
Ruby
mit
48
main
596
class AllEditionChurnPresenter < CSVPresenter def initialize(scope = Edition.all) super(scope) self.column_headings = %i[ id panopticon_id name slug state editioned_on version_number date_created time_created ] end private def get_value(header, e...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/formats/completed_transaction_presenter.rb
Ruby
mit
48
main
979
module Formats class CompletedTransactionPresenter < EditionFormatPresenter private PROMOTIONS = %w[organ_donor bring_id_to_vote mot_reminder electric_vehicle].freeze def schema_name "completed_transaction" end def document_type "completed_transaction" end def details o...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/formats/guide_presenter.rb
Ruby
mit
48
main
690
module Formats class GuidePresenter < EditionFormatPresenter private def schema_name "guide" end def document_type "guide" end def rendering_app "frontend" end def details { parts:, external_related_links:, hide_chapter_navigation: edit...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/formats/simple_smart_answer_presenter.rb
Ruby
mit
48
main
1,608
module Formats class SimpleSmartAnswerPresenter < EditionFormatPresenter def schema_name "simple_smart_answer" end def document_type "simple_smart_answer" end def details required_details .merge(optional_details) .merge(external_related_links:) end privat...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/formats/popular_links_presenter.rb
Ruby
mit
48
main
1,347
module Formats class PopularLinksPresenter # Unlike presenters for other models which inherit from editions model, # PopularLinksPresenter does not inherit from EditionFormatPresenter # This is because Edition presenter has dependency on Artefact and # Popular links are not coupled with Artefact unlik...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/formats/transaction_presenter.rb
Ruby
mit
48
main
1,080
module Formats class TransactionPresenter < EditionFormatPresenter private def schema_name "transaction" end def document_type "transaction" end def details { variants: [], introductory_paragraph: govspeak(edition.introduction), start_button_text: edi...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/formats/answer_presenter.rb
Ruby
mit
48
main
432
module Formats class AnswerPresenter < EditionFormatPresenter private def schema_name "answer" end def document_type "answer" end def rendering_app "frontend" end def details { body: [ { content_type: "text/govspeak", ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/formats/edition_format_presenter.rb
Ruby
mit
48
main
2,278
module Formats class EditionFormatPresenter def initialize(edition) @edition = edition @artefact = edition.artefact end def render_for_publishing_api(republish: false) required_fields(republish).merge optional_fields end private attr_reader :edition, :artefact def optio...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/formats/local_transaction_presenter.rb
Ruby
mit
48
main
2,824
module Formats class LocalTransactionPresenter < EditionFormatPresenter private def schema_name "local_transaction" end def document_type "local_transaction" end def details required_details .merge(optional_details) .merge(external_related_links:) end ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/formats/help_page_presenter.rb
Ruby
mit
48
main
440
module Formats class HelpPagePresenter < EditionFormatPresenter private def schema_name "help_page" end def document_type "help_page" end def rendering_app "frontend" end def details { body: [ { content_type: "text/govspeak", ...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/formats/place_presenter.rb
Ruby
mit
48
main
611
module Formats class PlacePresenter < EditionFormatPresenter private def schema_name "place" end def document_type "place" end def details details = { external_related_links: } details[:place_type] = edition.place_type if edition.place_type %i[introduction more...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/presenters/formats/generic_edition_presenter.rb
Ruby
mit
48
main
591
module Formats class GenericEditionPresenter < EditionFormatPresenter def render_for_fact_check_manager_api return unless @edition.respond_to?(:whole_body) { body: @edition.whole_body.presence || "" } end private def schema_name "generic_with_external_related_links" end def...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/workers/update_worker.rb
Ruby
mit
48
main
263
class UpdateWorker include Sidekiq::Worker def perform(edition_id, publish = false) # rubocop:disable Style/OptionalBooleanParameter edition = Edition.find(edition_id) UpdateService.call(edition) PublishService.call(edition) if publish end end
github
alphagov/publisher
https://github.com/alphagov/publisher
app/workers/scheduled_publisher.rb
Ruby
mit
48
main
1,203
require "sidekiq/api" class ScheduledPublisher include Sidekiq::Worker # 5 retries over 10 mins sidekiq_options retry: 5 sidekiq_retry_in do |count| # 16s, 31s, 96s, 271s, 640s count**4 + 15 end def self.enqueue(edition) perform_at(edition.publish_at, edition.id.to_s) end # NOTE: on ids:...
github
alphagov/publisher
https://github.com/alphagov/publisher
app/workers/downtime_remover.rb
Ruby
mit
48
main
365
class DowntimeRemover include Sidekiq::Worker def self.destroy_immediately(downtime) return if downtime.nil? artefact_id = downtime.artefact.id.to_s downtime.destroy! perform_async(artefact_id) end def perform(artefact_id) artefact = Artefact.find_by(id: artefact_id) PublishingApiWork...