Sha256: def00dea3be73cb35dd4f452cee0f1a3bc7a144cc4141925b13250e57ad6c0a9

Contents?: true

Size: 675 Bytes

Versions: 4

Compression:

Stored size: 675 Bytes

Contents

require 'method_source'

class Rufus::Scheduler::Job
  UNDESIRED_ELEMENTS = ['', '}', 'end']

  def identifier
    @identifier ||= begin
      return name if name

      lines = handler.source.split("\n")
      whitespace_removed = lines.map(&:strip)
      undesired_removed = whitespace_removed - UNDESIRED_ELEMENTS
      comment_only_lines_removed = undesired_removed.grep_v(/#.*/)
      comment_only_lines_removed[-1] # final line
    rescue
      begin
        source_location.join('-')
      rescue
        'error-calculating-job-identifier'
      end
    end
  end

  def slug
    require 'active_support/inflector'
    identifier.gsub('_', '-').parameterize
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruby-clock-2.0.1 lib/rufus_monkeypatch.rb
ruby-clock-2.0.0 lib/rufus_monkeypatch.rb
ruby-clock-2.0.0.beta10 lib/rufus_monkeypatch.rb
ruby-clock-2.0.0.beta9 lib/rufus_monkeypatch.rb