Module: Yarnlock

Defined in:
lib/yarnlock.rb,
lib/yarnlock/entry.rb,
lib/yarnlock/config.rb,
lib/yarnlock/version.rb,
lib/yarnlock/js_executor.rb,
lib/yarnlock/entry/collection.rb

Defined Under Namespace

Modules: JsExecutor Classes: Config, Entry

Constant Summary collapse

VERSION =
'0.3.2'

Class Method Summary collapse

Class Method Details

.configObject



13
14
15
# File 'lib/yarnlock.rb', line 13

def self.config
  @config ||= Config.new
end

.configure {|config| ... } ⇒ Object

Yields:



17
18
19
# File 'lib/yarnlock.rb', line 17

def self.configure
  yield config
end

.load(file) ⇒ Object



43
44
45
# File 'lib/yarnlock.rb', line 43

def self.load(file)
  parse File.read(file)
end

.parse(yarnlock) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/yarnlock.rb', line 21

def self.parse(yarnlock)
  json_string = JsExecutor.execute 'parse', yarnlock
  parsed = JSON.parse json_string

  raise "An error was occurred when parsing yarn.lock: #{parsed}" unless parsed.is_a? Hash
  raise "Could not parse yarn.lock: #{parsed['reason']}" if parsed['type'] == 'failure'

  return parsed['object'] unless config.return_collection

  Entry::Collection.parse parsed['object']
end

.stringify(object) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/yarnlock.rb', line 33

def self.stringify(object)
  json_string = JsExecutor.execute 'stringify', JSON.generate(object)
  parsed = JSON.parse json_string

  raise "An error was occurred when stringing object: #{parsed}" unless parsed.is_a? Hash
  raise "Could not stringing object: #{parsed['reason']}" if parsed['type'] == 'failure'

  parsed['yarnlock']
end