Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace squema with easy_talk gem for convert active record… #82

Merged
merged 1 commit into from
Mar 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ PATH
remote: .
specs:
oas_rails (0.9.0)
easy_talk (~> 1.0)
method_source (~> 1.0)
model-to-schema (~> 0.1.2)
yard (~> 0.9)

GEM
Expand Down Expand Up @@ -94,6 +94,10 @@ GEM
irb (~> 1.10)
reline (>= 0.3.8)
drb (2.2.1)
easy_talk (1.0.4)
activemodel (>= 7.0)
activesupport (>= 7.0)
sorbet-runtime (>= 0.5)
erubi (1.13.1)
factory_bot (6.5.1)
activesupport (>= 6.1.0)
Expand Down Expand Up @@ -130,7 +134,6 @@ GEM
mini_mime (1.1.5)
mini_portile2 (2.8.8)
minitest (5.25.5)
model-to-schema (0.1.2)
net-imap (0.5.6)
date
net-protocol
Expand Down Expand Up @@ -228,6 +231,7 @@ GEM
parser (>= 3.3.7.2)
ruby-progressbar (1.13.0)
securerandom (0.4.1)
sorbet-runtime (0.5.11953)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails-7.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem 'rails', '~> 7.0.0'

gem 'model-to-schema', '~> 0.1.2'
gem 'easy_talk', '~> 1.0'

gem 'method_source', '~> 1.0'

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails-7.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem 'rails', '~> 7.1.0'

gem 'model-to-schema', '~> 0.1.2'
gem 'easy_talk', '~> 1.0'

gem 'method_source', '~> 1.0'

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails-7.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem 'rails', '~> 7.2.0'

gem 'model-to-schema', '~> 0.1.2'
gem 'easy_talk', '~> 1.0'

gem 'method_source', '~> 1.0'

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails-8.0.0-beta1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem 'rails', '~> 8.0.0.beta1'

gem 'model-to-schema', '~> 0.1.2'
gem 'easy_talk', '~> 1.0'

gem 'method_source', '~> 1.0'

Expand Down
2 changes: 1 addition & 1 deletion lib/oas_rails.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "yard"
require "method_source"
require "esquema"
require "easy_talk"

module OasRails
require "oas_rails/version"
Expand Down
19 changes: 10 additions & 9 deletions lib/oas_rails/builders/esquema_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,33 @@ class << self
#
# @param klass [Class] The class for which the schema is built.
# @return [Hash] The schema as a JSON-compatible hash.
def build_incoming_schema(klass:, model_to_schema_class: Esquema)
configure_common_settings
def build_incoming_schema(klass:, model_to_schema_class: EasyTalk)
configure_common_settings(model_to_schema_class:)
model_to_schema_class.configuration.excluded_columns = OasRails.config.excluded_columns_incoming

model_to_schema_class::Builder.new(klass).build_schema.as_json
model_to_schema_class::ActiveRecordSchemaBuilder.new(klass).build_schema_definition.as_json["schema"]
end

# Builds a schema for a class when it is used as outgoing API data.
#
# @param klass [Class] The class for which the schema is built.
# @return [Hash] The schema as a JSON-compatible hash.
def build_outgoing_schema(klass:, model_to_schema_class: Esquema)
configure_common_settings
def build_outgoing_schema(klass:, model_to_schema_class: EasyTalk)
configure_common_settings(model_to_schema_class:)
model_to_schema_class.configuration.excluded_columns = OasRails.config.excluded_columns_outgoing
model_to_schema_class.configuration.exclude_primary_key = false

model_to_schema_class::Builder.new(klass).build_schema.as_json
model_to_schema_class::ActiveRecordSchemaBuilder.new(klass).build_schema_definition.as_json["schema"]
end

private

# Configures common settings for schema building.
#
# Excludes associations and foreign keys from the schema.
def configure_common_settings
Esquema.configuration.exclude_associations = true
Esquema.configuration.exclude_foreign_keys = true
def configure_common_settings(model_to_schema_class: EasyTalk)
model_to_schema_class.configuration.exclude_associations = true
model_to_schema_class.configuration.exclude_foreign_keys = true
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion oas_rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = ">= 3.1"

spec.add_dependency 'easy_talk', '~> 1.0'
spec.add_dependency 'method_source', '~> 1.0'
spec.add_dependency 'model-to-schema', '~> 0.1.2' # Esquema
spec.add_dependency 'yard', '~> 0.9'
end