lib/doggy/cli/edit.rb in doggy-2.0.32 vs lib/doggy/cli/edit.rb in doggy-2.0.33

- old
+ new

@@ -6,11 +6,11 @@ @options = options @param = param end def run - resource = resource_by_param + resource = Doggy::Model.find_local(@param) return Doggy.ui.error("Could not find resource with #{ @param }") unless resource forked_resource = fork(resource) system("open '#{ forked_resource.human_edit_url }'") wait_for_edit @@ -29,31 +29,12 @@ new_resource.save_local forked_resource.destroy end - private + private - def resource_by_param - resources = Doggy::Model.all_local_resources - if @param =~ /^[0-9]+$/ then - id = @param.to_i - return resources.find { |res| res.id == id } - elsif @param =~ /^http/ then - id = case @param - when /com\/dash/ then Integer(@param[/dash\/(\d+)/i, 1]) - when /com\/screen/ then Integer(@param[/screen\/(\d+)/i, 1]) - when /com\/monitors/ then Integer(@param[/monitors#(\d+)/i, 1]) - else raise StandardError.new('Unknown resource type, cannot edit.') - end - return resources.find { |res| res.id == id } - else - full_path = File.expand_path(@param.gsub('objects/', ''), Doggy.object_root) - return resources.find { |res| res.path == full_path } - end - end - def wait_for_edit while !Doggy.ui.yes?('Are you done editing?(Y/N)') do 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" end end @@ -80,6 +61,5 @@ def random_word (0...12).map { (65 + rand(26)).chr.downcase }.join end end end -