Class: Boxing::Database
- Inherits:
-
Object
- Object
- Boxing::Database
- Defined in:
- lib/boxing/database.rb
Overview
The package and dependency mapping database
Defined Under Namespace
Classes: DownloadFailed, UpdateFailed
Constant Summary collapse
- URL =
Git URL of the ruby-boxing-db
'https://github.com/elct9620/ruby-boxing-db.git'
- USER_PATH =
Path to the user’s copy of ruby-boxing-db
Pathname.new(Gem.user_home).join('.local/share/ruby-boxing-db')
- DEFAULT_PATH =
ENV.fetch('BOXING_DB', USER_PATH)
Instance Attribute Summary collapse
- #path ⇒ Object readonly
Class Method Summary collapse
-
.download!(path = DEFAULT_PATH) ⇒ Object
Download Database.
-
.exist?(path = DEFAULT_PATH) ⇒ TrueClass\FalseClass
Check for the database exists.
Instance Method Summary collapse
-
#each_package_path_for(name) {|path| ... } ⇒ Object
Enumerates over gems.
-
#git? ⇒ TrueClass|FalseClass
The Database is Git Repoistory.
-
#initialize(path = DEFAULT_PATH) ⇒ Database
constructor
Initialize Database.
-
#package_for(name) {|path| ... } ⇒ Object
Find packages for rubygems.
-
#update! ⇒ Object
Update the database.
Constructor Details
#initialize(path = DEFAULT_PATH) ⇒ Database
Initialize Database
61 62 63 |
# File 'lib/boxing/database.rb', line 61 def initialize(path = DEFAULT_PATH) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
56 57 58 |
# File 'lib/boxing/database.rb', line 56 def path @path end |
Class Method Details
.download!(path = DEFAULT_PATH) ⇒ Object
Download Database
26 27 28 29 30 31 32 33 |
# File 'lib/boxing/database.rb', line 26 def download!(path = DEFAULT_PATH) command = %w[git clone --quiet] command << URL << path.to_s raise DownloadFailed, "failed to download #{URL} to #{path}" unless system(*command) new(path) end |
.exist?(path = DEFAULT_PATH) ⇒ TrueClass\FalseClass
Check for the database exists
19 20 21 |
# File 'lib/boxing/database.rb', line 19 def exist?(path = DEFAULT_PATH) File.directory?(path) && !(Dir.entries(path) - %w[. ..]).empty? end |
Instance Method Details
#each_package_path_for(name) {|path| ... } ⇒ Object
Enumerates over gems
111 112 113 |
# File 'lib/boxing/database.rb', line 111 def each_package_path_for(name, &block) Dir.glob(File.join(@path, 'gems', name, '*.yml'), &block) end |
#git? ⇒ TrueClass|FalseClass
The Database is Git Repoistory
70 71 72 |
# File 'lib/boxing/database.rb', line 70 def git? File.directory?(File.join(@path, '.git')) end |
#package_for(name) {|path| ... } ⇒ Object
Find packages for rubygems
96 97 98 99 100 101 102 |
# File 'lib/boxing/database.rb', line 96 def package_for(name) return enum_for(__method__, name) unless block_given? each_package_path_for(name.to_s) do |path| yield Package.load(path) end end |
#update! ⇒ Object
Update the database
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/boxing/database.rb', line 77 def update! return unless git? Dir.chdir(@path) do command = %w[git pull --quiet origin main] raise UpdateFailed, "failed to update #{@path}" unless system(*command) end true end |