lib/doggy/cli/edit.rb in doggy-2.1.1 vs lib/doggy/cli/edit.rb in doggy-3.0.0.pre.beta1
- old
+ new
@@ -1,6 +1,5 @@
-# encoding: utf-8
# frozen_string_literal: true
module Doggy
class CLI::Edit
def initialize(options, param)
@@ -21,12 +20,10 @@
if new_resource.is_a?(Doggy::Models::Dashboard)
new_resource.title = resource.title
new_resource.description = resource.description
elsif new_resource.is_a?(Doggy::Models::Monitor)
new_resource.name = resource.name
- elsif new_resource.is_a?(Doggy::Models::Screen)
- new_resource.board_title = resource.board_title
end
new_resource.path = resource.path
new_resource.save_local
forked_resource.destroy
@@ -37,23 +34,21 @@
def wait_for_edit
Doggy.ui.say("run, rabbit run / dig that hole, forget the sun / and when at last the work is done / don't sit down / it's time to dig another one") until Doggy.ui.yes?('Are you done editing?(Y/N)')
end
def fork(resource)
- salt = Doggy.random_word
- forked_resource = resource.dup
- forked_resource.id = nil
+ forked_resource = resource.class.new(resource.attributes.except("id")) # TODO: Except "url" too
+ forked_resource.path = resource.path # TODO: should not be forked
forked_resource.refute_read_only!
+
if /dashboard/.match?(resource.class.to_s.downcase)
- forked_resource.title = "[#{salt}] " + forked_resource.title
- forked_resource.description = "[fork of #{resource.id}] " + forked_resource.title
- elsif /screen/.match?(resource.class.to_s.downcase)
- forked_resource.board_title = "[#{salt}] " + forked_resource.board_title
+ forked_resource.title = "[#{Doggy.random_word}] #{resource.title}"
elsif /monitor/.match?(resource.class.to_s.downcase)
- forked_resource.name = "[#{salt}] " + forked_resource.name
+ forked_resource.name = "[#{Doggy.random_word}] #{resource.name}"
else
raise StandardError, 'Unknown resource type, cannot edit.'
end
+
forked_resource.save
forked_resource
end
end
end