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",
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Change.



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

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_editionsObject (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_nameObject

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



33
34
35
# File 'lib/stepmod/utils/change.rb', line 33

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

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



37
38
39
# File 'lib/stepmod/utils/change.rb', line 37

def fetch_change_edition(version)
  @change_editions[version]
end

#module?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/stepmod/utils/change.rb', line 29

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

#resource?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/stepmod/utils/change.rb', line 25

def resource?
  !module?
end

#save_to_fileObject



42
43
44
# File 'lib/stepmod/utils/change.rb', line 42

def save_to_file
  File.write(filepath(@type), Psych.dump(to_h))
end

#to_hObject



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

def to_h
  {
    "schema" => schema_name,
    "change_edition" => change_editions.to_h,
  }
end