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 | open-ews/open-ews | https://github.com/open-ews/open-ews | app/controllers/dashboard/settings/users_controller.rb | Ruby | mit | 47 | develop | 919 | module Dashboard
module Settings
class UsersController < DashboardController
def index
@users = paginate_resources(scope)
end
def show
@user = scope.find(params[:id])
end
def new
@user = UserForm.new
end
def create
@user = UserForm.new(a... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/controllers/dashboard/settings/accounts_controller.rb | Ruby | mit | 47 | develop | 803 | module Dashboard
module Settings
class AccountsController < DashboardController
self.action_on_open_redirect = :log
def show
@account = AccountForm.initialize_with(current_account)
end
def update
@account = AccountForm.new(object: current_account, **permitted_params)
... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/filters/application_filter.rb | Ruby | mit | 47 | develop | 997 | class ApplicationFilter < ApplicationRequestSchema
class_attribute :field_collection
def self.has_fields(field_collection)
self.field_collection = field_collection
params do
field_collection.each do |field|
optional(field.path.to_sym).filled(:hash).schema(field.schema.schema_definition)
... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/helpers/application_helper.rb | Ruby | mit | 47 | develop | 6,092 | module ApplicationHelper
NOTIFICATION_STATUSES = {
pending: { color: "gray-200", icon: "clock" },
failed: { color: "red", icon: "alert-triangle" },
succeeded: { color: "green", icon: "check" }
}.freeze
BROADCAST_STATUSES = {
pending: { color: "gray-200", icon: "clock" },
queued: { color: "gra... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/stats_query.rb | Ruby | mit | 47 | develop | 972 | class StatsQuery
MAX_RESULTS = 10_000
class TooManyResultsError < StandardError; end
attr_reader :filter_fields, :group_by_fields
def initialize(options)
@filter_fields = options.fetch(:filter_fields, [])
@group_by_fields = options.fetch(:group_by_fields)
end
def apply(scope)
query = apply_f... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/beneficiary_filter_data.rb | Ruby | mit | 47 | develop | 603 | class BeneficiaryFilterData
include ActiveModel::Model
include ActiveModel::Attributes
attribute :data, FilterDataType.new(field_definitions: FieldDefinitions::BeneficiaryFields)
attribute :address_data_field_name
def address_fields
@address_fields ||= data.fields.each_with_object({}) do |(_name, field)... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/broadcast_beneficiary_group.rb | Ruby | mit | 47 | develop | 360 | class BroadcastBeneficiaryGroup < ApplicationRecord
belongs_to :broadcast
belongs_to :beneficiary_group
validate :validate_associations_belong_to_the_same_account
private
def validate_associations_belong_to_the_same_account
return if broadcast.account_id == beneficiary_group.account_id
errors.add(... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/delivery_attempt_status_update.rb | Ruby | mit | 47 | develop | 722 | class DeliveryAttemptStatusUpdate
INCOMPLETE_STATUSES = {
voice: [ "queued", "ringing", "in-progress" ],
sms: [ "accepted", "scheduled", "queued", "sending" ]
}.freeze
SUCCEEDED_STATUSES = {
voice: [ "completed" ],
sms: [ "delivered", "sent" ]
}.freeze
COMPLETED = "completed".freeze
FAILED... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/query_cache.rb | Ruby | mit | 47 | develop | 769 | class QueryCache
attr_reader :store, :default_expires_in
def initialize(store: Rails.cache, default_expires_in: 1.day)
@store = store
@default_expires_in = default_expires_in
end
def fetch(params, scope_keys: [], **)
store.fetch(cache_key(params, scope_keys:), expires_in: default_expires_in, **) d... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/filter_field.rb | Ruby | mit | 47 | develop | 1,135 | class FilterField
attr_reader :field_definition, :operator, :value
delegate :association, :column, to: :field_definition
def initialize(field_definition:, operator:, value:)
@field_definition = field_definition
@operator = operator.to_sym
@value = value
end
def to_query
column.public_send(o... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/app_request.rb | Ruby | mit | 47 | develop | 626 | class AppRequest
attr_reader :request
def initialize(request)
@request = ActionDispatch::Request.new(request.env.except("HTTP_X_FORWARDED_HOST"))
end
def account_subdomain_request?
_subdomain, *namespace = request.subdomains
namespace == [ AppSettings.fetch(:app_subdomain) ]
end
def find_acco... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/broadcast_preview.rb | Ruby | mit | 47 | develop | 778 | class BroadcastPreview
attr_reader :broadcast
def initialize(broadcast)
@broadcast = broadcast
end
def filtered_beneficiaries
return Beneficiary.none if !beneficiary_filter.success? || beneficiary_filter.output.blank?
FilterScopeQuery.new(
broadcast.account.beneficiaries.active,
benef... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/application_record.rb | Ruby | mit | 47 | develop | 231 | class ApplicationRecord < ActiveRecord::Base
extend Enumerize
include SerializableResource
include DecoratableResource
include ApproximateCount
primary_abstract_class
scope :latest_first, -> { order(id: :desc) }
end |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/user.rb | Ruby | mit | 47 | develop | 865 | class User < ApplicationRecord
devise :two_factor_authenticatable
ACCEPTED_AVATAR_CONTENT_TYPES = [ "image/png", "image/jpeg", "image/webp" ].freeze
devise :invitable, :registerable, :two_factor_authenticatable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable, reconfirmable:... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/audio_url.rb | Ruby | mit | 47 | develop | 252 | class AudioURL
attr_reader :key, :host
def initialize(options)
@key = options.fetch(:key)
@host = options.fetch(:host) { AppSettings.fetch(:audio_host) }
end
def url
uri = URI(host)
uri.path = "/#{key}"
uri.to_s
end
end |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/beneficiary_group.rb | Ruby | mit | 47 | develop | 262 | class BeneficiaryGroup < ApplicationRecord
belongs_to :account
has_many :memberships, class_name: "BeneficiaryGroupMembership"
has_many :members, through: :memberships, source: :beneficiary, class_name: "Beneficiary"
validates :name, presence: true
end |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/delivery_attempt.rb | Ruby | mit | 47 | develop | 774 | class DeliveryAttempt < ApplicationRecord
attribute :phone_number, :phone_number
belongs_to :notification, counter_cache: true
belongs_to :beneficiary
belongs_to :broadcast
delegate :account, to: :broadcast
delegate :initiated?, :transition_to!, :may_transition_to?, to: :state_machine
enumerize :error_... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/country_address_data.rb | Ruby | mit | 47 | develop | 653 | module CountryAddressData
Locality = Data.define(:value, :name_en, :name_local, :subdivisions)
SETTINGS = {
KH: :administrative_division_level_3_code,
LA: :administrative_division_level_2_code,
NP: :administrative_division_level_2_code
}
def self.address_field_name(iso_country_code)
SETTINGS[i... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/errors.rb | Ruby | mit | 47 | develop | 1,038 | module Errors
class ApplicationError < StandardError
attr_reader :code, :definition
def initialize(message = nil, code:)
super(message || code.to_s.humanize)
@code = Definitions.find(code).code
end
end
class ImportError < ApplicationError; end
module Definitions
Error = Data.defin... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/dashboard_summary.rb | Ruby | mit | 47 | develop | 1,772 | class DashboardSummary
attr_reader :account
class Stats
attr_reader :scope
def initialize(scope)
@scope = scope
end
def total_count
@total_count ||= scope.approximate_count
end
def new_count
@new_count ||= scope.where(created_at: 30.days.ago..).count
end
def ne... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/filter_scope_query.rb | Ruby | mit | 47 | develop | 405 | class FilterScopeQuery
attr_reader :scope, :filter_fields
def initialize(scope, filter_fields)
@scope = scope
@filter_fields = filter_fields
end
def apply
scope.left_joins(joins_with).where(conditions).distinct
end
private
def joins_with
filter_fields.map(&:association).compact_blank.u... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/stat_result.rb | Ruby | mit | 47 | develop | 260 | StatResult = Data.define(:key, :groups, :value, :sequence_number) do
def id
StatResult::IDGenerator.generate_id(key)
end
end
class StatResult::IDGenerator
def self.generate_id(key)
Digest::SHA256.hexdigest(key.compact_blank.join(":"))
end
end |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/broadcast_state_machine.rb | Ruby | mit | 47 | develop | 705 | class BroadcastStateMachine
attr_reader :current_status
delegate :pending?, :errored?, :may_transition_to?, :transition_to!, to: :state_machine
class StateMachine < StateMachine::Machine
state :pending, initial: true, transitions_to: { running: { as: :queued } }
state :queued
state :errored, transit... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/account.rb | Ruby | mit | 47 | develop | 1,137 | class Account < ApplicationRecord
LOGO_CONTENT_TYPES = %w[image/jpg image/png].freeze
has_one :access_token, class_name: "Doorkeeper::AccessToken", foreign_key: :resource_owner_id
has_many :users
has_many :beneficiaries
has_many :beneficiary_groups
has_many :broadcasts
has_many :events
has_many :notifi... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/notification.rb | Ruby | mit | 47 | develop | 947 | class Notification < ApplicationRecord
attribute :phone_number, :phone_number
belongs_to :broadcast
belongs_to :beneficiary, optional: true
has_many :delivery_attempts
delegate :account, to: :broadcast
delegate :transition_to!, :transition_to, to: :state_machine
validates :beneficiary, presence: true,... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/beneficiary.rb | Ruby | mit | 47 | develop | 1,077 | class Beneficiary < ApplicationRecord
attribute :phone_number, :phone_number
attribute :address_administrative_division_codes, :string, array: true
enumerize :status, in: [ :active, :disabled ], scope: :shallow
enumerize :gender, in: [ "M", "F" ]
enumerize :disability_status, in: [ :none, :disabled ]
enume... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/beneficiary_address.rb | Ruby | mit | 47 | develop | 857 | class BeneficiaryAddress < ApplicationRecord
enumerize :iso_country_code, in: ISO3166::Country.codes.freeze
attribute :beneficiary_address_validator, default: -> { BeneficiaryAddressValidator.new }
belongs_to :beneficiary, inverse_of: :addresses
validates :iso_region_code, presence: true
validates :iso_reg... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/feature_flag.rb | Ruby | mit | 47 | develop | 331 | class FeatureFlag
PERMISSIONS = {
1 => [ :alerts ],
1297 => [ :alerts ],
1198 => [ :alerts ],
1300 => [ :alerts ],
1331 => [ :alerts ],
1332 => [ :alerts ],
1495 => [ :alerts ]
}
class << self
def enabled_for?(user, flag)
PERMISSIONS.fetch(user.id, []).include?(flag)
end... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/aggregate_query.rb | Ruby | mit | 47 | develop | 397 | class AggregateQuery
attr_reader :scope, :group_by_fields
def initialize(scope, group_by_fields)
@scope = scope
@group_by_fields = group_by_fields
end
def apply
scope.left_joins(joins_with).group(group_columns)
end
private
def joins_with
group_by_fields.map(&:association).compact_blank... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/import.rb | Ruby | mit | 47 | develop | 737 | class Import < ApplicationRecord
belongs_to :user
belongs_to :account
attr_accessor :error_line
enumerize :resource_type, in: %w[Beneficiary]
has_one_attached :file
validates :file, presence: true, attached: true, content_type: "text/csv"
before_create :set_default_status
delegate :transition_to!,... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/beneficiary_group_membership.rb | Ruby | mit | 47 | develop | 365 | class BeneficiaryGroupMembership < ApplicationRecord
belongs_to :beneficiary
belongs_to :beneficiary_group
validate :validate_associations_belong_to_the_same_account
private
def validate_associations_belong_to_the_same_account
return if beneficiary.account_id == beneficiary_group.account_id
errors... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/broadcast_summary.rb | Ruby | mit | 47 | develop | 658 | class BroadcastSummary
extend ActiveModel::Translation
extend ActiveModel::Naming
include ActiveModel::Conversion
attr_accessor :broadcast
def initialize(broadcast)
self.broadcast = broadcast
end
def notifications_count
notifications.count
end
def notifications_still_to_be_called
notif... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/broadcast.rb | Ruby | mit | 47 | develop | 2,147 | class Broadcast < ApplicationRecord
AUDIO_CONTENT_TYPES = %w[audio/mpeg audio/mp3 audio/wav audio/x-wav].freeze
MAX_BENEFICIARY_GROUPS = 10
class StateMachine < StateMachine::ActiveRecord
state :pending, initial: true, transitions_to: :queued
state :queued, transitions_to: [ :running, :errored ]
stat... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/export.rb | Ruby | mit | 47 | develop | 514 | class Export < ApplicationRecord
enumerize :resource_type, in: %w[
Beneficiary
BeneficiaryGroup
BeneficiaryGroupMembership
Broadcast
Notification
]
belongs_to :user
belongs_to :account
has_one_attached :file
before_create :set_default_values
validates :scoped_to, presence: true
d... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/concerns/approximate_count.rb | Ruby | mit | 47 | develop | 395 | module ApproximateCount
extend ActiveSupport::Concern
class_methods do
# https://wiki.postgresql.org/wiki/Count_estimate
def approximate_count
explain_result = connection.execute("EXPLAIN (FORMAT JSON) #{all.to_sql}")
json_result = JSON.parse(explain_result.first["QUERY PLAN"])
... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/concerns/serializable_resource.rb | Ruby | mit | 47 | develop | 346 | module SerializableResource
extend ActiveSupport::Concern
included do
delegate :jsonapi_serializer_class, to: :class
end
module ClassMethods
def jsonapi_serializer_class
"#{model_name}Serializer".constantize
end
def csv_serializer_class
CSVSerializers.const_get("#{model_name}Seria... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/country_address_data/la.rb | Ruby | mit | 47 | develop | 600 | module CountryAddressData
class LA
def self.address_data
@address_data ||= Baan::Province.all.map do |province|
CountryAddressData::Locality.new(
value: province.code,
name_en: province.name_en,
name_local: province.name_lo,
subdivisions: province.districts.ma... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/country_address_data/kh.rb | Ruby | mit | 47 | develop | 1,347 | module CountryAddressData
class KH
def self.address_data
@address_data ||= begin
data = Pumi::Commune.all.each_with_object(Hash.new { |h1, k1| h1[k1] = Hash.new { |h2, k2| h2[k2] = [] } }) do |commune, result|
province_locality = CountryAddressData::Locality.new(
value: commune... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/country_address_data/np.rb | Ruby | mit | 47 | develop | 600 | module CountryAddressData
class NP
def self.address_data
@address_data ||= Gaun::Province.all.map do |province|
CountryAddressData::Locality.new(
value: province.code,
name_en: province.name_en,
name_local: province.name_ne,
subdivisions: province.districts.ma... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/field_definitions/beneficiary_group_fields.rb | Ruby | mit | 47 | develop | 289 | module FieldDefinitions
BeneficiaryGroupFields = Collection.new(
[
Field.new(
name: "name",
column: BeneficiaryGroup.arel_table[:name],
schema: FilterSchema::StringType.define,
description: "A friendly name for the group."
)
]
)
end |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/field_definitions/event_fields.rb | Ruby | mit | 47 | develop | 623 | module FieldDefinitions
EventFields = Collection.new(
[
Field.new(
name: "type",
column: Event.arel_table[:type],
schema: FilterSchema::ListType.define(type: :string, options: Event.type.values),
description: "The event type. Must be one of #{Event.type.values.map { "`#{it}`"... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/field_definitions/types.rb | Ruby | mit | 47 | develop | 271 | module FieldDefinitions
module Types
include Dry.Types()
Number = String.constructor do |string|
string.gsub(/\D/, "") if string.present?
end
UpcaseString = String.constructor do |string|
string.upcase if string.present?
end
end
end |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/field_definitions/beneficiary_fields.rb | Ruby | mit | 47 | develop | 4,966 | module FieldDefinitions
BeneficiaryFields = Collection.new([
Field.new(
name: :phone_number,
column: Beneficiary.arel_table[:phone_number],
schema: FilterSchema::StringType.define,
description: "The phone number of the beneficiary.",
required: true,
example: "85516200101"
)... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/field_definitions/field.rb | Ruby | mit | 47 | develop | 1,943 | module FieldDefinitions
class Field
OPERATORS = %i[
eq
not_eq
contains
not_contains
starts_with
gt
gteq
lt
lteq
between
is_null
in
not_in
].freeze
MULTIPLE_SELECTION_OPERATORS = %w[in not_in]
attr_reader :name, :prefix, :p... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/field_definitions/collection.rb | Ruby | mit | 47 | develop | 453 | module FieldDefinitions
class Collection
include Enumerable
attr_reader :collection
delegate :each, to: :collection
def initialize(collection)
@collection = collection
end
def find_by!(attributes)
collection.find(-> { raise ArgumentError, "Unable to find field with #{attributes... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/field_definitions/broadcast_fields.rb | Ruby | mit | 47 | develop | 1,589 | module FieldDefinitions
BroadcastFields = Collection.new(
[
Field.new(name: "name", column: Broadcast.arel_table[:name], schema: FilterSchema::StringType.define, description: "The name of the broadcast."),
Field.new(name: "status", column: Broadcast.arel_table[:status], schema: FilterSchema::ListType.... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/field_definitions/notification_fields.rb | Ruby | mit | 47 | develop | 1,287 | module FieldDefinitions
NotificationFields = Collection.new([
Field.new(name: "status", column: Notification.arel_table[:status], schema: FilterSchema::ListType.define(type: :string, options: Notification.status.values), description: "Must be one of #{Notification.status.values.map { |t| "`#{t}`" }.join(", ")}.")... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/field_definitions/filter_schema/list_type.rb | Ruby | mit | 47 | develop | 732 | module FieldDefinitions
module FilterSchema
class ListType < Base
def self.define(type:, options:)
schema = Dry::Schema.Params do
optional(:eq).filled(type, included_in?: options)
optional(:not_eq).filled(type, included_in?: options)
optional(:in).array(type, included_i... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/field_definitions/filter_schema/country_list_type.rb | Ruby | mit | 47 | develop | 411 | module FieldDefinitions
module FilterSchema
class CountryListType < ListType
def options_for_select
results = options.fetch(:list_options).map do
country = ISO3166::Country[it]
localized_name = country.translations.fetch(I18n.locale.to_s, country.iso_short_name)
[ loca... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/field_definitions/filter_schema/value_type.rb | Ruby | mit | 47 | develop | 669 | module FieldDefinitions
module FilterSchema
class ValueType < Base
def self.define(type:, **options)
schema = Dry::Schema.Params do
optional(:eq).filled(type)
optional(:not_eq).filled(type)
optional(:gt).filled(type)
optional(:gteq).filled(type)
opti... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/field_definitions/filter_schema/string_type.rb | Ruby | mit | 47 | develop | 674 | module FieldDefinitions
module FilterSchema
class StringType < Base
def self.define(type: :string, **options)
schema = Dry::Schema.Params do
optional(:eq).filled(type)
optional(:not_eq).filled(type)
optional(:contains).filled(type)
optional(:not_contains).fill... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/models/field_definitions/filter_schema/base.rb | Ruby | mit | 47 | develop | 411 | module FieldDefinitions
module FilterSchema
class Base
attr_reader :schema_definition, :value_type, :form_value_type, :options
def initialize(schema_definition:, value_type:, **options)
@schema_definition = schema_definition
@value_type = value_type
@form_value_type = options.... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/validators/email_format_validator.rb | Ruby | mit | 47 | develop | 224 | class EmailFormatValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if value =~ Devise.email_regexp
record.errors.add(attribute, options.fetch(:message, :invalid))
end
end |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/validators/phone_number_type_validator.rb | Ruby | mit | 47 | develop | 411 | class PhoneNumberTypeValidator < ActiveModel::EachValidator
attr_reader :validator
def initialize(*, **options)
super(*)
@validator = options.fetch(:validator) { PhoneNumberValidator.new }
end
def validate_each(record, attribute, value)
return record.errors.add(attribute, :blank) if value.blank?
... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/validators/subdomain_validator.rb | Ruby | mit | 47 | develop | 454 | class SubdomainValidator < ActiveModel::EachValidator
MIN_LENGTH = 3
def validate_each(record, attribute, value)
return record.errors.add(attribute, :blank) if value.blank?
return record.errors.add(attribute, :too_short, count: MIN_LENGTH) if value.length < MIN_LENGTH
scope = options.fetch(:scope) { -... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/validators/beneficiary_address_validator.rb | Ruby | mit | 47 | develop | 866 | class BeneficiaryAddressValidator
attr_reader :errors
Error = Data.define(:key, :message)
def initialize
@errors = []
end
def valid?(attributes)
attributes.symbolize_keys!
4.downto(3) do |level|
division_attributes = [ :code, :name ].map { |type| :"administrative_division_level_#{level}_... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/validators/email_uniqueness_validator.rb | Ruby | mit | 47 | develop | 255 | class EmailUniquenessValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if value.blank?
return unless User.exists?(email: value)
record.errors.add(attribute, options.fetch(:message, :taken))
end
end |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/serailizers/stat_serializer.rb | Ruby | mit | 47 | develop | 246 | class StatSerializer < JSONAPISerializer
attribute :result do |object|
result = {}
object.groups.each_with_index do |group, index|
result[group] = object.key[index]
end
result[:value] = object.value
result
end
end |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/serailizers/beneficiary_address_serializer.rb | Ruby | mit | 47 | develop | 348 | class BeneficiaryAddressSerializer < ResourceSerializer
attributes :iso_region_code,
:administrative_division_level_2_code,
:administrative_division_level_2_name,
:administrative_division_level_3_code,
:administrative_division_level_3_name,
:administrative_division_level_4_code,
:administrativ... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/serailizers/broadcast_serializer.rb | Ruby | mit | 47 | develop | 227 | class BroadcastSerializer < ResourceSerializer
attributes :name, :channel, :audio_url, :message, :metadata, :beneficiary_filter, :status, :error_code
has_many :beneficiary_groups, serializer: BeneficiaryGroupSerializer
end |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/serailizers/simple_serializer.rb | Ruby | mit | 47 | develop | 1,755 | module SimpleSerializer
extend ActiveSupport::Concern
included do
include ActiveModel::Serialization
attr_reader :object
end
def initialize(object)
@object = object
end
def as_json(*)
self.class.serialized_attributes.each_with_object({}) do |(attribute_name, attribute_block), result|
... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/serailizers/beneficiary_serializer.rb | Ruby | mit | 47 | develop | 307 | class BeneficiarySerializer < ResourceSerializer
attributes :phone_number, :gender, :status, :disability_status, :iso_language_code, :date_of_birth, :iso_country_code, :metadata
has_many :addresses, serializer: BeneficiaryAddressSerializer
has_many :groups, serializer: BeneficiaryGroupSerializer
end |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/serailizers/csv_serializers/broadcast_serializer.rb | Ruby | mit | 47 | develop | 319 | module CSVSerializers
class BroadcastSerializer < ResourceSerializer
has_associations :beneficiary_groups
attributes :name, :channel, :audio_url, :message, :beneficiary_filter, :status, :error_code
attribute :beneficiary_groups do |object|
object.beneficiary_groups.pluck(:name)
end
end
end |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/serailizers/csv_serializers/beneficiary_address_serializer.rb | Ruby | mit | 47 | develop | 440 | module CSVSerializers
class BeneficiaryAddressSerializer < ResourceSerializer
attributes :iso_region_code,
:administrative_division_level_2_code,
:administrative_division_level_2_name,
:administrative_division_level_3_code,
:administrative_division_level_3_n... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/serailizers/csv_serializers/beneficiary_serializer.rb | Ruby | mit | 47 | develop | 392 | module CSVSerializers
class BeneficiarySerializer < ResourceSerializer
has_associations :addresses
attributes :phone_number, :gender, :status, :disability_status, :iso_language_code, :date_of_birth, :iso_country_code
attribute :addresses do |object|
object.addresses.map do |address|
Benefi... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/serailizers/csv_serializers/beneficiary_group_membership_serializer.rb | Ruby | mit | 47 | develop | 251 | module CSVSerializers
class BeneficiaryGroupMembershipSerializer < ResourceSerializer
has_associations :beneficiary
attributes :beneficiary_id
attribute :phone_number do |object|
object.beneficiary.phone_number
end
end
end |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/sample_data/fake_resource/alert.rb | Ruby | mit | 47 | develop | 4,598 | module FakeResource
class Alert
include ActiveModel::Model
include ActiveModel::Attributes
extend Enumerize
attribute :id
attribute :event
attribute :headline
attribute :description
attribute :instruction
attribute :urgency
attribute :severity
attribute :created_at, :date... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/sample_data/fake_resource/broadcast.rb | Ruby | mit | 47 | develop | 1,537 | module FakeResource
class Broadcast
include ActiveModel::Model
include ActiveModel::Attributes
extend Enumerize
attribute :id
attribute :operator
attribute :channel
attribute :status
attribute :progress_percentage, :integer, default: 0
attribute :created_at
attribute :started... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/forms/export_form.rb | Ruby | mit | 47 | develop | 1,693 | class ExportForm < ApplicationForm
class InvalidFormValues < StandardError; end
NESTED_RESOURCE_TYPES = {
"Notification" => {
scope_model: Broadcast,
field: :broadcast_id
},
"BeneficiaryGroupMembership" => {
scope_model: BeneficiaryGroup,
field: :beneficiary_group_id
}
}.f... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/forms/notification_filter_form.rb | Ruby | mit | 47 | develop | 406 | class NotificationFilterForm < FilterForm
self.filter_class = NotificationFilter
attribute :status, FormType.new(form: FilterFieldForm)
attribute :delivery_attempts_count, FormType.new(form: FilterFieldForm)
attribute :phone_number, FormType.new(form: FilterFieldForm)
attribute :created_at, FormType.new(form... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/forms/user_form.rb | Ruby | mit | 47 | develop | 578 | class UserForm < ApplicationForm
attribute :object, default: -> { User.new }
attribute :name
attribute :email
attribute :account
attribute :inviter
validates :name, :email, presence: true
validates :email, email_uniqueness: true, email_format: true, allow_blank: true
delegate :persisted?, :id, to: :ob... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/forms/broadcast_form.rb | Ruby | mit | 47 | develop | 2,721 | class BroadcastForm < ApplicationForm
attribute :account
attribute :channel
attribute :audio_file
attribute :message
attribute :created_by
attribute :started_by
attribute :stopped_by
attribute :updated_by
attribute :name
attribute :beneficiary_groups, FilledArrayType.new
attribute :beneficiary_fil... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/forms/forgot_subdomain_form.rb | Ruby | mit | 47 | develop | 458 | class ForgotSubdomainForm < ApplicationForm
attribute :email
validates :email, presence: true
validate :validate_email_exists
def self.model_name
ActiveModel::Name.new(self, nil, "User")
end
def save
return false if invalid?
ForgotSubdomainMailer.forgot_subdomain(User.find_by!(email:)).deliv... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/forms/filter_form.rb | Ruby | mit | 47 | develop | 457 | class FilterForm < ApplicationForm
class_attribute :filter_class
def self.model_name
ActiveModel::Name.new(self, nil, "Filter")
end
def apply(scope)
FilterScopeQuery.new(
scope,
filter_class.new(input_params: normalized_filter_params).output
).apply
end
def normalized_filter_param... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/forms/two_factor_authentication_form.rb | Ruby | mit | 47 | develop | 567 | class TwoFactorAuthenticationForm < ApplicationForm
attribute :user
attribute :otp_attempt
validates :otp_attempt, presence: true
validate :validate_otp_attempt
def self.model_name
ActiveModel::Name.new(self, nil, "TwoFactorAuthentication")
end
def persisted?
false
end
def save
return ... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/forms/broadcast_filter_form.rb | Ruby | mit | 47 | develop | 313 | class BroadcastFilterForm < FilterForm
self.filter_class = BroadcastFilter
attribute :name, FormType.new(form: FilterFieldForm)
attribute :channel, FormType.new(form: FilterFieldForm)
attribute :status, FormType.new(form: FilterFieldForm)
attribute :created_at, FormType.new(form: FilterFieldForm)
end |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/forms/beneficiary_filter_form.rb | Ruby | mit | 47 | develop | 1,234 | class BeneficiaryFilterForm < FilterForm
self.filter_class = BeneficiaryFilter
class AddressFieldForm < FilterFieldForm; end
attribute :status, FormType.new(form: FilterFieldForm)
attribute :gender, FormType.new(form: FilterFieldForm)
attribute :disability_status, FormType.new(form: FilterFieldForm)
attri... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/forms/application_form.rb | Ruby | mit | 47 | develop | 250 | class ApplicationForm
include ActiveModel::Model
include ActiveModel::Attributes
extend Enumerize
def self.attributes
attribute_names.each_with_object({}) do |name, result|
result[name] = type_for_attribute(name)
end
end
end |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/forms/account_form.rb | Ruby | mit | 47 | develop | 1,738 | class AccountForm < ApplicationForm
attribute :object, default: -> { Account.new }
attribute :name, FormDataType.new
attribute :country
attribute :logo
attribute :somleng_account_sid, FormDataType.new
attribute :somleng_auth_token, FormDataType.new
attribute :notification_phone_number, FormDataType.new
... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/request_schemas/jsonapi_request_schema.rb | Ruby | mit | 47 | develop | 1,388 | class JSONAPIRequestSchema < ApplicationRequestSchema
option :resource, optional: true
def self.attribute_rule(*args, &block)
args = args.first if args.one?
rule(data: { attributes: args }) do |context:|
attributes = values.fetch(:data).fetch(:attributes, {})
relationships = values.fetch(:data)... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/request_schemas/metadata_request_schema.rb | Ruby | mit | 47 | develop | 262 | class MetadataRequestSchema < ApplicationRequestSchema
METADATA_MERGE_MODES = %w[replace merge deep_merge].freeze
params do
optional(:metadata).filled(:hash)
optional(:metadata_merge_mode).filled(:str?, included_in?: METADATA_MERGE_MODES)
end
end |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/request_schemas/application_request_schema.rb | Ruby | mit | 47 | develop | 1,919 | class ApplicationRequestSchema < Dry::Validation::Contract
Types = FieldDefinitions::Types
attr_reader :input_params
option :resource, optional: true
option :account, optional: true
option :phone_number_validator, default: -> { PhoneNumberValidator.new }
delegate :success?, :context, :errors, to: :result... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/request_schemas/schema_rules/application_schema_rules.rb | Ruby | mit | 47 | develop | 223 | module SchemaRules
class ApplicationSchemaRules
attr_reader :context
def initialize(context)
@context = context
end
private
delegate :account, :values, :resource, :key, to: :context
end
end |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/request_schemas/schema_rules/jsonapi_schema_rules.rb | Ruby | mit | 47 | develop | 205 | module SchemaRules
class JSONAPISchemaRules < ApplicationSchemaRules
def values
super.dig(:data, :attributes)
end
def key(key)
super(data: { attributes: key })
end
end
end |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/request_schemas/v1/update_beneficiary_group_request_schema.rb | Ruby | mit | 47 | develop | 389 | module V1
class UpdateBeneficiaryGroupRequestSchema < JSONAPIRequestSchema
params do
required(:data).value(:hash).schema do
required(:type).filled(:str?, eql?: "beneficiary_group")
required(:id).filled(:integer)
required(:attributes).value(:hash).schema do
required(:name).f... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/request_schemas/v1/beneficiary_group_request_schema.rb | Ruby | mit | 47 | develop | 344 | module V1
class BeneficiaryGroupRequestSchema < JSONAPIRequestSchema
params do
required(:data).value(:hash).schema do
required(:type).filled(:str?, eql?: "beneficiary_group")
required(:attributes).value(:hash).schema do
required(:name).filled(:str?, max_size?: 255)
end
... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/request_schemas/v1/beneficiary_stats_request_schema.rb | Ruby | mit | 47 | develop | 1,844 | module V1
class BeneficiaryStatsRequestSchema < ApplicationRequestSchema
option :beneficiary_address_validator, default: -> { BeneficiaryAddressValidator.new }
GROUPS = [
"gender",
"disability_status",
"iso_language_code",
"iso_country_code",
"address.iso_region_code",
"ad... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/request_schemas/v1/event_stats_request_schema.rb | Ruby | mit | 47 | develop | 630 | module V1
class EventStatsRequestSchema < ApplicationRequestSchema
GROUPS = [ "type" ].freeze
params do
optional(:filter).schema(EventFilter.schema)
required(:group_by).value(:array).each(:string, included_in?: GROUPS)
end
rule(:filter).validate(contract: EventFilter)
def output
... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/request_schemas/v1/beneficiary_request_schema.rb | Ruby | mit | 47 | develop | 2,632 | module V1
class BeneficiaryRequestSchema < JSONAPIRequestSchema
option :beneficiary_address_validator, default: -> { BeneficiaryAddressValidator.new }
params do
required(:data).value(:hash).schema do
required(:type).filled(:str?, eql?: "beneficiary")
required(:attributes).value(:hash).s... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/request_schemas/v1/beneficiary_address_request_schema.rb | Ruby | mit | 47 | develop | 1,245 | module V1
class BeneficiaryAddressRequestSchema < JSONAPIRequestSchema
option :beneficiary_address_validator, default: -> { BeneficiaryAddressValidator.new }
params do
required(:data).value(:hash).schema do
required(:type).filled(:str?, eql?: "beneficiary_address")
required(:attributes)... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/request_schemas/v1/notification_stats_request_schema.rb | Ruby | mit | 47 | develop | 754 | module V1
class NotificationStatsRequestSchema < ApplicationRequestSchema
GROUPS = [
"status",
*BeneficiaryStatsRequestSchema::GROUPS.map { |f| "beneficiary.#{f}" }
].freeze
params do
optional(:filter).schema(NotificationFilter.schema)
required(:group_by).value(:array).each(:strin... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/request_schemas/v1/broadcast_request_schema.rb | Ruby | mit | 47 | develop | 2,434 | module V1
class BroadcastRequestSchema < JSONAPIRequestSchema
option :broadcast_state_machine, default: -> { BroadcastStateMachine.new }
params do
required(:data).value(:hash).schema do
required(:type).filled(:str?, eql?: "broadcast")
required(:attributes).value(:hash).schema do
... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/request_schemas/v1/beneficiary_group_member_request_schema.rb | Ruby | mit | 47 | develop | 616 | module V1
class BeneficiaryGroupMemberRequestSchema < JSONAPIRequestSchema
option :beneficiary_group
params do
required(:data).value(:hash).schema do
required(:type).filled(:str?, eql?: "beneficiary_group_member")
required(:attributes).value(:hash).schema do
required(:benefici... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/request_schemas/v1/update_beneficiary_request_schema.rb | Ruby | mit | 47 | develop | 1,198 | module V1
class UpdateBeneficiaryRequestSchema < JSONAPIRequestSchema
params do
required(:data).value(:hash).schema do
required(:id).filled(:integer)
required(:type).filled(:str?, eql?: "beneficiary")
required(:attributes).value(:hash).schema do
optional(:phone_number).fill... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/request_schemas/v1/update_broadcast_request_schema.rb | Ruby | mit | 47 | develop | 3,011 | module V1
class UpdateBroadcastRequestSchema < JSONAPIRequestSchema
VALID_STATES = [ "running", "stopped" ].freeze
option :broadcast_state_machine, default: -> { BroadcastStateMachine.new(resource.status) }
params do
required(:data).value(:hash).schema do
required(:id).filled(:integer)
... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/jobs/retry_notification_job.rb | Ruby | mit | 47 | develop | 386 | class RetryNotificationJob < ApplicationJob
def perform(notification)
return if notification.completed? || notification.max_delivery_attempts_reached?
notification.delivery_attempts.create!(
beneficiary: notification.beneficiary,
broadcast: notification.broadcast,
phone_number: notification... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/jobs/update_delivery_attempt_status_job.rb | Ruby | mit | 47 | develop | 1,464 | class UpdateDeliveryAttemptStatusJob < ApplicationJob
queue_as AppSettings.fetch(:aws_sqs_low_priority_queue_name)
class Handler
attr_reader :delivery_attempt, :somleng_client
def initialize(delivery_attempt, **options)
@delivery_attempt = delivery_attempt
@somleng_client = options.fetch(:soml... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/jobs/execute_workflow_job.rb | Ruby | mit | 47 | develop | 377 | class ExecuteWorkflowJob < ApplicationJob
queue_as do
workflow_name = arguments.first
workflow_queue_url = AppSettings[:"#{workflow_name.underscore}_queue_url"]
workflow_queue_url.present? ? self.class.parse_queue_name(workflow_queue_url) : self.class.default_queue_name
end
def perform(workflow_name... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/jobs/scheduled_job.rb | Ruby | mit | 47 | develop | 1,501 | class ScheduledJob < ApplicationJob
queue_as AppSettings.fetch(:aws_sqs_high_priority_queue_name)
def perform
Account.find_each do |account|
queue_delivery_attempts(account)
end
update_delivery_attempts
complete_broadcasts
end
private
def queue_delivery_attempts(account)
delivery... |
github | open-ews/open-ews | https://github.com/open-ews/open-ews | app/jobs/initiate_delivery_attempt_job.rb | Ruby | mit | 47 | develop | 3,048 | class InitiateDeliveryAttemptJob < ApplicationJob
class Handler
class AudioNotAttachedError < StandardError; end
attr_reader :delivery_attempt, :somleng_client, :twiml_builder
def initialize(delivery_attempt, **options)
@delivery_attempt = delivery_attempt
@somleng_client = options.fetch(:so... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.