Sha256: 198bf6b6236626de2257b26ffb3eff369e50946902a2204c19dbc60aee0e3134

Contents?: true

Size: 1.12 KB

Versions: 8

Compression:

Stored size: 1.12 KB

Contents

# vim:fileencoding=utf-8

module ResqueAdmin
  module Scheduler
    class Util
      # In order to upgrade to resque_admin(1.25) which has deprecated following
      # methods, we just added these usefull helpers back to use in ResqueAdmin
      # Scheduler.  refer to:
      # https://github.com/resque_admin/resque_admin-scheduler/pull/273

      def self.constantize(camel_cased_word)
        camel_cased_word = camel_cased_word.to_s

        if camel_cased_word.include?('-')
          camel_cased_word = classify(camel_cased_word)
        end

        names = camel_cased_word.split('::')
        names.shift if names.empty? || names.first.empty?

        constant = Object
        names.each do |name|
          args = Module.method(:const_get).arity != 1 ? [false] : []

          constant = if constant.const_defined?(name, *args)
                       constant.const_get(name)
                     else
                       constant.const_missing(name)
                     end
        end
        constant
      end

      def self.classify(dashed_word)
        dashed_word.split('-').map(&:capitalize).join
      end
    end
  end
end

Version data entries

8 entries across 6 versions & 2 rubygems

Version Path
resque_admin-scheduler-1.2.0 lib/resque_admin/scheduler/util.rb
resque_admin-scheduler-1.1.9 lib/resque_admin/scheduler/util.rb
resque_admin-scheduler-1.1.7 lib/resque_admin/scheduler/util.rb
resque_admin-scheduler-1.3.0 lib/resque_admin/scheduler/util.rb
resque-admin-scheduler-1.3.0 lib/resque_admin/scheduler/util.rb
resque-admin-scheduler-1.3.0 lib/resque/scheduler/util.rb
resque-admin-scheduler-4.3.0 lib/resque_admin/scheduler/util.rb
resque-admin-scheduler-4.3.0 lib/resque/scheduler/util.rb