Class: Hackpad::Migration::Result
- Inherits:
-
Object
- Object
- Hackpad::Migration::Result
- Defined in:
- lib/hackpad/migration/result.rb
Instance Method Summary collapse
- #add_source_and_target(source, target) ⇒ Object
- #add_user_option(key, vlaue) ⇒ Object
-
#initialize(out_file) ⇒ Result
constructor
A new instance of Result.
- #result ⇒ Object
- #source_and_target_map ⇒ Object
- #to_json ⇒ Object
- #user_options ⇒ Object
- #write! ⇒ Object
Constructor Details
#initialize(out_file) ⇒ Result
Returns a new instance of Result.
4 5 6 |
# File 'lib/hackpad/migration/result.rb', line 4 def initialize(out_file) @out_file = out_file end |
Instance Method Details
#add_source_and_target(source, target) ⇒ Object
30 31 32 |
# File 'lib/hackpad/migration/result.rb', line 30 def add_source_and_target(source, target) source_and_target_map[source] = target end |
#add_user_option(key, vlaue) ⇒ Object
26 27 28 |
# File 'lib/hackpad/migration/result.rb', line 26 def add_user_option(key, vlaue) [key] = value end |
#result ⇒ Object
8 9 10 |
# File 'lib/hackpad/migration/result.rb', line 8 def result @result ||= File.exist?(@out_file) ? JSON.parse(open(@out_file).read) : {} end |
#source_and_target_map ⇒ Object
22 23 24 |
# File 'lib/hackpad/migration/result.rb', line 22 def source_and_target_map @source_and_target_map ||= result['source_and_target_map'] || {} end |
#to_json ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/hackpad/migration/result.rb', line 34 def to_json JSON.pretty_generate( user_options: , source_and_target_map: source_and_target_map, updated_at: Time.now ) end |
#user_options ⇒ Object
18 19 20 |
# File 'lib/hackpad/migration/result.rb', line 18 def @user_options ||= result['user_options'] || {} end |
#write! ⇒ Object
12 13 14 15 16 |
# File 'lib/hackpad/migration/result.rb', line 12 def write! open(@out_file, 'w+') do |f| f.write(to_json) end end |