Class: Woods::Chunking::ModelChunker Private

Inherits:
Object
  • Object
show all
Includes:
ChunkBuilder
Defined in:
lib/woods/chunking/semantic_chunker.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Chunks a model unit by semantic sections: summary, associations, validations, callbacks, scopes, methods.

Constant Summary collapse

ASSOCIATION_PATTERN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/^\s*(has_many|has_one|belongs_to|has_and_belongs_to_many)\b/
VALIDATION_PATTERN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/^\s*validates?\b/
CALLBACK_ACTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'(save|create|update|destroy|validation|action|commit|rollback|find|initialize|touch)'
CALLBACK_PATTERN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/^\s*(before_|after_|around_)#{CALLBACK_ACTIONS}\b/
SCOPE_PATTERN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

/^\s*scope\s+:/
SECTION_PATTERNS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  associations: ASSOCIATION_PATTERN,
  validations: VALIDATION_PATTERN,
  callbacks: CALLBACK_PATTERN,
  scopes: SCOPE_PATTERN
}.freeze
SEMANTIC_SECTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%i[associations validations callbacks scopes].freeze

Instance Method Summary collapse

Constructor Details

#initialize(unit) ⇒ ModelChunker

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ModelChunker.

Parameters:



318
319
320
# File 'lib/woods/chunking/semantic_chunker.rb', line 318

def initialize(unit)
  @unit = unit
end

Instance Method Details

#chunkArray<Chunk>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



323
324
325
326
# File 'lib/woods/chunking/semantic_chunker.rb', line 323

def chunk
  sections = classify_lines(@unit.source_code.lines)
  build_chunks(sections).reject(&:empty?)
end