Skip to content

Commit

Permalink
Fix signetures for ActiveModelSerializers
Browse files Browse the repository at this point in the history
  • Loading branch information
sinsoku committed Oct 3, 2024
1 parent f5f878b commit 2640188
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion gems/active_model_serializers/0.10/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Tag < ActiveModelSerializers::Model
end

class ArticleSerializer < ActiveModel::Serializer
attribute :title
attribute :title, key: :name
attributes :body, :tag_names

Expand All @@ -21,7 +22,12 @@ def tag_names
end

resource = Article.new(title: "Hello", body: "World", tags: [Tag.new(name: "foo"), Tag.new(name: "bar")])
serialization = ActiveModelSerializers::SerializableResource.new(resource, serializer: ArticleSerializer)
ArticleSerializer.new(resource).as_json

serialization = ActiveModelSerializers::SerializableResource.new(resource)
serialization.to_json
serialization.as_json

serialization_json = ActiveModelSerializers::SerializableResource.new(resource, adapter: :json)
serialization_json.to_json
end
4 changes: 2 additions & 2 deletions gems/active_model_serializers/0.10/active_model.rbs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module ActiveModel
class Serializer[T]
def self.attributes: (*Symbol attrs) -> void
def self.attribute: (Symbol attr, Hash[Symbol, untyped] options) ?{ () -> untyped } -> void
def self.attribute: (Symbol attr, ?Hash[Symbol, untyped] options) ?{ () -> untyped } -> void

attr_accessor object: T
attr_accessor root: untyped
attr_accessor scope: untyped

def initialize: (T object, Hash[Symbol, untyped] options) -> void
def initialize: (T object, ?Hash[Symbol, untyped] options) -> void
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module ActiveModelSerializers
end

class SerializableResource
def initialize: (untyped resource, Hash[Symbol, untyped] options) -> void
def initialize: (untyped resource, ?Hash[Symbol, untyped] options) -> void
def to_json: -> String
def as_json: -> Hash[Symbol, untyped]
end
Expand Down

0 comments on commit 2640188

Please sign in to comment.