Sha256: 126af9dabd72de2e53027cf581643c047f1df1c70d144751f096ce0fcd7d163f

Contents?: true

Size: 738 Bytes

Versions: 14

Compression:

Stored size: 738 Bytes

Contents

require_relative '../helpers'

# Handle a .mixin

class Livetext::Handler::Mixin
  include Livetext::Helpers
  include GlobalHelpers

  attr_reader :file

  def initialize(name, parent)
    @name = name
    @file = find_file(name, ".rb", "plugin")
    parent.graceful_error FileNotFound(name) if @file.nil?
  end

  def self.get_module(filename, parent)
    handler = self.new(filename, parent)
    modname, code = handler.read_mixin
    eval(code)   # Avoid in the future
    newmod = Object.const_get("::" + modname)
    newmod   # return actual module
  end

  def read_mixin
    modname = @name.gsub("/","_").capitalize
    meths = grab_file(@file)  # already has .rb?
    [modname, "module ::#{modname}; #{meths}\nend"]
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
livetext-0.9.42 lib/livetext/handler/mixin.rb
livetext-0.9.41 lib/livetext/handler/mixin.rb
livetext-0.9.40 lib/livetext/handler/mixin.rb
livetext-0.9.39 lib/livetext/handler/mixin.rb
livetext-0.9.38 lib/livetext/handler/mixin.rb
livetext-0.9.37 lib/livetext/handler/mixin.rb
livetext-0.9.36 lib/livetext/handler/mixin.rb
livetext-0.9.35 lib/livetext/handler/mixin.rb
livetext-0.9.33 lib/livetext/handler/mixin.rb
livetext-0.9.32 lib/livetext/handler/mixin.rb
livetext-0.9.31 lib/livetext/handler/mixin.rb
livetext-0.9.30 lib/livetext/handler/mixin.rb
livetext-0.9.27 lib/livetext/handler/mixin.rb
livetext-0.9.26 lib/livetext/handler/mixin.rb