Skip to content

Commit

Permalink
Merge pull request #1 from bilbof/sorbet
Browse files Browse the repository at this point in the history
Sorbet
  • Loading branch information
bilbof committed Jun 24, 2019
2 parents d6fcfb9 + cdeaeef commit 923b1f7
Show file tree
Hide file tree
Showing 319 changed files with 88,532 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Expand Up @@ -17,6 +17,10 @@ gem 'sass-rails', '~> 5.0'
gem 'uglifier', '~> 4.1'
gem 'whenever', "~> 1.0.0"

# Type checks with sorbet https://github.com/sorbet/sorbet
gem 'sorbet', :group => :development
gem 'sorbet-runtime'

group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Expand Up @@ -333,6 +333,10 @@ GEM
plek (>= 1.1.0)
rack
rest-client
sorbet (0.4.4259)
sorbet-static (= 0.4.4259)
sorbet-runtime (0.4.4259)
sorbet-static (0.4.4259-universal-darwin-14)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand Down Expand Up @@ -402,6 +406,8 @@ DEPENDENCIES
sdoc
simplecov (~> 0.16.1)
slimmer (~> 13.1.0)
sorbet
sorbet-runtime
timecop
uglifier (~> 4.1)
webmock (~> 3.6.0)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/advanced_search_finder_controller.rb
@@ -1,3 +1,4 @@
# typed: true
class AdvancedSearchFinderController < FindersController
layout "advanced_search_layout"
rescue_from AdvancedSearchFinderApi::TaxonNotFound,
Expand Down
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
@@ -1,3 +1,4 @@
# typed: false
class ApplicationController < ActionController::Base
include Slimmer::Headers
include Slimmer::Template
Expand Down
1 change: 1 addition & 0 deletions app/controllers/concerns/finder_top_result_ab_testable.rb
@@ -1,3 +1,4 @@
# typed: false
module FinderTopResultAbTestable
CUSTOM_DIMENSION = 69

Expand Down
1 change: 1 addition & 0 deletions app/controllers/email_alert_subscriptions_controller.rb
@@ -1,3 +1,4 @@
# typed: true
require 'email_alert_signup_api'
require 'email_alert_title_builder'

Expand Down
1 change: 1 addition & 0 deletions app/controllers/finders_controller.rb
@@ -1,3 +1,4 @@
# typed: false
class FindersController < ApplicationController
include FinderTopResultAbTestable

Expand Down
1 change: 1 addition & 0 deletions app/controllers/qa_controller.rb
@@ -1,3 +1,4 @@
# typed: false
class QaController < ApplicationController
layout "finder_layout"

Expand Down
1 change: 1 addition & 0 deletions app/controllers/qa_to_content_controller.rb
@@ -1,3 +1,4 @@
# typed: true
# This class currently supports only one question
# If there is a need for multiple questions, this class needs to be modified

Expand Down
1 change: 1 addition & 0 deletions app/controllers/redirection_controller.rb
@@ -1,3 +1,4 @@
# typed: false
require 'publications_routes'

class RedirectionController < ApplicationController
Expand Down
1 change: 1 addition & 0 deletions app/controllers/search_controller.rb
@@ -1,3 +1,4 @@
# typed: false
class SearchController < ApplicationController
layout "search_layout"
before_action :set_expiry
Expand Down
1 change: 1 addition & 0 deletions app/helpers/application_helper.rb
@@ -1,3 +1,4 @@
# typed: false
module ApplicationHelper
def input_checked(key, value)
if facet_has_any_selected_values?(key)
Expand Down
1 change: 1 addition & 0 deletions app/helpers/eu_exit_finder_helper.rb
@@ -1,3 +1,4 @@
# typed: true
module EuExitFinderHelper
def self.eu_exit_finder?(content_id)
content_id == "42ce66de-04f3-4192-bf31-8394538e0734"
Expand Down
1 change: 1 addition & 0 deletions app/lib/advanced_search_finder_api.rb
@@ -1,3 +1,4 @@
# typed: true
class AdvancedSearchFinderApi < FinderApi
include AdvancedSearchParams

Expand Down
1 change: 1 addition & 0 deletions app/lib/advanced_search_order_query_builder.rb
@@ -1,3 +1,4 @@
# typed: true
class AdvancedSearchOrderQueryBuilder < OrderQueryBuilder
include AdvancedSearchParams

Expand Down
1 change: 1 addition & 0 deletions app/lib/advanced_search_params.rb
@@ -1,3 +1,4 @@
# typed: true
module AdvancedSearchParams
GROUP_SEARCH_FILTER = "group".freeze
SUBGROUP_SEARCH_FILTER = "subgroup".freeze
Expand Down
1 change: 1 addition & 0 deletions app/lib/advanced_search_query_builder.rb
@@ -1,3 +1,4 @@
# typed: true
class AdvancedSearchQueryBuilder < SearchQueryBuilder
include AdvancedSearchParams
def base_return_fields
Expand Down
1 change: 1 addition & 0 deletions app/lib/email_alert_list_title_builder.rb
@@ -1,3 +1,4 @@
# typed: false
class EmailAlertListTitleBuilder
def self.call(*args)
new(*args).call
Expand Down
1 change: 1 addition & 0 deletions app/lib/facet_extractor.rb
@@ -1,3 +1,4 @@
# typed: true
class FacetExtractor
attr_reader :content_item

Expand Down
1 change: 1 addition & 0 deletions app/lib/facet_query_builder.rb
@@ -1,3 +1,4 @@
# typed: true
# Used by the SearchQueryBuilder to build the `facet` part of the Rummager
# search query. This will determine the "facets" Rummager returns.
#
Expand Down
1 change: 1 addition & 0 deletions app/lib/facets_from_facet_group_extractor.rb
@@ -1,3 +1,4 @@
# typed: true
class FacetsFromFacetGroupExtractor
def initialize(facet_group)
@facets = facet_group.dig('links', 'facets') || []
Expand Down
1 change: 1 addition & 0 deletions app/lib/filter_query_builder.rb
@@ -1,3 +1,4 @@
# typed: true
# Used by the SearchQueryBuilder to build the `filter` part of the Rummager
# search query. This will determine the documents that are returned from rummager.
class FilterQueryBuilder
Expand Down
1 change: 1 addition & 0 deletions app/lib/filters/checkbox_filter.rb
@@ -1,3 +1,4 @@
# typed: true
module Filters
class CheckboxFilter < Filter
private # rubocop:disable Layout/IndentationWidth
Expand Down
1 change: 1 addition & 0 deletions app/lib/filters/content_id_filter.rb
@@ -1,3 +1,4 @@
# typed: true
module Filters
class ContentIdFilter < Filter
private # rubocop:disable Layout/IndentationWidth
Expand Down
1 change: 1 addition & 0 deletions app/lib/filters/date_filter.rb
@@ -1,3 +1,4 @@
# typed: true
module Filters
class DateFilter < Filter
private # rubocop:disable Layout/IndentationWidth
Expand Down
1 change: 1 addition & 0 deletions app/lib/filters/dropdown_select_filter.rb
@@ -1,3 +1,4 @@
# typed: true
module Filters
class DropdownSelectFilter < Filter
private # rubocop:disable Layout/IndentationWidth
Expand Down
1 change: 1 addition & 0 deletions app/lib/filters/filter.rb
@@ -1,3 +1,4 @@
# typed: true
module Filters
class Filter
def initialize(facet, params)
Expand Down
1 change: 1 addition & 0 deletions app/lib/filters/hidden_clearable_filter.rb
@@ -1,3 +1,4 @@
# typed: true
module Filters
class HiddenClearableFilter < Filter
private # rubocop:disable Layout/IndentationWidth
Expand Down
1 change: 1 addition & 0 deletions app/lib/filters/hidden_filter.rb
@@ -1,3 +1,4 @@
# typed: true
module Filters
class HiddenFilter < Filter
private # rubocop:disable Layout/IndentationWidth
Expand Down
1 change: 1 addition & 0 deletions app/lib/filters/official_documents_filter.rb
@@ -1,3 +1,4 @@
# typed: true
module Filters
class OfficialDocumentsFilter < RadioFilterForMultipleFields
def filter_hashes
Expand Down
1 change: 1 addition & 0 deletions app/lib/filters/radio_filter.rb
@@ -1,3 +1,4 @@
# typed: true
module Filters
class RadioFilter < Filter
private # rubocop:disable Layout/IndentationWidth
Expand Down
1 change: 1 addition & 0 deletions app/lib/filters/radio_filter_for_multiple_fields.rb
@@ -1,3 +1,4 @@
# typed: true
module Filters
class RadioFilterForMultipleFields < Filter
def query_hash
Expand Down
1 change: 1 addition & 0 deletions app/lib/filters/research_and_statistics_filter.rb
@@ -1,3 +1,4 @@
# typed: true
module Filters
class ResearchAndStatisticsFilter < RadioFilterForMultipleFields
def filter_hashes
Expand Down
1 change: 1 addition & 0 deletions app/lib/filters/taxon_filter.rb
@@ -1,3 +1,4 @@
# typed: true
module Filters
class TaxonFilter < Filter
private # rubocop:disable Layout/IndentationWidth
Expand Down
1 change: 1 addition & 0 deletions app/lib/filters/text_filter.rb
@@ -1,3 +1,4 @@
# typed: true
module Filters
class TextFilter < Filter
private # rubocop:disable Layout/IndentationWidth
Expand Down
1 change: 1 addition & 0 deletions app/lib/filters/topical_filter.rb
@@ -1,3 +1,4 @@
# typed: true
module Filters
class TopicalFilter < Filter
private # rubocop:disable Layout/IndentationWidth
Expand Down
1 change: 1 addition & 0 deletions app/lib/finder_api.rb
@@ -1,3 +1,4 @@
# typed: true
# Facade that speaks to rummager. Combines a content item with
# search results from rummager.
class FinderApi
Expand Down
1 change: 1 addition & 0 deletions app/lib/healthchecks/registries_cache.rb
@@ -1,3 +1,4 @@
# typed: true
module Healthchecks
class RegistriesCache
def name
Expand Down
1 change: 1 addition & 0 deletions app/lib/order_query_builder.rb
@@ -1,3 +1,4 @@
# typed: true
class OrderQueryBuilder
def initialize(content_item, keywords, params, override_sort_for_feed: false)
@content_item = content_item
Expand Down
1 change: 1 addition & 0 deletions app/lib/params_cleaner.rb
@@ -1,3 +1,4 @@
# typed: true
# In some cases requests come in to this app with a mangled query string in
# this form:
#
Expand Down
1 change: 1 addition & 0 deletions app/lib/publications_routes.rb
@@ -1,3 +1,4 @@
# typed: true
module PublicationsRoutes
PUBLICATIONS_ROUTES = {
'consultations' => {
Expand Down
1 change: 1 addition & 0 deletions app/lib/registries/base_registries.rb
@@ -1,3 +1,4 @@
# typed: true
module Registries
NAMESPACE = 'registries'.freeze

Expand Down
10 changes: 10 additions & 0 deletions app/lib/registries/cacheable_registry.rb
@@ -1,16 +1,23 @@
# typed: strict
module Registries
module CacheableRegistry
extend T::Sig
include Kernel

sig {returns(TrueClass)}
def can_refresh_cache?
true
end

sig {returns(T::Boolean)}
def refresh_cache
Rails.cache.write(cache_key, cacheable_data)
rescue GdsApi::HTTPServerError, GdsApi::HTTPBadGateway
report_error
false
end

sig {returns(T::Hash)}
def fetch_from_cache
Rails.cache.fetch(cache_key) do
cacheable_data
Expand All @@ -20,14 +27,17 @@ def fetch_from_cache
{}
end

sig {void}
def cacheable_data
raise NotImplementedError, "Please supply a cacheable_data method"
end

sig {void}
def cache_key
raise NotImplementedError, "Please supply a cache_key method"
end

sig {void}
def report_error
raise NotImplementedError, "Please supply a report_error method"
end
Expand Down
1 change: 1 addition & 0 deletions app/lib/registries/full_topic_taxonomy_registry.rb
@@ -1,3 +1,4 @@
# typed: true
module Registries
class FullTopicTaxonomyRegistry < Registry
include CacheableRegistry
Expand Down
1 change: 1 addition & 0 deletions app/lib/registries/manuals_registry.rb
@@ -1,3 +1,4 @@
# typed: true
module Registries
class ManualsRegistry < Registry
include CacheableRegistry
Expand Down
1 change: 1 addition & 0 deletions app/lib/registries/organisations_registry.rb
@@ -1,3 +1,4 @@
# typed: true
module Registries
class OrganisationsRegistry < Registry
include CacheableRegistry
Expand Down
1 change: 1 addition & 0 deletions app/lib/registries/people_registry.rb
@@ -1,3 +1,4 @@
# typed: true
module Registries
class PeopleRegistry < Registry
include CacheableRegistry
Expand Down
1 change: 1 addition & 0 deletions app/lib/registries/registry.rb
@@ -1,3 +1,4 @@
# typed: true
module Registries
class Registry
def can_refresh_cache?
Expand Down
1 change: 1 addition & 0 deletions app/lib/registries/topic_taxonomy_registry.rb
@@ -1,3 +1,4 @@
# typed: true
module Registries
class TopicTaxonomyRegistry < Registry
include CacheableRegistry
Expand Down
1 change: 1 addition & 0 deletions app/lib/registries/world_locations_registry.rb
@@ -1,3 +1,4 @@
# typed: true
module Registries
class WorldLocationsRegistry < Registry
include CacheableRegistry
Expand Down
1 change: 1 addition & 0 deletions app/lib/search_query_builder.rb
@@ -1,3 +1,4 @@
# typed: true
# SearchQueryBuilder takes the content item for the finder and the query params
# from the URL to generate a query for Rummager.
class SearchQueryBuilder
Expand Down
1 change: 1 addition & 0 deletions app/lib/services.rb
@@ -1,3 +1,4 @@
# typed: true
require 'gds_api/content_store'
require 'gds_api/rummager'
require 'gds_api/email_alert_api'
Expand Down
1 change: 1 addition & 0 deletions app/lib/supergroups.rb
@@ -1,3 +1,4 @@
# typed: true
class Supergroups
def self.lookup(keys)
raise_not_found(nil) unless keys
Expand Down
1 change: 1 addition & 0 deletions app/lib/url_builder.rb
@@ -1,3 +1,4 @@
# typed: true
# The UrlBuilder class is responsible for creating URLs to be rendered as
# HTML links.
class UrlBuilder
Expand Down
1 change: 1 addition & 0 deletions app/models/checkbox_facet.rb
@@ -1,3 +1,4 @@
# typed: true
class CheckboxFacet < FilterableFacet
def initialize(facet, checked)
@checked = checked
Expand Down
1 change: 1 addition & 0 deletions app/models/content_item.rb
@@ -1,3 +1,4 @@
# typed: true
class ContentItem
def initialize(request_path)
@request_path = request_path
Expand Down
1 change: 1 addition & 0 deletions app/models/date_facet.rb
@@ -1,3 +1,4 @@
# typed: true
class DateFacet < FilterableFacet
attr_reader :value

Expand Down
1 change: 1 addition & 0 deletions app/models/document.rb
@@ -1,3 +1,4 @@
# typed: false
class Document
attr_reader :title, :public_timestamp, :is_historic, :government_name,
:content_purpose_supergroup, :document_type, :organisations,
Expand Down
1 change: 1 addition & 0 deletions app/models/facet.rb
@@ -1,3 +1,4 @@
# typed: true
class Facet
def initialize(facet)
@facet = facet
Expand Down
1 change: 1 addition & 0 deletions app/models/facet_collection.rb
@@ -1,3 +1,4 @@
# typed: true
class FacetCollection
include Enumerable

Expand Down
1 change: 1 addition & 0 deletions app/models/filterable_facet.rb
@@ -1,3 +1,4 @@
# typed: false
class FilterableFacet < Facet
DEFAULT_PREPOSITION = 'related to'.freeze

Expand Down
1 change: 1 addition & 0 deletions app/models/filters.rb
@@ -1,3 +1,4 @@
# typed: true
module Filters
class ResearchAndStatsHashes
def call
Expand Down
1 change: 1 addition & 0 deletions app/models/hidden_clearable_facet.rb
@@ -1,3 +1,4 @@
# typed: true
class HiddenClearableFacet < FilterableFacet
def initialize(facet, value_hash)
@value = Array(value_hash)
Expand Down
1 change: 1 addition & 0 deletions app/models/hidden_facet.rb
@@ -1,3 +1,4 @@
# typed: true
class HiddenFacet < FilterableFacet
def initialize(facet, value)
@value = Array(value)
Expand Down
1 change: 1 addition & 0 deletions app/models/keyword_facet.rb
@@ -1,3 +1,4 @@
# typed: true
class KeywordFacet
def initialize(keywords = "")
@keywords = keywords
Expand Down
1 change: 1 addition & 0 deletions app/models/option_select_facet.rb
@@ -1,3 +1,4 @@
# typed: true
class OptionSelectFacet < FilterableFacet
attr_reader :value

Expand Down
1 change: 1 addition & 0 deletions app/models/radio_facet.rb
@@ -1,3 +1,4 @@
# typed: true
class RadioFacet < FilterableFacet
def initialize(facet, value)
@value = value
Expand Down
1 change: 1 addition & 0 deletions app/models/radio_facet_for_multiple_filters.rb
@@ -1,3 +1,4 @@
# typed: true
class RadioFacetForMultipleFilters < FilterableFacet
def initialize(facet, value, filter_hashes)
@filter_hashes = filter_hashes
Expand Down

0 comments on commit 923b1f7

Please sign in to comment.