Class: RbsDraper::Decorator::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs_draper/decorator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, rbs_builder, decorated_class: nil) ⇒ Generator

Returns a new instance of Generator.



15
16
17
18
19
20
# File 'lib/rbs_draper/decorator.rb', line 15

def initialize(klass, rbs_builder, decorated_class: nil)
  @klass = klass
  @klass_name = klass.name || ""
  @rbs_builder = rbs_builder
  @decorated_class = decorated_class
end

Instance Attribute Details

#decorated_classObject (readonly)

Returns the value of attribute decorated_class.



13
14
15
# File 'lib/rbs_draper/decorator.rb', line 13

def decorated_class
  @decorated_class
end

#klassObject (readonly)

Returns the value of attribute klass.



13
14
15
# File 'lib/rbs_draper/decorator.rb', line 13

def klass
  @klass
end

#klass_nameObject (readonly)

Returns the value of attribute klass_name.



13
14
15
# File 'lib/rbs_draper/decorator.rb', line 13

def klass_name
  @klass_name
end

#rbs_builderObject (readonly)

Returns the value of attribute rbs_builder.



13
14
15
# File 'lib/rbs_draper/decorator.rb', line 13

def rbs_builder
  @rbs_builder
end

Instance Method Details

#generateObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rbs_draper/decorator.rb', line 22

def generate
  return if decorated_class_def.blank?

  format <<~RBS
    #{header}
    #{mixin_decls}
    #{class_method_decls}
    #{object_method_decls}

    #{method_decls}
    #{footer}
  RBS
end