Class: Klenod::Runtime::Mod

Inherits:
Module
  • Object
show all
Defined in:
lib/klenod/runtime/mod.rb

Defined Under Namespace

Classes: Exports

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, source, imports: {}, source_map: nil, version: 0, constant_name: nil, eval_path: nil) ⇒ Mod

Returns a new instance of Mod.



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/klenod/runtime/mod.rb', line 68

def initialize(path, source, imports: {}, source_map: nil, version: 0, constant_name: nil, eval_path: nil)
  @path = path
  @source = source
  @imports = imports
  @source_map = source_map
  @version = version
  @constant_name = constant_name || self.class.constant_name_for(path)
  @eval_path = eval_path || path
  register_constant
  create_exports
end

Instance Attribute Details

#constant_nameObject (readonly)

Returns the value of attribute constant_name.



58
59
60
# File 'lib/klenod/runtime/mod.rb', line 58

def constant_name
  @constant_name
end

#eval_pathObject (readonly)

Returns the value of attribute eval_path.



58
59
60
# File 'lib/klenod/runtime/mod.rb', line 58

def eval_path
  @eval_path
end

#pathObject (readonly)

Returns the value of attribute path.



58
59
60
# File 'lib/klenod/runtime/mod.rb', line 58

def path
  @path
end

#sourceObject (readonly)

Returns the value of attribute source.



58
59
60
# File 'lib/klenod/runtime/mod.rb', line 58

def source
  @source
end

#source_mapObject (readonly)

Returns the value of attribute source_map.



58
59
60
# File 'lib/klenod/runtime/mod.rb', line 58

def source_map
  @source_map
end

#versionObject (readonly)

Returns the value of attribute version.



58
59
60
# File 'lib/klenod/runtime/mod.rb', line 58

def version
  @version
end

Class Method Details

.constant_name_for(path) ⇒ Object



60
61
62
# File 'lib/klenod/runtime/mod.rb', line 60

def self.constant_name_for(path)
  "Mod_#{Digest::SHA256.hexdigest(path)[0, 24]}"
end

Instance Method Details

#inspectObject



64
65
66
# File 'lib/klenod/runtime/mod.rb', line 64

def inspect
  "Mod(#{path.inspect})"
end

#marshal_dumpObject



80
81
82
# File 'lib/klenod/runtime/mod.rb', line 80

def marshal_dump
  [@path, @source, @source_map, @version, @constant_name, @eval_path]
end

#marshal_load(data) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/klenod/runtime/mod.rb', line 84

def marshal_load(data)
  @path, @source, @source_map, @version, @constant_name, @eval_path = data
  @eval_path ||= @path
  @imports = {}
  register_constant
  create_exports
end

#to_sObject



92
93
94
# File 'lib/klenod/runtime/mod.rb', line 92

def to_s
  "#<#{self.class.name} path=#{@path.inspect}>"
end