Class: EmergeCLI::Commands::Reaper::DeadCodeResult

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/reaper/reaper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ DeadCodeResult

Returns a new instance of DeadCodeResult.



155
156
157
158
159
160
# File 'lib/commands/reaper/reaper.rb', line 155

def initialize(data)
  @metadata = data['metadata']
  @dead_code = data['dead_code']
  @counts = data['counts']
  @pagination = data['pagination']
end

Instance Attribute Details

#countsObject (readonly)

Returns the value of attribute counts.



153
154
155
# File 'lib/commands/reaper/reaper.rb', line 153

def counts
  @counts
end

#dead_codeObject (readonly)

Returns the value of attribute dead_code.



153
154
155
# File 'lib/commands/reaper/reaper.rb', line 153

def dead_code
  @dead_code
end

#metadataObject (readonly)

Returns the value of attribute metadata.



153
154
155
# File 'lib/commands/reaper/reaper.rb', line 153

def 
  @metadata
end

#paginationObject (readonly)

Returns the value of attribute pagination.



153
154
155
# File 'lib/commands/reaper/reaper.rb', line 153

def pagination
  @pagination
end

Instance Method Details

#filtered_unseen_classesObject



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/commands/reaper/reaper.rb', line 162

def filtered_unseen_classes
  @filtered_unseen_classes ||= dead_code
                               .reject { |item| item['seen'] }
                               .reject do |item|
    paths = item['paths']
    next false if paths.nil? || paths.empty?

    next true if paths.any? do |path|
      path.include?('/SourcePackages/checkouts/') ||
      path.include?('/Pods/') ||
      path.include?('/Carthage/') ||
      path.include?('/Vendor/') ||
      path.include?('/Sources/') ||
      path.include?('/DerivedSources/')
    end

    next false if paths.none? do |path|
      path.end_with?('.swift', '.java', '.kt')
    end
  end
end

#to_sObject



184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/commands/reaper/reaper.rb', line 184

def to_s
  <<~SUMMARY.yellow

    Dead Code Analysis Results:
    App ID: #{@metadata['app_id']}
    App Version: #{@metadata['version']}
    Platform: #{@metadata['platform']}

    Statistics:
    - Total User Sessions: #{@counts['user_sessions']}
    - Seen Classes: #{@counts['seen_classes']}
    - Unseen Classes: #{@counts['unseen_classes']}
  SUMMARY
end