Module: Pray::Destination

Defined in:
lib/pray/destination.rb

Class Method Summary collapse

Class Method Details

.bind_local_entry(target, path) ⇒ Object



118
119
120
121
122
# File 'lib/pray/destination.rb', line 118

def bind_local_entry(target, path)
  return if target.entries.any? { |candidate| candidate.kind == "local" && candidate.path == path }

  target.entries << DestinationEntry.local(path)
end

.bind_package_entry(target, package_name) ⇒ Object



111
112
113
114
115
116
# File 'lib/pray/destination.rb', line 111

def bind_package_entry(target, package_name)
  entry = DestinationEntry.package(package_name)
  return if target.entries.any? { |candidate| candidate.kind == "package" && candidate.name == package_name }

  target.entries << entry
end

.destination_target_name(mode, path) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/pray/destination.rb', line 23

def destination_target_name(mode, path)
  prefix = case mode
  when "compose" then "compose"
  when "tree" then "tree"
  else "legacy"
  end
  "#{prefix}:#{path}"
end

.export_kind_matches_role?(kind, role) ⇒ Boolean

Returns:

  • (Boolean)


149
150
151
152
153
154
155
156
# File 'lib/pray/destination.rb', line 149

def export_kind_matches_role?(kind, role)
  case role
  when "fragment" then kind == "fragment"
  when "folder" then %w[folder skill].include?(kind)
  when "file" then kind == "file"
  else false
  end
end

.local_path_form?(value) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/pray/destination.rb', line 17

def local_path_form?(value)
  value.start_with?(".", "/") ||
    value.end_with?(".md", ".txt", ".markdown") ||
    !value.include?("/")
end

.new_destination_target(mode, path) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pray/destination.rb', line 32

def new_destination_target(mode, path)
  target = ManifestTarget.new(
    name: destination_target_name(mode, path),
    mode: mode,
    scoped: true
  )
  case mode
  when "compose" then target.outputs << path
  when "tree" then target.skills << path
  end
  target
end

.package_bound_to_compose?(package, target) ⇒ Boolean

Returns:

  • (Boolean)


131
132
133
134
135
136
137
138
# File 'lib/pray/destination.rb', line 131

def package_bound_to_compose?(package, target)
  if target.scoped && target.mode == "compose"
    return target.entries.any? { |entry| entry.kind == "package" && entry.name == package.name }
  end
  return false if package.bound || package.file

  true
end

.package_bound_to_tree?(package, target) ⇒ Boolean

Returns:

  • (Boolean)


140
141
142
143
144
145
146
147
# File 'lib/pray/destination.rb', line 140

def package_bound_to_tree?(package, target)
  if target.scoped && target.mode == "tree"
    return target.entries.any? { |entry| entry.kind == "package" && entry.name == package.name }
  end
  return false if package.bound || package.file

  true
end

.role_for_destination(mode) ⇒ Object



124
125
126
127
128
129
# File 'lib/pray/destination.rb', line 124

def role_for_destination(mode)
  case mode
  when "compose" then "fragment"
  when "tree" then "folder"
  end
end

.upsert_local(manifest, local) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/pray/destination.rb', line 97

def upsert_local(manifest, local)
  existing = manifest.local.find { |candidate| candidate.path == local.path }
  unless existing
    manifest.local << local
    return
  end

  existing.bound = existing.bound || local.bound
  existing.optional = existing.optional || local.optional
  if existing.position == "after" && local.position != "after"
    existing.position = local.position
  end
end

.upsert_package(manifest, package) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/pray/destination.rb', line 45

def upsert_package(manifest, package)
  existing = manifest.packages.find { |candidate| candidate.name == package.name }
  unless existing
    manifest.packages << package
    return
  end

  if existing.constraint != package.constraint &&
      existing.constraint != "*" &&
      package.constraint != "*"
    raise Error.manifest(
      "package #{package.name} declared with conflicting constraints " \
      "(#{existing.constraint} vs #{package.constraint})"
    )
  end
  existing.constraint = package.constraint if existing.constraint == "*" && package.constraint != "*"

  if existing.source.nil?
    existing.source = package.source
  elsif package.source && existing.source != package.source
    raise Error.manifest("package #{package.name} declared with conflicting sources")
  end

  package.exports.each do |export|
    existing.exports << export unless existing.exports.include?(export)
  end
  package.roles.each do |role|
    existing.roles << role unless existing.roles.include?(role)
  end

  if package.file
    if existing.file && existing.file != package.file
      raise Error.manifest(
        "package #{package.name} declared with conflicting file: destinations"
      )
    end
    existing.file = package.file
  end

  existing.bound = existing.bound || package.bound
  existing.optional = existing.optional || package.optional
  existing.path ||= package.path
  existing.git ||= package.git
  existing.tag ||= package.tag
  existing.rev ||= package.rev
  existing.tarball ||= package.tarball
  existing.oci ||= package.oci
  package.groups.each do |group|
    existing.groups << group unless existing.groups.include?(group)
  end
end