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 | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/query/filter/boolean_filter.rb | Ruby | mit | 84 | main | 243 | # frozen_string_literal: true
class Query::Filter
class BooleanFilter < Query::Filter
attr_accessor :on_vals, :prefs_vals, :off_val
def type
:boolean
end
def on?(val)
val.to_s != off_val.to_s
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/query/params/filters.rb | Ruby | mit | 84 | main | 493 | # frozen_string_literal: true
module Query::Params::Filters
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
# Get all param keys with `Query::Filter.all.map(&:sym)`.
# Current params [:has_images, :has_specimens, :lichen, :region, :clade]
def content_filter_parameter_de... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/query/params/advanced_search.rb | Ruby | mit | 84 | main | 985 | # frozen_string_literal: true
# Advanced search is really something like this:
# "Observation Search, or Locations or Names of Observations Search"
# It returns results by joining to observations and filtering the observations.
module Query::Params::AdvancedSearch
def self.included(base)
base.extend(ClassMethods... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/autocomplete/for_location_containing.rb | Ruby | mit | 84 | main | 1,631 | # frozen_string_literal: true
# Autocompleter for location names that encompass a given lat/lng.
class Autocomplete::ForLocationContaining < Autocomplete::ByWord
attr_accessor :reverse, :lat, :lng
# include Mappable::BoxMethods
def initialize(params)
super
self.reverse = (params[:format] == "scientific... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/autocomplete/for_name.rb | Ruby | mit | 84 | main | 1,845 | # frozen_string_literal: true
class Autocomplete::ForName < Autocomplete::ByString
# Minimum characters before switching from beginning-match to word-match
WORD_MATCH_THRESHOLD = 4
def rough_matches(letter)
names = Name.with_correct_spelling.
select(:text_name, :id, :deprecated).distinct.
... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/autocomplete/for_species_list.rb | Ruby | mit | 84 | main | 813 | # frozen_string_literal: true
class Autocomplete::ForSpeciesList < Autocomplete::ByWord
def rough_matches(letter)
lists = SpeciesList.select(:title, :id).distinct.
where(SpeciesList[:title].matches("#{letter}%").
or(SpeciesList[:title].matches("% #{letter}%"))).
order(title:... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/autocomplete/for_project.rb | Ruby | mit | 84 | main | 791 | # frozen_string_literal: true
class Autocomplete::ForProject < Autocomplete::ByWord
def rough_matches(letter)
projects = Project.select(:title, :id).distinct.
where(Project[:title].matches("#{letter}%").
or(Project[:title].matches("% #{letter}%"))).
order(title: :as... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/autocomplete/by_word.rb | Ruby | mit | 84 | main | 992 | # frozen_string_literal: true
class Autocomplete::ByWord < Autocomplete
# Same as AutocompleteByString#refine_token, except words are allowed
# to be out of order.
def refine_token
# Get rid of trivial case immediately.
return string[0] if matches&.length&.<= limit
# Apply words in order, requiring ... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/autocomplete/for_location.rb | Ruby | mit | 84 | main | 1,581 | # frozen_string_literal: true
# Nimmo note: Is it desirable to make `rough_matches` a scope for these models?
# Doing that, plus a method to pluck the values, would solve the ABC violation.
# Any caching advantage in that? Then below, it'd be something like:
# Observation.rough_matches(letter).pluck_matches
# Or wou... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/autocomplete/for_user.rb | Ruby | mit | 84 | main | 1,473 | # frozen_string_literal: true
class Autocomplete::ForUser < Autocomplete::ByString
def rough_matches(letter)
users = User.verified.select(:login, :name, :id).distinct.
where(User[:login].matches("#{letter}%").
or(User[:name].matches("#{letter}%")).
or(User[:name].matches("... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/autocomplete/by_string.rb | Ruby | mit | 84 | main | 1,042 | # frozen_string_literal: true
class Autocomplete::ByString < Autocomplete
# Find minimal string whose matches are within the limit. This is designed
# to reduce the number of AJAX requests required if the user backspaces from
# the end of the text field string.
#
# The initial query has already matched ever... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/autocomplete/for_clade.rb | Ruby | mit | 84 | main | 1,040 | # frozen_string_literal: true
class Autocomplete::ForClade < Autocomplete::ByString
def rough_matches(letter)
# (this sort puts higher rank on top)
clades = Name.with_correct_spelling.with_rank_above_genus.
where(Name[:text_name].matches("#{letter}%")).order(rank: :desc).
select(:te... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/autocomplete/for_region.rb | Ruby | mit | 84 | main | 2,253 | # frozen_string_literal: true
# Region autocompleter - queries Location records filtered to "region-sized"
# places (1-4 comma-separated parts = country through sub-county level).
#
# Uses the same word-beginning matching as ForLocation for good typeahead UX,
# but filters to locations with 0-3 commas (1-4 parts like
... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/autocomplete/for_herbarium.rb | Ruby | mit | 84 | main | 1,363 | # frozen_string_literal: true
# Note this gets a params[:user_id] but we're ignoring it here
class Autocomplete::ForHerbarium < Autocomplete::ByWord
def rough_matches(letter)
herbaria =
Herbarium.select(:code, :name, :id).distinct.
where(Herbarium[:name].matches("#{letter}%").
or(Herbarium[:n... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/prawn/field_slip_card.rb | Ruby | mit | 84 | main | 6,930 | # frozen_string_literal: true
module Prawn
module FieldSlipCard
# Slip constants
FONT_SIZE = 9
# Rulers
RULER_WIDTH = 9.5.cm
RULER_HEIGHT = 7.5.cm
X_MIN = 0
X_MAX = X_MIN + RULER_WIDTH
Y_MAX = 244
Y_MIN = Y_MAX - RULER_HEIGHT
RULER_SIZE = 0.5.cm
RULER_LEFT = X_MIN + RULER... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/observation_labels/label.rb | Ruby | mit | 84 | main | 3,686 | # frozen_string_literal: true
# Represents a single 5"x3" label for one mushroom observation
class ObservationLabels::Label
LABEL_WIDTH = 5.in
LABEL_HEIGHT = 3.in
X_MARGIN = 0.25.in
Y_MARGIN = 0.5.in
QR_CODE_SIZE = 0.75.in
attr_reader :observation, :font_family, :pdf
def initialize(observation, font_fa... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/observation_labels/pdf_labels.rb | Ruby | mit | 84 | main | 3,357 | # frozen_string_literal: true
require "prawn"
require "prawn/measurement_extensions"
# Main document class for generating PDF labels
class ObservationLabels::PdfLabels
attr_reader :query, :page_width, :page_height
def initialize(query)
@query = query
if query.results.one?
@page_width = 5.in
@... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/observation_labels/name_field.rb | Ruby | mit | 84 | main | 7,931 | # frozen_string_literal: true
# Represents a taxonomic name field with proper formatting for
# scientific names Handles Textile markup (**bold** and __italic__)
# and renders with appropriate font styling
class ObservationLabels::NameField
attr_reader :name, :value, :tokens
def initialize(name, textile_value)
... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/observation_labels/fields.rb | Ruby | mit | 84 | main | 5,107 | # frozen_string_literal: true
# Handles the creation of label fields from an observation
class ObservationLabels::Fields
attr_reader :observation
def initialize(observation)
@observation = observation
end
# Returns an array of LabelField objects for the observation
def label_fields
field_list = [
... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/observation_labels/qr_code_field.rb | Ruby | mit | 84 | main | 2,918 | # frozen_string_literal: true
require "prawn"
require "prawn/measurement_extensions"
require "rqrcode"
# Represents a QR code field with a label
class ObservationLabels::QRCodeField
attr_reader :label, :url
def initialize(label, url)
@label = label
@url = url
end
# Renders the QR code with label und... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/observation_labels/rtf_labels.rb | Ruby | mit | 84 | main | 5,249 | # frozen_string_literal: true
require("rtf")
# Format observations as fancy labels in RTF format.
class ObservationLabels::RtfLabels
PARAGRAPH_PREFIX = "\\pard\\plain \\s0\\dbch\\af8\\langfe1081\\dbch\\af8" \
"\\afs24\\alang1081\\ql\\keep\\nowidctlpar\\sb0\\sa720" \
"\\ltrp... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/observation_labels/text_field.rb | Ruby | mit | 84 | main | 3,004 | # frozen_string_literal: true
# Represents a single field on a mushroom observation label
class ObservationLabels::TextField
attr_reader :pdf, :name, :value
def initialize(name, value)
@name = name
@value = value
end
# Renders the field as a formatted line on the PDF
def render(pdf, _options = {})
... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/occurrence_api.rb | Ruby | mit | 84 | main | 3,980 | # frozen_string_literal: true
class API2
# API for Occurrence
class OccurrenceAPI < ModelAPI
def model
Occurrence
end
def high_detail_includes
[
{ observations: [:name, :location, :user, :thumb_image] },
:field_slip,
:user
]
end
def query_params
... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/species_list_api.rb | Ruby | mit | 84 | main | 3,542 | # frozen_string_literal: true
class API2
# API for SpeciesList
class SpeciesListAPI < ModelAPI
def model
SpeciesList
end
def high_detail_includes
[
{ comments: :user },
:location,
:user
]
end
def query_params
{
id_in_set: parse_array(:sp... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/location_api.rb | Ruby | mit | 84 | main | 4,432 | # frozen_string_literal: true
class API2
# API for Location
class LocationAPI < ModelAPI
def model
Location
end
def high_detail_includes
[
{ comments: :user }
]
end
def query_params
box = parse_bounding_box!
{
id_in_set: parse_array(:location, :id... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/herbarium_record_api.rb | Ruby | mit | 84 | main | 5,053 | # frozen_string_literal: true
class API2
# API for HerbariumRecord
class HerbariumRecordAPI < ModelAPI
def model
HerbariumRecord
end
def high_detail_includes
[
:observations,
:herbarium,
:user
]
end
def query_params
{
id_in_set: parse_ar... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/project_api.rb | Ruby | mit | 84 | main | 5,667 | # frozen_string_literal: true
class API2
# API for Project
class ProjectAPI < ModelAPI
def model
Project
end
def high_detail_includes
[
{ comments: :user },
:user
]
end
def query_params
{
id_in_set: parse_array(:project, :id, as: :id),
c... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/image_api.rb | Ruby | mit | 84 | main | 4,799 | # frozen_string_literal: true
class API2
# API for Image
class ImageAPI < ModelAPI
def model
Image
end
def low_detail_includes
[:license]
end
def high_detail_includes
[
:license,
:observations,
:user
]
end
# Disable cop to keep table st... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/external_site_api.rb | Ruby | mit | 84 | main | 662 | # frozen_string_literal: true
class API2
# API for ExternalSite
class ExternalSiteAPI < ModelAPI
def model
ExternalSite
end
def page_length_level
:lightweight
end
def high_detail_includes
[:project]
end
def query_params
{
id_in_set: parse_array(:extern... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/collection_number_api.rb | Ruby | mit | 84 | main | 3,675 | # frozen_string_literal: true
class API2
# API for CollectionNumber
class CollectionNumberAPI < ModelAPI
def model
CollectionNumber
end
def high_detail_includes
[
:observations,
:user
]
end
def query_params
{
id_in_set: parse_array(:collection_n... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/location_description_api.rb | Ruby | mit | 84 | main | 918 | # frozen_string_literal: true
class API2
# API for Location Description
class LocationDescriptionAPI < ModelAPI
def model
LocationDescription
end
def page_length_level
:heavyweight
end
def low_detail_includes
[:license]
end
def high_detail_includes
[]
end
... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/comment_api.rb | Ruby | mit | 84 | main | 1,637 | # frozen_string_literal: true
class API2
# API for Comment
class CommentAPI < ModelAPI
def model
Comment
end
def page_length_level
:lightweight
end
def high_detail_includes
[:user]
end
def query_params
@target = parse(:object, :target, limit: Comment::ALL_TYPE... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/observation_api.rb | Ruby | mit | 84 | main | 14,199 | # frozen_string_literal: true
class API2
# API for Observation
# rubocop:disable Metrics/ClassLength
class ObservationAPI < ModelAPI
def model
Observation
end
def high_detail_includes
[
:collection_numbers,
{ comments: :user },
:external_links,
{ occurrenc... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/parameter_declaration.rb | Ruby | mit | 84 | main | 1,719 | # frozen_string_literal: true
class API2
# Information about an API parameter to provide automatic documentation
class ParameterDeclaration
attr_accessor :key, :type, :args, :set_parameter, :deprecated
def initialize(key, type, args = {})
self.key = key
self.type = type
self.args = args... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/external_link_api.rb | Ruby | mit | 84 | main | 1,463 | # frozen_string_literal: true
class API2
# API for ExternalLink
class ExternalLinkAPI < ModelAPI
def model
ExternalLink
end
def high_detail_includes
[
:external_site,
:user
]
end
def query_params
{
id_in_set: parse_array(:external_link, :id, as:... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/name_description_api.rb | Ruby | mit | 84 | main | 878 | # frozen_string_literal: true
class API2
# API for Name Description
class NameDescriptionAPI < ModelAPI
def model
NameDescription
end
def page_length_level
:heavyweight
end
def low_detail_includes
[:license]
end
def high_detail_includes
[]
end
def que... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/herbarium_api.rb | Ruby | mit | 84 | main | 917 | # frozen_string_literal: true
class API2
# API for Herbarium
class HerbariumAPI < ModelAPI
def model
Herbarium
end
def high_detail_includes
[
:location,
:personal_user
]
end
def query_params
{
id_in_set: parse_array(:herbarium, :id, as: :id),
... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/field_slip_api.rb | Ruby | mit | 84 | main | 3,110 | # frozen_string_literal: true
class API2
# API for FieldSlip
class FieldSlipAPI < ModelAPI
def model
FieldSlip
end
def high_detail_includes
[
{ occurrence: :observations },
:project,
:user
]
end
def query_params
{
id_in_set: parse_array(... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/name_api.rb | Ruby | mit | 84 | main | 9,619 | # frozen_string_literal: true
class API2
# API for Name
class NameAPI < ModelAPI
def model
Name
end
def high_detail_includes
[
{ comments: :user },
{ synonym: :names }
]
end
def query_params
{
id_in_set: parse_array(:name, :id, as: :id),
... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/model_api.rb | Ruby | mit | 84 | main | 3,811 | # frozen_string_literal: true
class API2
# API subclass for all model-based endpoints
class ModelAPI < API2
def model_tag
self.class.model.type_tag
end
def get
self.query = build_query
done_parsing_parameters!
end
def post
must_authenticate!
object = build_object... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/user_api.rb | Ruby | mit | 84 | main | 2,978 | # frozen_string_literal: true
class API2
# API for User
class UserAPI < ModelAPI
def model
User
end
def high_detail_includes
[
:api_keys,
:location,
{ image: [:license, :user] }
]
end
def query_params
{
id_in_set: parse_array(:user, :id,... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/sequence_api.rb | Ruby | mit | 84 | main | 3,009 | # frozen_string_literal: true
class API2
# API for Sequence
class SequenceAPI < ModelAPI
def model
Sequence
end
def high_detail_includes
[:user]
end
def query_params
{
id_in_set: parse_array(:sequence, :id, as: :id),
created_at: parse_range(:time, :created_at... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/ordered_range.rb | Ruby | mit | 84 | main | 634 | # frozen_string_literal: true
class API2
# Encapsulates a range of values of any types of objects that can be compared
class OrderedRange < Range
attr_accessor :begin, :end
def initialize(from, to)
super
@begin = from
@end = to
end
def reverse!
@begin, @end = @end, @begin
... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/api_key_api.rb | Ruby | mit | 84 | main | 2,093 | # frozen_string_literal: true
class API2
# API for APIKey
class APIKeyAPI < ModelAPI
def model
APIKey
end
def page_length_level
:lightweight
end
# the :user may be the mobile app. the :for_user is the user the key is for
def create_params
@for_user = parse(:user, :for_us... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/image_upload_failed.rb | Ruby | mit | 84 | main | 206 | # frozen_string_literal: true
class API2
# Upload didn't make it.
class ImageUploadFailed < FatalError
def initialize(img)
super()
args.merge!(error: img.dump_errors)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/user_already_exists.rb | Ruby | mit | 84 | main | 213 | # frozen_string_literal: true
class API2
# Tried to create user that already exists.
class UserAlreadyExists < FatalError
def initialize(str)
super()
args.merge!(login: str)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/bad_version.rb | Ruby | mit | 84 | main | 209 | # frozen_string_literal: true
class API2
# Syntax of requested version is wrong.
class BadVersion < FatalError
def initialize(str)
super()
args.merge!(version: str.to_s)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/object_error.rb | Ruby | mit | 84 | main | 594 | # frozen_string_literal: true
class API2
# API exception base class for errors having to do with database records.
class ObjectError < FatalError
def initialize(obj)
super()
args.merge!(type: obj.type_tag, name: display_name(obj))
end
def display_name(obj)
if obj.respond_to?(:unique_... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/bad_parameter_value.rb | Ruby | mit | 84 | main | 270 | # frozen_string_literal: true
class API2
# Parameter has bad syntax.
class BadParameterValue < FatalError
def initialize(str, type)
super()
args.merge!(val: str.to_s, type: type)
self.tag = :"api_bad_#{type}_parameter_value"
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/must_be_admin.rb | Ruby | mit | 84 | main | 217 | # frozen_string_literal: true
class API2
# Request requires you to be project admin.
class MustBeAdmin < FatalError
def initialize(proj)
super()
args.merge!(project: proj.title)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/missing_parameter.rb | Ruby | mit | 84 | main | 201 | # frozen_string_literal: true
class API2
# Missing required parameter.
class MissingParameter < FatalError
def initialize(arg)
super()
args.merge!(arg: arg.to_s)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/can_only_use_one_of_these_fields.rb | Ruby | mit | 84 | main | 272 | # frozen_string_literal: true
class API2
# Can't set both specimen_id and herbarium_label, choose one or the other.
class CanOnlyUseOneOfTheseFields < FatalError
def initialize(*fields)
super()
args.merge!(fields: fields.join(", "))
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/parameter_cant_be_blank.rb | Ruby | mit | 84 | main | 234 | # frozen_string_literal: true
class API2
# Some PATCH set parameters, if supplied, cannot be blank.
class ParameterCantBeBlank < FatalError
def initialize(arg)
super()
args.merge!(arg: arg.to_s)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/one_or_the_other.rb | Ruby | mit | 84 | main | 247 | # frozen_string_literal: true
class API2
# Tried to both clear synonyms and add synonyms at the same time.
class OneOrTheOther < FatalError
def initialize(fields)
super()
args.merge!(args: fields.join(", "))
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/cant_add_herbarium_record.rb | Ruby | mit | 84 | main | 213 | # frozen_string_literal: true
class API2
# Tried to add herbarium record to observation that you don't own, and you
# are not a curator of the herbarium.
class CantAddHerbariumRecord < FatalError
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/dubious_location_name.rb | Ruby | mit | 84 | main | 238 | # frozen_string_literal: true
class API2
# Location name is "dubious".
class DubiousLocationName < FatalError
def initialize(reasons)
super()
args.merge!(reasons: reasons.join("; ").gsub(".;", ";"))
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/bad_method.rb | Ruby | mit | 84 | main | 206 | # frozen_string_literal: true
class API2
# Request method not recognized.
class BadMethod < FatalError
def initialize(method)
super()
args.merge!(method: method.to_s)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/object_not_found_by_string.rb | Ruby | mit | 84 | main | 246 | # frozen_string_literal: true
class API2
# Referenced object name doesn't exist.
class ObjectNotFoundByString < FatalError
def initialize(str, model)
super()
args.merge!(str: str.to_s, type: model.type_tag)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/file_missing.rb | Ruby | mit | 84 | main | 232 | # frozen_string_literal: true
class API2
# Upload was supposed to be a local file, but it doesn't exist.
class FileMissing < FatalError
def initialize(file)
super()
args.merge(file: file.to_s)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/user_group_taken.rb | Ruby | mit | 84 | main | 227 | # frozen_string_literal: true
class API2
# Tried to create a user group that already exists.
class UserGroupTaken < FatalError
def initialize(title)
super()
args.merge!(title: title.to_s)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/help_message.rb | Ruby | mit | 84 | main | 941 | # frozen_string_literal: true
class API2
# API auto-discover help message.
class HelpMessage < Error
attr_accessor :params
def initialize(params)
super()
self.params = params
args.merge!(help: help_message)
end
def help_message
if keys_for_patch.any?
"query params:... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/ambiguous_name.rb | Ruby | mit | 84 | main | 286 | # frozen_string_literal: true
class API2
# Name parameter has multiple matches.
class AmbiguousName < FatalError
def initialize(name, others)
super()
str = others.map(&:real_search_name).join(" / ")
args.merge!(name: name.to_s, others: str)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/can_only_synonymize_unsynonymized_names.rb | Ruby | mit | 84 | main | 329 | # frozen_string_literal: true
class API2
# We're not allowing client to merge to sets of synonyms. Even more, we're
# only allowing them to synonymize unsynonmized names with other names.
# (The name they synonymize it with, however, can have synonyms.)
class CanOnlySynonymizeUnsynonymizedNames < FatalError
... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/must_own_all_species_lists.rb | Ruby | mit | 84 | main | 238 | # frozen_string_literal: true
class API2
# Cannot update location unless you own all its species_lists.
class MustOwnAllSpeciesLists < FatalError
def initialize(type)
super()
args.merge!(type: type)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/unused_parameters.rb | Ruby | mit | 84 | main | 240 | # frozen_string_literal: true
class API2
# Request included unexpected parameters.
class UnusedParameters < Error
def initialize(params)
super()
args.merge!(params: params.map(&:to_s).sort.join(", "))
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/bad_notes_field_parameter.rb | Ruby | mit | 84 | main | 214 | # frozen_string_literal: true
class API2
# Notes template field didn't parse.
class BadNotesFieldParameter < FatalError
def initialize(str)
super()
args.merge!(val: str.to_s)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/bad_limited_parameter_value.rb | Ruby | mit | 84 | main | 240 | # frozen_string_literal: true
class API2
# Parameter value out of range.
class BadLimitedParameterValue < FatalError
def initialize(str, limit)
super()
args.merge!(val: str.to_s, limit: limit.inspect)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/string_too_long.rb | Ruby | mit | 84 | main | 228 | # frozen_string_literal: true
class API2
# String parameter too long.
class StringTooLong < FatalError
def initialize(str, length)
super()
args.merge!(val: str.to_s, limit: length.inspect)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/query_error.rb | Ruby | mit | 84 | main | 202 | # frozen_string_literal: true
class API2
# Error while executing query.
class QueryError < FatalError
def initialize(error)
super()
args.merge!(error: error.to_s)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/field_slip_in_use.rb | Ruby | mit | 84 | main | 230 | # frozen_string_literal: true
class API2
# Field slip with code exists and already has an observation
class FieldSlipInUse < ObjectError
def initialize(obj)
super
args.merge!(code: obj.code)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/error.rb | Ruby | mit | 84 | main | 529 | # frozen_string_literal: true
class API2
# API exception base class.
class Error < ::StandardError
attr_accessor :tag, :args, :fatal, :trace
def initialize
super
self.tag = self.class.name.underscore.tr("/", "_").
sub(/^api\d+/, "api").to_sym
self.args = {}
self.fa... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/create_failed.rb | Ruby | mit | 84 | main | 230 | # frozen_string_literal: true
class API2
# POST request couldn't create object.
class CreateFailed < ObjectError
def initialize(obj)
super
args.merge!(error: obj.formatted_errors.join("; "))
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/species_list_already_exists.rb | Ruby | mit | 84 | main | 228 | # frozen_string_literal: true
class API2
# Tried to create species_list that already exists.
class SpeciesListAlreadyExists < FatalError
def initialize(str)
super()
args.merge!(title: str)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/couldnt_download_url.rb | Ruby | mit | 84 | main | 285 | # frozen_string_literal: true
class API2
# Upload was supposed to be a URL, but couldn't get download it.
class CouldntDownloadURL < FatalError
def initialize(url, error)
super()
args.merge!(url: url.to_s, error: "#{error.class.name}: #{error}")
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/must_own_all_namings.rb | Ruby | mit | 84 | main | 246 | # frozen_string_literal: true
class API2
# Can only update names which no one else has proposed on any observations.
class MustOwnAllNamings < FatalError
def initialize(type)
super()
args.merge!(type: type)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/must_be_creator.rb | Ruby | mit | 84 | main | 224 | # frozen_string_literal: true
class API2
# Can only update locations/names which you have created.
class MustBeCreator < FatalError
def initialize(type)
super()
args.merge!(type: type)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/object_not_found_by_id.rb | Ruby | mit | 84 | main | 237 | # frozen_string_literal: true
class API2
# Referenced object id doesn't exist.
class ObjectNotFoundById < FatalError
def initialize(id, model)
super()
args.merge!(id: id.to_s, type: model.type_tag)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/can_only_use_this_field_if_has_specimen.rb | Ruby | mit | 84 | main | 260 | # frozen_string_literal: true
class API2
# Tried to set herbarium_record info without claiming specimen present.
class CanOnlyUseThisFieldIfHasSpecimen < FatalError
def initialize(field)
super()
args.merge!(field: field)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/location_already_exists.rb | Ruby | mit | 84 | main | 246 | # frozen_string_literal: true
class API2
# Tried to create/rename a location over top of an existing one.
class LocationAlreadyExists < FatalError
def initialize(str)
super()
args.merge!(location: str.to_s)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/api_key_not_verified.rb | Ruby | mit | 84 | main | 226 | # frozen_string_literal: true
class API2
# APIKey not verified yet.
class APIKeyNotVerified < FatalError
def initialize(key)
super()
args.merge!(key: key.key.to_s, notes: key.notes.to_s)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/name_wrong_for_rank.rb | Ruby | mit | 84 | main | 246 | # frozen_string_literal: true
class API2
# Taxon name isn't valid for the given rank.
class NameWrongForRank < FatalError
def initialize(str, rank)
super()
args.merge!(name: str.to_s, rank: :"rank_#{rank}")
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/project_taken.rb | Ruby | mit | 84 | main | 220 | # frozen_string_literal: true
class API2
# Tried to create project that already exists.
class ProjectTaken < FatalError
def initialize(title)
super()
args.merge!(title: title.to_s)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/render_failed.rb | Ruby | mit | 84 | main | 259 | # frozen_string_literal: true
class API2
# Error rendering API request results.
class RenderFailed < FatalError
def initialize(error)
super()
msg = "#{error}\n#{error.backtrace.join("\n")}"
args.merge!(error: msg)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/name_already_exists.rb | Ruby | mit | 84 | main | 248 | # frozen_string_literal: true
class API2
# Tried to create/rename a name over top of an existing one.
class NameAlreadyExists < FatalError
def initialize(str)
super()
args.merge!(new: str.to_s, old: str.to_s)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/no_method_for_action.rb | Ruby | mit | 84 | main | 261 | # frozen_string_literal: true
class API2
# Method not implemented for this endpoint.
class NoMethodForAction < FatalError
def initialize(method, action)
super()
args.merge!(method: method.to_s.upcase, action: action.to_s)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/herbarium_record_already_exists.rb | Ruby | mit | 84 | main | 299 | # frozen_string_literal: true
class API2
# Tried to create herbarium record already been used by someone else.
class HerbariumRecordAlreadyExists < FatalError
def initialize(obj)
super()
args.merge!(herbarium: obj.herbarium.name, number: obj.accession_number)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/must_be_only_editor.rb | Ruby | mit | 84 | main | 232 | # frozen_string_literal: true
class API2
# Cannot update locations/names which other users have edited.
class MustBeOnlyEditor < FatalError
def initialize(type)
super()
args.merge!(type: type)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/must_own_all_descriptions.rb | Ruby | mit | 84 | main | 249 | # frozen_string_literal: true
class API2
# Can only update locations/names which you own all the desrciptions for.
class MustOwnAllDescriptions < FatalError
def initialize(type)
super()
args.merge!(type: type)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/user_not_verified.rb | Ruby | mit | 84 | main | 200 | # frozen_string_literal: true
class API2
# User not verified yet.
class UserNotVerified < FatalError
def initialize(user)
super()
args.merge!(login: user.login)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/error/must_own_all_observations.rb | Ruby | mit | 84 | main | 242 | # frozen_string_literal: true
class API2
# Cannot update location/name unless you own all its observations.
class MustOwnAllObservations < FatalError
def initialize(type)
super()
args.merge!(type: type)
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/parsers/date_time_patterns.rb | Ruby | mit | 84 | main | 1,306 | # frozen_string_literal: true
class API2
module Parsers
# Patterns and helpers used by both date and time parser.
module DateTimePatterns
MM = "(0?[1-9]|1[012])"
MMDD1 = '(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])'
MMDD2 = '(0?[1-9]|1[012])-(0?[1-9]|[12]\d|3[01])'... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/parsers/date_parser.rb | Ruby | mit | 84 | main | 4,464 | # frozen_string_literal: true
class API2
module Parsers
# Parse dates for API.
class DateParser < Base
include DateTimePatterns
def parse(str)
scalar_yyyymmdd(str)
rescue ArgumentError
raise(BadParameterValue.new(str, :date))
end
def parse_range
args[:r... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/parsers/object_parser.rb | Ruby | mit | 84 | main | 1,234 | # frozen_string_literal: true
class API2
module Parsers
# Parse objects for API.
class ObjectParser < ObjectBase
attr_accessor :limit
# Always has to have limit argument: the set of allowed object types.
def initialize(*args)
super
self.limit = self.args[:limit]
rai... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/parsers/confidence_parser.rb | Ruby | mit | 84 | main | 279 | # frozen_string_literal: true
class API2
module Parsers
# Parse confidences for API.
class ConfidenceParser < FloatParser
def initialize(*args)
super
self.args[:limit] = Range.new(Vote.minimum_vote, Vote.maximum_vote)
end
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/parsers/altitude_parser.rb | Ruby | mit | 84 | main | 213 | # frozen_string_literal: true
class API2
module Parsers
# Parse altitudes for API.
class AltitudeParser < CoordinateParser
def parse(str)
super(:altitude, str)
end
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/parsers/place_name_parser.rb | Ruby | mit | 84 | main | 305 | # frozen_string_literal: true
class API2
module Parsers
# Parse place names for API.
class PlaceNameParser < LocationParser
def parse(str)
val = super
val.is_a?(Location) ? val.display_name : str
rescue ObjectNotFoundByString
str
end
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/parsers/project_parser.rb | Ruby | mit | 84 | main | 721 | # frozen_string_literal: true
class API2
module Parsers
# Parse projects for API.
class ProjectParser < ObjectBase
def model
Project
end
def try_finding_by_string(str)
Project.find_by_title(str)
end
def parse(str)
val = super
check_if_admin!(val... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/parsers/integer_parser.rb | Ruby | mit | 84 | main | 575 | # frozen_string_literal: true
class API2
module Parsers
# Parse integer for API.
class IntegerParser < Base
def parse(str)
raise(BadParameterValue.new(str, :integer)) unless /^-?\d+$/.match?(str)
val = str.to_i
limit = args[:limit]
return val if !limit || limit.include?... |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/parsers/archive_parser.rb | Ruby | mit | 84 | main | 285 | # frozen_string_literal: true
class API2
module Parsers
# Parse sequence archives for API.
class ArchiveParser < EnumParser
def initialize(api, key, args)
args[:limit] ||= WebSequenceArchive.all_archives.map(&:to_sym)
super
end
end
end
end |
github | MushroomObserver/mushroom-observer | https://github.com/MushroomObserver/mushroom-observer | app/classes/api2/parsers/external_site_parser.rb | Ruby | mit | 84 | main | 289 | # frozen_string_literal: true
class API2
module Parsers
# Parse external sites for API.
class ExternalSiteParser < ObjectBase
def model
ExternalSite
end
def try_finding_by_string(str)
ExternalSite.find_by_name(str)
end
end
end
end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.