Skip to content

Commit

Permalink
feat(model): Introduce poro model plugin
Browse files Browse the repository at this point in the history
This model plugin would be used in serializers for PORO.
It's implementation is empty but it works as expected.
See spec/app/app/serializers/alba/poro_serializer.rb for details.
  • Loading branch information
okuramasafumi committed Sep 30, 2024
1 parent 0b0015a commit e8672c7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 1 deletion.
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

0 comments on commit e8672c7

Please sign in to comment.