<commit_before># 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
        if resource.class.to_s.downcase =~ /dashboard/
          forked_resource = fork(resource)
          system("open '#{ forked_resource.human_edit_url }'")

          wait_for_edit

          new_resource             = Doggy::Models::Dashboard.find(forked_resource.id)
          new_resource.id          = resource.id
          new_resource.title       = resource.title
          new_resource.description = resource.description
          new_resource.path        = resource.path
          new_resource.save_local

          forked_resource.destroy
        else
          system("open '#{ resource.human_edit_url }'")

          wait_for_edit

          new_resource      = resource.class.find(resource.id)
          new_resource.path = resource.path
          new_resource.save_local
        end
      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
# raise 1.inspect
      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)
        # raise full_path.inspect
        return resources.find { |res| res.path == full_path }
      end<commit_msg>Clean up debugging comments<commit_after># 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
        if resource.class.to_s.downcase =~ /dashboard/
          forked_resource = fork(resource)
          system("open '#{ forked_resource.human_edit_url }'")

          wait_for_edit

          new_resource             = Doggy::Models::Dashboard.find(forked_resource.id)
          new_resource.id          = resource.id
          new_resource.title       = resource.title
          new_resource.description = resource.description
          new_resource.path        = resource.path
          new_resource.save_local

          forked_resource.destroy
        else
          system("open '#{ resource.human_edit_url }'")

          wait_for_edit

          new_resource      = resource.class.find(resource.id)
          new_resource.path = resource.path
          new_resource.save_local
        end
      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 }
      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
{'fraction_non_alphanumeric': 0.11412268188302425, 'fraction_numerical': 0.003090822634331907, 'mean_word_length': 2.0888399412628487, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4473038', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1218, 'n_words': 262}