Class: Mxrb::RubyApp::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/ruby_app.rb

Overview

Reads and validates paths before runtime or reverse compilation uses them.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, data) ⇒ Manifest

Returns a new instance of Manifest.

Raises:

  • (ArgumentError)


104
105
106
107
108
# File 'lib/mxrb/ruby_app.rb', line 104

def initialize(root, data)
  @root = root
  @data = data
  raise ArgumentError, 'MXRB Ruby application manifest must use mode ruby' unless data['mode'] == 'ruby'
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



92
93
94
# File 'lib/mxrb/ruby_app.rb', line 92

def data
  @data
end

#rootObject (readonly)

Returns the value of attribute root.



92
93
94
# File 'lib/mxrb/ruby_app.rb', line 92

def root
  @root
end

Class Method Details

.load(root) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/mxrb/ruby_app.rb', line 94

def self.load(root)
  expanded = File.expand_path(root)
  path = File.join(expanded, MANIFEST_PATH)
  raise ArgumentError, "not an MXRB Ruby application: #{expanded}" unless File.file?(path)

  new(expanded, JSON.parse(File.read(path)))
rescue JSON::ParserError => e
  raise ArgumentError, "invalid MXRB Ruby application manifest: #{e.message}"
end

Instance Method Details

#absolute_path(key) ⇒ Object



114
115
116
117
118
119
120
121
122
123
# File 'lib/mxrb/ruby_app.rb', line 114

def absolute_path(key)
  relative = data.fetch('round_trip').fetch(key)
  clean = Pathname.new(relative).cleanpath
  if clean.absolute? || clean.to_s.start_with?('../')
    raise ArgumentError,
          "unsafe Ruby application path: #{relative}"
  end

  File.join(root, clean.to_s)
end

#coverageObject



112
# File 'lib/mxrb/ruby_app.rb', line 112

def coverage = data.fetch('coverage')

#modulesObject



111
# File 'lib/mxrb/ruby_app.rb', line 111

def modules = data.fetch('modules')

#mpr_nameObject



110
# File 'lib/mxrb/ruby_app.rb', line 110

def mpr_name = data.fetch('source').fetch('name')