Sha256: 59c274bb5d695bf14b4f03e6dfb54cd0d9249ce3bcbf6ede94d3fcfa1128a153

Contents?: true

Size: 1.54 KB

Versions: 45

Compression:

Stored size: 1.54 KB

Contents

require "phantomjs/version"
require 'fileutils'

module Phantomjs
  class UnknownPlatform < StandardError; end;

  class << self
    def available_platforms
      @available_platforms ||= []
    end

    def base_dir
       @base_dir ||= File.join(File.expand_path('~'), '.phantomjs', version)
    end

    def base_dir=(dir)
      @base_dir = dir
    end

    def version
      Phantomjs::VERSION.split('.')[0..-2].join('.')
    end

    def path
      @path ||= platform.phantomjs_path
    end

    def platform
      if platform = available_platforms.find {|p| p.useable? }
        platform.ensure_installed!
        platform
      else
        raise UnknownPlatform, "Could not find an appropriate PhantomJS library for your platform (#{RUBY_PLATFORM} :( Please install manually."
      end
    end

    # Removes the local phantomjs copy
    def implode!
      FileUtils.rm_rf File.join(File.expand_path('~'), '.phantomjs')
    end

    # Clears cached state. Primarily useful for testing.
    def reset!
      @base_dir = @path = nil
    end

    # Run phantomjs with the given arguments, and either
    # return the stdout or yield each line to the passed block.
    def run(*args, &block)
      IO.popen([path, *args]) do |io|
        block ? io.each(&block) : io.read
      end
    end
  end
end

require 'phantomjs/platform'
Phantomjs.available_platforms << Phantomjs::Platform::Linux32
Phantomjs.available_platforms << Phantomjs::Platform::Linux64
Phantomjs.available_platforms << Phantomjs::Platform::OsX
Phantomjs.available_platforms << Phantomjs::Platform::Win32

Version data entries

45 entries across 31 versions & 5 rubygems

Version Path
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.1.4 vendor/bundle/ruby/2.7.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.1.3 vendor/bundle/ruby/2.7.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.1.3 vendor/bundle/ruby/2.6.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/phantomjs-2.1.1.0/lib/phantomjs.rb