Class: Hackpad::Migration::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/hackpad/migration/result.rb

Instance Method Summary collapse

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)
  user_options[key] = value
end

#resultObject



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_mapObject



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_jsonObject



34
35
36
37
38
39
40
# File 'lib/hackpad/migration/result.rb', line 34

def to_json
  JSON.pretty_generate(
    user_options: user_options,
    source_and_target_map: source_and_target_map,
    updated_at: Time.now
  )
end

#user_optionsObject



18
19
20
# File 'lib/hackpad/migration/result.rb', line 18

def user_options
  @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