Class: Knitter::Yarn
- Inherits:
-
Object
- Object
- Knitter::Yarn
- Extended by:
- Forwardable
- Defined in:
- lib/knitter/yarn.rb
Constant Summary collapse
- PACKAGE_AREAS =
{ dev: 'devDependencies', peer: 'peerDependencies', optional: 'optionalDependencies', dependencies: 'dependencies' }
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
Instance Method Summary collapse
- #add(package) ⇒ Object
- #init ⇒ Object
-
#initialize(directory) ⇒ Yarn
constructor
A new instance of Yarn.
- #ok? ⇒ Boolean
- #package_file ⇒ Object
- #package_file_contents ⇒ Object
- #packages ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(directory) ⇒ Yarn
Returns a new instance of Yarn.
19 20 21 |
# File 'lib/knitter/yarn.rb', line 19 def initialize(directory) @directory = Pathname.new(directory) end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
17 18 19 |
# File 'lib/knitter/yarn.rb', line 17 def directory @directory end |
Instance Method Details
#add(package) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/knitter/yarn.rb', line 31 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
23 24 25 |
# File 'lib/knitter/yarn.rb', line 23 def init execute('init', '--yes') end |
#ok? ⇒ Boolean
27 28 29 |
# File 'lib/knitter/yarn.rb', line 27 def ok? @sh && @sh.status.exitstatus == 0 end |
#package_file ⇒ Object
41 42 43 |
# File 'lib/knitter/yarn.rb', line 41 def package_file @directory.join "package.json" end |
#package_file_contents ⇒ Object
59 60 61 |
# File 'lib/knitter/yarn.rb', line 59 def package_file_contents JSON.parse(package_file.read) end |
#packages ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/knitter/yarn.rb', line 45 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
63 64 65 |
# File 'lib/knitter/yarn.rb', line 63 def valid? package_file_contents end |