Class: Stepmod::Utils::Change
- Inherits:
-
Object
- Object
- Stepmod::Utils::Change
- 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: "changes", mapping_table: "mapping", }.freeze
- TYPES_WITHOUT_EXTENSION =
%w[ changes mapping_table ].freeze
Instance Attribute Summary collapse
-
#change_editions ⇒ Object
readonly
Returns the value of attribute change_editions.
-
#mapping_table ⇒ Object
Returns the value of attribute mapping_table.
-
#schema_name ⇒ Object
Returns the value of attribute schema_name.
Instance Method Summary collapse
- #add_change_edition(change_edition) ⇒ Object
- #fetch_change_edition(version) ⇒ Object (also: #[])
-
#initialize(stepmod_dir:, schema_name:, type:) ⇒ Change
constructor
A new instance of Change.
- #module? ⇒ Boolean
- #resource? ⇒ Boolean
- #save_to_file ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(stepmod_dir:, schema_name:, type:) ⇒ Change
Returns a new instance of Change.
26 27 28 29 30 31 32 |
# File 'lib/stepmod/utils/change.rb', line 26 def initialize(stepmod_dir:, schema_name:, type:) @stepmod_dir = stepmod_dir @change_editions = Stepmod::Utils::ChangeEditionCollection.new @mapping_table = {} @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 |
#mapping_table ⇒ Object
Returns the value of attribute mapping_table.
8 9 10 |
# File 'lib/stepmod/utils/change.rb', line 8 def mapping_table @mapping_table 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
42 43 44 |
# File 'lib/stepmod/utils/change.rb', line 42 def add_change_edition(change_edition) @change_editions[change_edition[:version]] = change_edition end |
#fetch_change_edition(version) ⇒ Object Also known as: []
46 47 48 |
# File 'lib/stepmod/utils/change.rb', line 46 def fetch_change_edition(version) @change_editions[version] end |
#module? ⇒ Boolean
38 39 40 |
# File 'lib/stepmod/utils/change.rb', line 38 def module? MODULE_TYPES.key?(@type.to_sym) || MODULE_TYPES.value?(@type.to_s) end |
#resource? ⇒ Boolean
34 35 36 |
# File 'lib/stepmod/utils/change.rb', line 34 def resource? !module? end |
#save_to_file ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/stepmod/utils/change.rb', line 51 def save_to_file change_hash = if @type == "mapping_table" @mapping_table else to_h end return if change_hash.empty? File.write(filepath(@type), Psych.dump(stringify_keys(change_hash))) end |
#to_h ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/stepmod/utils/change.rb', line 62 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 |