class RUTL::Application

Application, this top-level class, controls a browser and a fake browser. It will soon call into apps, at which point I need to rethink this naming convention.

Attributes

interface[R]

Public Class Methods

new(family:, type:, views: RUTL::VIEWS || ENV['RUTL_VIEWS']) click to toggle source
# File lib/rutl/application.rb, line 17
def initialize(family:, type:, views: RUTL::VIEWS || ENV['RUTL_VIEWS'])
  raise 'Must set views!' if views.nil? || views.empty?
  # This is kind of evil. Figure out how to ditch the $ variable.
  $application = self
  @interface = load_interface(family: family, type: type)
  @interface.views = load_views(directory: views)
end

Public Instance Methods

method_missing(method, *args, &block) click to toggle source
# File lib/rutl/application.rb, line 25
def method_missing(method, *args, &block)
  if args.empty?
    @interface.send(method)
  else
    @interface.send(method, *args, &block)
  end
end
respond_to_missing?(*args) click to toggle source
# File lib/rutl/application.rb, line 33
def respond_to_missing?(*args)
  @interface.respond_to?(*args)
end
screenshot() click to toggle source
# File lib/rutl/application.rb, line 13
def screenshot
  @interface.camera.screenshot
end

Private Instance Methods

find_class_name(file) click to toggle source
# File lib/rutl/application.rb, line 60
def find_class_name(file)
  require "rutl/../../#{file}"
  File.open(file).each do |line|
    bingo = line.match(/class (.*) < RUTL::View/)
    # One class per file.
    return bingo[1] if bingo && bingo[1]
  end
  false
end
load_interface(family:, type:) click to toggle source
# File lib/rutl/application.rb, line 39
def load_interface(family:, type:)
  require "rutl/interface/#{family}/#{type}"
  klass = "RUTL::Interface::#{type.to_s.pascal_case}"
  Object.const_get(klass).new
end
load_views(directory:) click to toggle source
# File lib/rutl/application.rb, line 45
def load_views(directory:)
  require_views(directory: directory).map do |klass|
    Object.const_get(klass).new(@interface)
  end
end
require_views(directory:) click to toggle source

Ugly. Requires files for view objects. Returns array of class names to load.

# File lib/rutl/application.rb, line 53
def require_views(directory:)
  Dir["#{directory}/*"].map do |file|
    result = find_class_name(file)
    result if result
  end
end