Sha256: f06e1b45b4ba6cf02069a1fb9a8458e160dae0525643bd0afa81912143bd9717

Contents?: true

Size: 736 Bytes

Versions: 4

Compression:

Stored size: 736 Bytes

Contents

# frozen_string_literal: true

module Phlex
	class Compiler
		def initialize(view)
			@view = view
		end

		def inspect
			"#{self.class.name} for #{@view.name} view class"
		end

		def call
			Visitors::File.new(self).visit(tree)
		end

		def redefined?(method_name)
			prototype = @view.allocate

			@view.instance_method(method_name).bind(prototype) !=
				Phlex::View.instance_method(method_name).bind(prototype)
		end

		def redefine(method)
			@view.class_eval(method)
		end

		def line
			location[1]
		end

		private

		def tree
			@tree ||= SyntaxTree.parse(source)
		end

		def source
			SyntaxTree.read(file)
		end

		def file
			location[0]
		end

		def location
			::Module.const_source_location(@view.name)
		end
	end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
phlex-0.4.0 lib/phlex/compiler.rb
phlex-0.3.2 lib/phlex/compiler.rb
phlex-0.3.1 lib/phlex/compiler.rb
phlex-0.3.0 lib/phlex/compiler.rb