Module: Yarnlock

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

Defined Under Namespace

Modules: JsExecutor Classes: Config

Constant Summary collapse

VERSION =
'0.1.1'

Class Method Summary collapse

Class Method Details

.configObject



11
12
13
# File 'lib/yarnlock.rb', line 11

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

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

Yields:



15
16
17
# File 'lib/yarnlock.rb', line 15

def self.configure
  yield config
end

.load(file) ⇒ Object



35
36
37
# File 'lib/yarnlock.rb', line 35

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

.parse(yarnlock) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/yarnlock.rb', line 19

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']}" unless parsed['type'] == 'success'
  parsed['object']
end

.stringify(object) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/yarnlock.rb', line 27

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']}" unless parsed['type'] == 'success'
  parsed['yarnlock']
end