Class: WhyClasses::Correctors::DataBucketCorrector::Analysis

Inherits:
Data
  • Object
show all
Defined in:
lib/why_classes/correctors/data_bucket_corrector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields

Returns:

  • (Object)

    the current value of fields



15
16
17
# File 'lib/why_classes/correctors/data_bucket_corrector.rb', line 15

def fields
  @fields
end

#keywordObject (readonly)

Returns the value of attribute keyword

Returns:

  • (Object)

    the current value of keyword



15
16
17
# File 'lib/why_classes/correctors/data_bucket_corrector.rb', line 15

def keyword
  @keyword
end

#kindObject (readonly)

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



15
16
17
# File 'lib/why_classes/correctors/data_bucket_corrector.rb', line 15

def kind
  @kind
end

Instance Method Details

#replacement(name) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/why_classes/correctors/data_bucket_corrector.rb', line 16

def replacement(name)
  list = fields.map { |f| ":#{f}" }.join(", ")
  case kind
  when :data
    "#{name} = Data.define(#{list})"
  when :struct
    keyword ? "#{name} = Struct.new(#{list}, keyword_init: true)" : "#{name} = Struct.new(#{list})"
  end
end