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

feat(model): Introduce poro model plugin #9

Merged
merged 1 commit into from
Sep 30, 2024
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
1 change: 1 addition & 0 deletions lib/typelizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
require_relative "typelizer/serializer_plugins/ams"

require_relative "typelizer/model_plugins/active_record"
require_relative "typelizer/model_plugins/poro"

require_relative "typelizer/railtie" if defined?(Rails)

Expand Down
13 changes: 13 additions & 0 deletions lib/typelizer/model_plugins/poro.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Typelizer
module ModelPlugins
class Poro
# We don't care about intialization
def initialize(...)
end

def infer_types(prop)
prop
end
end
end
end
10 changes: 10 additions & 0 deletions spec/__snapshots__/AlbaPoro.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Typelizer digest 3c3acd1390157d9666f0f2be46bfcb1c
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.

type AlbaPoro = {
foo: unknown;
bar: string | null;
}

export default AlbaPoro;
3 changes: 2 additions & 1 deletion spec/__snapshots__/index.ts.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Typelizer digest 57b8f7cafc55a420da0bed2b12cadf83
// Typelizer digest b11065c38d475f7104b4d09c6ee44a31
//
// DO NOT MODIFY: This file was automatically generated by Typelizer.
export type { default as AlbaInline } from './AlbaInline'
export type { default as AlbaMetaNil } from './AlbaMetaNil'
export type { default as AlbaMeta } from './AlbaMeta'
export type { default as AlbaPoro } from './AlbaPoro'
export type { default as AlbaPost } from './AlbaPost'
export type { default as AlbaUserAuthor } from './AlbaUserAuthor'
export type { default as AlbaUser } from './AlbaUser'
Expand Down
9 changes: 9 additions & 0 deletions spec/app/app/models/poro.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Poro
def foo
"This is foo method"
end

def as_json
{foo: foo}
end
end
15 changes: 15 additions & 0 deletions spec/app/app/serializers/alba/poro_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Alba
class PoroSerializer
include Alba::Serializer
include Typelizer::DSL

typelize_from :poro

typelizer_config do |c|
# This is required
c.model_plugin = Typelizer::ModelPlugins::Poro
end

attributes :foo, bar: :String
end
end
Loading