module Catalyst

typed: strong

typed: true

Constants

CatalystError
MissingConfig
NotInstalled

Public Class Methods

build!(environment = nil) click to toggle source
# File lib/catalyst-rails.rb, line 52
def self.build!(environment = nil)
  ::Catalyst::Builder.build!(environment)
end
check_for_catalyst!() click to toggle source
# File lib/catalyst-rails.rb, line 98
  def self.check_for_catalyst!
    check_for_yarn!

    unless File.exist?(File.join(Dir.pwd, 'node_modules/catalyst/lib/index.js'))
      raise NotInstalled, <<~MESSAGE
        The catalyst binary is not available in this directory.
        Please follow the instructions here to install it:
        https://github.com/friendsoftheweb/catalyst
      MESSAGE
    end
  end
check_for_yarn!() click to toggle source
# File lib/catalyst-rails.rb, line 88
  def self.check_for_yarn!
    unless system 'which yarn > /dev/null 2>&1'
      raise NotInstalled, <<~MESSAGE
        The yarn binary is not available in this directory.
        Please follow the instructions here to install it:
        https://yarnpkg.com/lang/en/docs/install
      MESSAGE
    end
  end
development?() click to toggle source
# File lib/catalyst-rails.rb, line 40
def self.development?
  config.environment == :development
end
log(message, level = :info) click to toggle source
# File lib/catalyst-rails.rb, line 32
def self.log(message, level = :info)
  message = message.split("\n").reduce('') do |reduction, line|
    reduction + "\e[35m[Catalyst]\e[0m #{line}\n"
  end

  puts message
end
production?() click to toggle source
# File lib/catalyst-rails.rb, line 48
def self.production?
  config.environment == :production
end
serve!() click to toggle source
# File lib/catalyst-rails.rb, line 56
def self.serve!
  unless $catalyst_server_pid.nil?
    log(
      "A Catalyst server is already running (#{$catalyst_server_pid}).",
      :warn
    )

    return
  end

  check_for_catalyst!

  stdin, stdout, stderr, wait_thr = Open3.popen3('yarn start')

  $catalyst_server_pid = wait_thr.pid

  Thread.new do
    begin
      while line = stdout.gets
        puts line
      end
    rescue IOError
    end
  end

  at_exit do
    stdin.close
    stdout.close
    stderr.close
  end
end
test?() click to toggle source
# File lib/catalyst-rails.rb, line 44
def self.test?
  config.environment == :test
end
version() click to toggle source
# File lib/catalyst/version.rb, line 5
def self.version
  Gem::Version.new('0.1.3')
end