Skip to content

Commit

Permalink
chore: clean up factorial classes, use tapioca and auto formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobobq committed Nov 15, 2024
1 parent 5af1a59 commit 17f0421
Show file tree
Hide file tree
Showing 93 changed files with 70,438 additions and 18,695 deletions.
21 changes: 11 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

gem 'activesupport'
gem 'rspec'
gem 'rspec-json_expectations', require: true
gem 'rspec-sorbet', '~> 1.9.2'
gem 'sorbet-coerce', '>= 0.2.6'
gem 'sorbet-static-and-runtime', '>= 0.5.11609'
gem 'tapioca', '~> 0.15.1', require: false
gem "activesupport"
gem "rspec"
gem "rspec-json_expectations"
gem "rspec-sorbet", "~> 1.9.2"
gem "sorbet-coerce", ">= 0.2.6"
gem "sorbet-static-and-runtime", ">= 0.5.11609"
gem "tapioca", "~> 0.15.1", require: false
gem "syntax_tree", "~> 6.2", require: false

gem 'guard'
gem 'guard-rspec'
gem "guard"
gem "guard-rspec"
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ GEM
shellany (~> 0.0)
parallel (1.23.0)
polyfill (1.9.0)
prettier_print (1.2.1)
prism (0.30.0)
pry (0.14.2)
coderay (~> 1.1)
Expand Down Expand Up @@ -101,6 +102,8 @@ GEM
prism (>= 0.28.0)
sorbet-static-and-runtime (>= 0.5.10187)
thor (>= 0.19.2)
syntax_tree (6.2.0)
prettier_print (>= 1.2.0)
tapioca (0.15.1)
bundler (>= 2.2.25)
netrc (>= 0.11.0)
Expand Down Expand Up @@ -131,6 +134,7 @@ DEPENDENCIES
rspec-sorbet (~> 1.9.2)
sorbet-coerce (>= 0.2.6)
sorbet-static-and-runtime (>= 0.5.11609)
syntax_tree (~> 6.2)
tapioca (~> 0.15.1)

BUNDLED WITH
Expand Down
6 changes: 4 additions & 2 deletions lib/public/capabilities/capability_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ module ClassMethods

# The key of the capability, this key will be used to take it from yaml configuration
sig { abstract.returns(Symbol) }
def key; end
def key
end
end

requires_ancestor { Object }

mixes_in_class_methods(ClassMethods)

sig { abstract.returns(T::Hash[String, T.untyped]) }
def serialize; end
def serialize
end
end
end
end
24 changes: 19 additions & 5 deletions lib/public/capability_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,33 @@ class CapabilityFactory
sig do
params(
data: T::Hash[String, T.untyped],
capabilities: T::Hash[Symbol, T.all(T::Class[Capabilities::CapabilityConfig], T.class_of(T::Struct))]
capabilities:
T::Hash[
Symbol,
T.all(
T::Class[Capabilities::CapabilityConfig],
T.class_of(T::Struct)
)
]
).returns(Capabilities::CapabilityConfig)
end
def self.load(data, capabilities: ResourceRegistry.configuration.capabilities)
key = data['key']
def self.load(
data,
capabilities: ResourceRegistry.configuration.capabilities
)
key = data["key"]
capability = capabilities.fetch(key.to_sym)
# FIXME: This T.let should not be needed
T.let(capability, T.class_of(T::Struct)).from_hash(data)
end

sig { params(capability: Capabilities::CapabilityConfig).returns(T::Hash[String, T.untyped]) }
sig do
params(capability: Capabilities::CapabilityConfig).returns(
T::Hash[String, T.untyped]
)
end
def self.dump(capability)
{ 'key' => capability.class.key }.merge!(capability.serialize)
{ "key" => capability.class.key }.merge!(capability.serialize)
end
end
end
28 changes: 18 additions & 10 deletions lib/public/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# frozen_string_literal: true
# typed: true

require_relative 'relationship_types/has_many'
require_relative 'relationship_types/has_many_through'
require_relative 'relationship_types/has_one'
require_relative 'relationship_types/belongs_to'
require_relative "relationship_types/has_many"
require_relative "relationship_types/has_many_through"
require_relative "relationship_types/has_one"
require_relative "relationship_types/belongs_to"

module ResourceRegistry
class Configuration
extend T::Sig

DEFAULT_RELATIONSHIP_TYPES = {
'has_many_through' => RelationshipTypes::HasManyThrough,
'has_many' => RelationshipTypes::HasMany,
'has_one' => RelationshipTypes::HasOne,
'belongs_to' => RelationshipTypes::BelongsTo
"has_many_through" => RelationshipTypes::HasManyThrough,
"has_many" => RelationshipTypes::HasMany,
"has_one" => RelationshipTypes::HasOne,
"belongs_to" => RelationshipTypes::BelongsTo
}.freeze

sig { void }
Expand All @@ -28,7 +28,12 @@ def register_relationship_type(type, klass)
@relationship_types[type] = klass
end

sig { params(capability: Symbol, klass: T.class_of(Capabilities::CapabilityConfig)).void }
sig do
params(
capability: Symbol,
klass: T.class_of(Capabilities::CapabilityConfig)
).void
end
def register_capability(capability, klass)
@capabilities[capability] = klass
end
Expand All @@ -38,7 +43,10 @@ def register_capability(capability, klass)

sig do
returns(
T::Hash[Symbol, T.all(T::Class[Capabilities::CapabilityConfig], T.class_of(T::Struct))]
T::Hash[
Symbol,
T.all(T::Class[Capabilities::CapabilityConfig], T.class_of(T::Struct))
]
)
end
attr_reader :capabilities
Expand Down
68 changes: 0 additions & 68 deletions lib/public/context_creator.rb

This file was deleted.

16 changes: 0 additions & 16 deletions lib/public/dtos/context.rb

This file was deleted.

10 changes: 0 additions & 10 deletions lib/public/dtos/sort.rb

This file was deleted.

4 changes: 3 additions & 1 deletion lib/public/entity_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ class EntityFinder
extend T::Sig

sig do
params(repository: T.class_of(Repositories::Base)).returns(T.nilable(T.class_of(T::Struct)))
params(repository: T.class_of(Repositories::Base)).returns(
T.nilable(T.class_of(T::Struct))
)
end
def self.call(repository:)
entity = repository.entity
Expand Down
109 changes: 0 additions & 109 deletions lib/public/i18n_keys_for_resource.rb

This file was deleted.

Loading

0 comments on commit 17f0421

Please sign in to comment.