Sha256: f68e1306e8e0002b6df4fa66d738e141df60df354068dda7d8723985a0bfdbb2

Contents?: true

Size: 1.2 KB

Versions: 11

Compression:

Stored size: 1.2 KB

Contents

# encoding: utf-8

module Doggy
  class CLI::Edit
    def initialize(options, param)
      @options = options
      @param   = param
    end

    def run
      resource = resource_by_param
      return Doggy.ui.error("Could not find resource with #{ @param }") unless resource

      Dir.chdir(File.dirname(resource.path)) do
        system("open '#{ resource.human_edit_url }'")
        while !Doggy.ui.yes?('Are you done editing?') 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

        new_resource      = resource.class.find(resource.id)
        new_resource.path = resource.path
        new_resource.save_local
      end
    end

  private

    def resource_by_param
      resources  = Doggy::Models::Dashboard.all_local
      resources += Doggy::Models::Monitor.all_local
      resources += Doggy::Models::Screen.all_local

      if @param =~ /^[0-9]+$/ then
        id = @param.to_i
        return resources.find { |res| res.id == id }
      else
        full_path = File.expand_path(@param, Dir.pwd)
        return resources.find { |res| res.path == full_path }
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
doggy-2.0.12 lib/doggy/cli/edit.rb
doggy-2.0.11 lib/doggy/cli/edit.rb
doggy-2.0.10 lib/doggy/cli/edit.rb
doggy-2.0.9 lib/doggy/cli/edit.rb
doggy-2.0.8 lib/doggy/cli/edit.rb
doggy-2.0.7 lib/doggy/cli/edit.rb
doggy-2.0.6 lib/doggy/cli/edit.rb
doggy-2.0.5 lib/doggy/cli/edit.rb
doggy-2.0.4 lib/doggy/cli/edit.rb
doggy-2.0.3 lib/doggy/cli/edit.rb
doggy-2.0.2 lib/doggy/cli/edit.rb