Class: Hackpad::Migration::Migrator
- Inherits:
-
Object
- Object
- Hackpad::Migration::Migrator
- Defined in:
- lib/hackpad/migration/migrator.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(last_result) ⇒ Migrator
constructor
A new instance of Migrator.
- #migrate ⇒ Object
Constructor Details
#initialize(last_result) ⇒ Migrator
Returns a new instance of Migrator.
5 6 7 8 9 10 |
# File 'lib/hackpad/migration/migrator.rb', line 5 def initialize(last_result) = last_result. @source = API.new(['source_site'], ['source_client_id'], ['source_secret']) @target = API.new(['target_site'], ['target_client_id'], ['target_secret']) @result = last_result end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
4 5 6 |
# File 'lib/hackpad/migration/migrator.rb', line 4 def result @result end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
4 5 6 |
# File 'lib/hackpad/migration/migrator.rb', line 4 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
4 5 6 |
# File 'lib/hackpad/migration/migrator.rb', line 4 def target @target end |
Instance Method Details
#migrate ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/hackpad/migration/migrator.rb', line 12 def migrate source.list.each do |source_pid| body = source.get(source_pid) # pad {"padId"=>"RAtutOXxMGF1", "globalPadId"=>"2$RAtutOXxMGF1"} target_pid = result.source_and_target_map[source_pid] if target_pid.nil? pad = target.create(body) result.add_source_and_target(source_pid, pad['padId']) puts "created pad #{pad['padId']} from source pad #{source_pid}" result.write! else puts "Updating pad #{target_pid} from source pad #{source_pid}" pad = target.update(target_pid, body) end end end |