Class: Stepmod::Utils::Change

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

Constant Summary collapse

MODULE_TYPES =
{
  arm: "arm",
  mim: "mim",
  arm_longform: "arm_lf",
  mim_longform: "mim_lf",
  mapping: "mapping",
  changes: "",
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stepmod_dir:, schema_name:, type:) ⇒ Change

Returns a new instance of Change.



20
21
22
23
24
25
# File 'lib/stepmod/utils/change.rb', line 20

def initialize(stepmod_dir:, schema_name:, type:)
  @stepmod_dir = stepmod_dir
  @change_editions = Stepmod::Utils::ChangeEditionCollection.new
  @schema_name = schema_name
  @type = type
end

Instance Attribute Details

#change_editions ⇒ Object (readonly)

Returns the value of attribute change_editions.



9
10
11
# File 'lib/stepmod/utils/change.rb', line 9

def change_editions
  @change_editions
end

#schema_name ⇒ Object

Returns the value of attribute schema_name.



8
9
10
# File 'lib/stepmod/utils/change.rb', line 8

def schema_name
  @schema_name
end

Instance Method Details

#add_change_edition(change_edition) ⇒ Object



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

def add_change_edition(change_edition)
  @change_editions[change_edition[:version]] = change_edition
end

#fetch_change_edition(version) ⇒ Object Also known as: []



39
40
41
# File 'lib/stepmod/utils/change.rb', line 39

def fetch_change_edition(version)
  @change_editions[version]
end

#module? ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/stepmod/utils/change.rb', line 31

def module?
  MODULE_TYPES.key?(@type.to_sym) || MODULE_TYPES.value?(@type.to_s)
end

#resource? ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/stepmod/utils/change.rb', line 27

def resource?
  !module?
end

#save_to_file ⇒ Object



44
45
46
47
48
49
# File 'lib/stepmod/utils/change.rb', line 44

def save_to_file
  change_hash = to_h
  return if change_hash.empty?

  File.write(filepath(@type), Psych.dump(change_hash))
end

#to_h ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/stepmod/utils/change.rb', line 51

def to_h
  change_editions_list = change_editions.to_h

  return {} if change_editions_list.empty?

  {
    "schema" => schema_name,
    "change_edition" => change_editions_list,
  }
end