Module: Dapp::Dapp::Command::Sample::Create
- Included in:
- Dapp::Dapp
- Defined in:
- lib/dapp/dapp/command/sample/create.rb
Instance Method Summary collapse
- #_sample_directory(sample_name) ⇒ Object
- #_sample_repo_blobs_entries(sample_name) ⇒ Object
- #_sample_slice_cwd(sample_name, path) ⇒ Object
- #sample_create(sample_name) ⇒ Object
- #sample_exist!(sample_name) ⇒ Object
- #sample_exist?(sample_name) ⇒ Boolean
Instance Method Details
#_sample_directory(sample_name) ⇒ Object
42 43 44 |
# File 'lib/dapp/dapp/command/sample/create.rb', line 42 def _sample_directory(sample_name) File.(File.join('/', _samples_dir, sample_name))[1..-1] end |
#_sample_repo_blobs_entries(sample_name) ⇒ Object
36 37 38 39 40 |
# File 'lib/dapp/dapp/command/sample/create.rb', line 36 def _sample_repo_blobs_entries(sample_name) _sample_git_repo .blobs_entries(_sample_git_repo.latest_branch_commit(_samples_git_repo_branch), paths: [_sample_directory(sample_name)]) .reject { |_, entry| entry[:filemode] == 0o160000 } end |
#_sample_slice_cwd(sample_name, path) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/dapp/dapp/command/sample/create.rb', line 46 def _sample_slice_cwd(sample_name, path) path .reverse .chomp(_sample_directory(sample_name).reverse) .chomp('/') .reverse end |
#sample_create(sample_name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dapp/dapp/command/sample/create.rb', line 6 def sample_create(sample_name) sample_exist!(sample_name) _sample_repo_blobs_entries(sample_name).each do |root, entry| file_path = _sample_slice_cwd(sample_name, File.join(root, entry[:name])) content = _sample_git_repo.lookup_object(entry[:oid]).content begin FileUtils.mkdir_p(File.dirname(file_path)) if entry[:filemode] == 0o120000 # symlink FileUtils.symlink(content, file_path) else IO.write(file_path, content) FileUtils.chmod(entry[:filemode], file_path) end rescue Errno::EEXIST => e log_warning("File `#{file_path}` skipped: `#{e.}`") end end end |
#sample_exist!(sample_name) ⇒ Object
27 28 29 30 |
# File 'lib/dapp/dapp/command/sample/create.rb', line 27 def sample_exist!(sample_name) return if sample_exist?(sample_name) raise Error::Command, code: :sample_not_exist, data: { name: sample_name, url: _samples_git_repo_url, path: _samples_dir } end |
#sample_exist?(sample_name) ⇒ Boolean
32 33 34 |
# File 'lib/dapp/dapp/command/sample/create.rb', line 32 def sample_exist?(sample_name) _sample_list.include?(sample_name) end |