Class: Stepmod::Utils::ChangeCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/stepmod/utils/change_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(stepmod_dir:) ⇒ ChangeCollection

Returns a new instance of ChangeCollection.



6
7
8
9
# File 'lib/stepmod/utils/change_collection.rb', line 6

def initialize(stepmod_dir:)
  @stepmod_dir = stepmod_dir
  @changes = {}
end

Instance Method Details

#countObject Also known as: size



30
31
32
# File 'lib/stepmod/utils/change_collection.rb', line 30

def count
  @changes.keys.count
end

#each(&block) ⇒ Object



35
36
37
# File 'lib/stepmod/utils/change_collection.rb', line 35

def each(&block)
  @changes.values.each(&block)
end

#fetch(change, type) ⇒ Object



21
22
23
24
# File 'lib/stepmod/utils/change_collection.rb', line 21

def fetch(change, type)
  schema = schema_name(change)
  @changes[schema_identifier(schema, type)]
end

#fetch_or_initialize(change, type) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/stepmod/utils/change_collection.rb', line 11

def fetch_or_initialize(change, type)
  schema = schema_name(change)

  @changes[schema_identifier(schema, type)] ||= Change.new(
    type: type,
    stepmod_dir: @stepmod_dir,
    schema_name: schema,
  )
end

#save_to_filesObject



26
27
28
# File 'lib/stepmod/utils/change_collection.rb', line 26

def save_to_files
  @changes.values.each(&:save_to_file)
end