Class: Tapioca::Compilers::Dsl::ActiveResource

Inherits:
Base
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/tapioca/compilers/dsl/active_resource.rb

Overview

`Tapioca::Compilers::Dsl::ActiveResource` decorates RBI files for subclasses of [`ActiveResource::Base`](github.com/rails/activeresource) which declare `schema` fields.

For example, with the following `ActiveResource::Base` subclass:

~~~rb class Post < ActiveResource::Base

schema do
  integer 'id', 'month', 'year'
end

end ~~~

this generator will produce the RBI file `post.rbi` with the following content:

~~~rbi # post.rbi # typed: true class Post

sig { returns(Integer) }
def id; end

sig { params(id: Integer).returns(Integer) }
def id=(id); end

sig { returns(T::Boolean) }
def id?; end

sig { returns(Integer) }
def month; end

sig { params(month: Integer).returns(Integer) }
def month=(month); end

sig { returns(T::Boolean) }
def month?; end

sig { returns(Integer) }
def year; end

sig { params(year: Integer).returns(Integer) }
def year=(year); end

sig { returns(T::Boolean) }
def year?; end

end ~~~

Constant Summary

Constants included from Reflection

Reflection::ANCESTORS_METHOD, Reflection::CLASS_METHOD, Reflection::CONSTANTS_METHOD, Reflection::EQUAL_METHOD, Reflection::METHOD_METHOD, Reflection::NAME_METHOD, Reflection::OBJECT_ID_METHOD, Reflection::PRIVATE_INSTANCE_METHODS_METHOD, Reflection::PROTECTED_INSTANCE_METHODS_METHOD, Reflection::PUBLIC_INSTANCE_METHODS_METHOD, Reflection::SINGLETON_CLASS_METHOD, Reflection::SUPERCLASS_METHOD

Instance Attribute Summary

Attributes inherited from Base

#errors, #processable_constants

Instance Method Summary collapse

Methods inherited from Base

#add_error, #handles?, #initialize

Methods included from Reflection

#ancestors_of, #are_equal?, #class_of, #constants_of, #descendants_of, #inherited_ancestors_of, #method_of, #name_of, #name_of_type, #object_id_of, #private_instance_methods_of, #protected_instance_methods_of, #public_instance_methods_of, #qualified_name_of, #signature_of, #singleton_class_of, #superclass_of

Constructor Details

This class inherits a constructor from Tapioca::Compilers::Dsl::Base

Instance Method Details

#decorate(root, constant) ⇒ Object


65
66
67
68
69
70
71
72
73
# File 'lib/tapioca/compilers/dsl/active_resource.rb', line 65

def decorate(root, constant)
  return if constant.schema.blank?

  root.create_path(constant) do |resource|
    constant.schema.each do |attribute, type|
      create_schema_methods(resource, attribute, type)
    end
  end
end

#gather_constantsObject


76
77
78
# File 'lib/tapioca/compilers/dsl/active_resource.rb', line 76

def gather_constants
  descendants_of(::ActiveResource::Base)
end