Class: RbsActivemodel::ActiveModel::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs_activemodel/active_model.rb

Constant Summary collapse

MIXINS =
[::ActiveModel::Model, ::ActiveModel::Attributes,
::ActiveModel::SecurePassword, ::ActiveModel::Validations].freeze
TYPES =
{
  big_integer: Integer,
  binary: String,
  boolean: :bool,
  date: Date,
  datetime: "DateTime | ActiveSupport::TimeWithZone",
  decimal: BigDecimal,
  float: Float,
  immutable_string: String,
  integer: Integer,
  string: String,
  time: Time
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Generator

Returns a new instance of Generator.



40
41
42
43
# File 'lib/rbs_activemodel/active_model.rb', line 40

def initialize(klass)
  @klass = klass
  @klass_name = klass.name || ""
end

Instance Method Details

#generateObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rbs_activemodel/active_model.rb', line 45

def generate
  return if mixins.empty? && secure_password.empty? && attributes.empty?

  format <<~RBS
    #{header}
    #{mixins}

    #{secure_password}

    #{attributes}
    #{footer}
  RBS
end