Class: Caco::FileLink
- Inherits:
-
Trailblazer::Operation
- Object
- Trailblazer::Operation
- Caco::FileLink
- Defined in:
- lib/caco/file_link.rb
Instance Method Summary collapse
- #create_link!(ctx, target:, link:, link_exist:, link_same_target:) ⇒ Object
- #ensure_target!(ctx, target_exist:, ensure_target: false) ⇒ Object
- #link_exist?(ctx, link:) ⇒ Boolean
- #link_same_target?(ctx, target_realpath:, link_realpath:) ⇒ Boolean
- #target_exist?(ctx, target:) ⇒ Boolean
Instance Method Details
#create_link!(ctx, target:, link:, link_exist:, link_same_target:) ⇒ Object
31 32 33 34 35 |
# File 'lib/caco/file_link.rb', line 31 def create_link!(ctx, target:, link:, link_exist:, link_same_target:, **) ctx[:force] = (link_exist && !link_same_target) FileUtils.ln_s target, link, force: ctx[:force] ctx[:link_created] = true end |
#ensure_target!(ctx, target_exist:, ensure_target: false) ⇒ Object
26 27 28 29 |
# File 'lib/caco/file_link.rb', line 26 def ensure_target!(ctx, target_exist:, ensure_target: false, **) return false if !target_exist && ensure_target true end |
#link_exist?(ctx, link:) ⇒ Boolean
10 11 12 13 14 |
# File 'lib/caco/file_link.rb', line 10 def link_exist?(ctx, link:, **) ctx[:link_exist] = !!File.lstat(link) rescue false ctx[:link_realpath] = File.realdirpath(link) rescue false ctx[:link_exist] end |
#link_same_target?(ctx, target_realpath:, link_realpath:) ⇒ Boolean
22 23 24 |
# File 'lib/caco/file_link.rb', line 22 def link_same_target?(ctx, target_realpath:, link_realpath:, **) ctx[:link_same_target] = (target_realpath == link_realpath) end |
#target_exist?(ctx, target:) ⇒ Boolean
16 17 18 19 20 |
# File 'lib/caco/file_link.rb', line 16 def target_exist?(ctx, target:, **) ctx[:target_exist] = File.exist?(target) ctx[:target_realpath] = File.realdirpath(target) rescue nil ctx[:target_exist] end |