Class: Knitter::Yarn
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Defined in:
- lib/knitter/yarn.rb
Defined Under Namespace
Classes: CommandExecutionError
Constant Summary
collapse
- PACKAGE_AREAS =
{
dev: 'devDependencies',
peer: 'peerDependencies',
optional: 'optionalDependencies',
dependencies: 'dependencies'
}
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(directory) ⇒ Yarn
Returns a new instance of Yarn.
22
23
24
|
# File 'lib/knitter/yarn.rb', line 22
def initialize(directory)
@directory = Pathname.new(directory)
end
|
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
20
21
22
|
# File 'lib/knitter/yarn.rb', line 20
def directory
@directory
end
|
Instance Method Details
#add(package) ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/knitter/yarn.rb', line 34
def add(package)
name = package.name
unless package.version.latest?
name << '@' << package.version.to_s
end
execute(
*['add', name, package_save_as_flag(package)].compact
)
end
|
#init ⇒ Object
26
27
28
|
# File 'lib/knitter/yarn.rb', line 26
def init
execute('init', '--yes')
end
|
#ok? ⇒ Boolean
30
31
32
|
# File 'lib/knitter/yarn.rb', line 30
def ok?
@sh && @sh.status.exitstatus == 0
end
|
#package_file ⇒ Object
44
45
46
|
# File 'lib/knitter/yarn.rb', line 44
def package_file
@directory.join "package.json"
end
|
#package_file_contents ⇒ Object
62
63
64
|
# File 'lib/knitter/yarn.rb', line 62
def package_file_contents
JSON.parse(package_file.read)
end
|
#packages ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/knitter/yarn.rb', line 48
def packages
json = package_file_contents
Enumerator.new do | enum |
PACKAGE_AREAS.each do | type, area |
(json[area] || []).each do | package, version |
package = Package.new(package, yarn: self)
package.version = version
package.dependency_type = type
enum << package
end
end
end
end
|
#valid? ⇒ Boolean
66
67
68
|
# File 'lib/knitter/yarn.rb', line 66
def valid?
package_file.exist? && package_file_contents
end
|