Class: RakeFly::OptionResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/rake_fly.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ OptionResolver

Returns a new instance of OptionResolver.



42
43
44
# File 'lib/rake_fly.rb', line 42

def initialize(opts)
  @opts = opts
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



40
41
42
# File 'lib/rake_fly.rb', line 40

def opts
  @opts
end

Instance Method Details

#dependencyObject



79
80
81
# File 'lib/rake_fly.rb', line 79

def dependency
  'fly'
end

#file_name_templateObject



114
115
116
117
118
119
120
# File 'lib/rake_fly.rb', line 114

def file_name_template
  if new_format?
    'fly-<%= @version %>-<%= @platform_os_name %>-amd64<%= @ext %>'
  else
    'fly_<%= @platform_os_name %>_amd64'
  end
end

#fly_binary_pathObject

rubocop:enable Metrics/MethodLength



71
72
73
# File 'lib/rake_fly.rb', line 71

def fly_binary_path
  File.join(path, 'bin', 'fly')
end

#installation_task_set_optionsObject

rubocop:disable Metrics/MethodLength



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rake_fly.rb', line 47

def installation_task_set_options
  task_set_opts = {
    namespace:,
    dependency:,
    version:,
    path:,
    type:,
    platform_os_names:,
    uri_template:,
    file_name_template:,
    needs_fetch: needs_fetch_check_lambda
  }

  unless new_format?
    task_set_opts[:source_binary_name_template] =
      source_binary_name_template
    task_set_opts[:target_binary_name_template] =
      target_binary_name_template
  end

  task_set_opts
end

#namespaceObject



75
76
77
# File 'lib/rake_fly.rb', line 75

def namespace
  opts[:namespace] || :fly
end

#needs_fetch_check_lambdaObject



130
131
132
133
134
135
136
# File 'lib/rake_fly.rb', line 130

def needs_fetch_check_lambda
  lambda { |t|
    fly_binary = File.join(t.path, t.binary_directory, 'fly')

    !(File.exist?(fly_binary) && RubyFly.version == version)
  }
end

#new_format?Boolean

Returns:

  • (Boolean)


138
139
140
141
# File 'lib/rake_fly.rb', line 138

def new_format?
  Semantic::Version.new(version) >=
    Semantic::Version.new(ARTIFACT_FORMAT_CHANGE_VERSION)
end

#pathObject



87
88
89
# File 'lib/rake_fly.rb', line 87

def path
  opts[:path] || File.join('vendor', 'fly')
end

#platform_os_namesObject



99
100
101
# File 'lib/rake_fly.rb', line 99

def platform_os_names
  { darwin: 'darwin', linux: 'linux' }
end

#source_binary_name_templateObject



126
127
128
# File 'lib/rake_fly.rb', line 126

def source_binary_name_template
  'fly_<%= @platform_os_name %>_amd64'
end

#target_binary_name_templateObject



122
123
124
# File 'lib/rake_fly.rb', line 122

def target_binary_name_template
  'fly'
end

#typeObject



91
92
93
94
95
96
97
# File 'lib/rake_fly.rb', line 91

def type
  if new_format?
    :tgz
  else
    :uncompressed
  end
end

#uri_templateObject



103
104
105
106
107
108
109
110
111
112
# File 'lib/rake_fly.rb', line 103

def uri_template
  if new_format?
    'https://github.com/concourse/concourse/releases/download' \
      '/v<%= @version %>' \
      '/fly-<%= @version %>-<%= @platform_os_name %>-amd64<%= @ext %>'
  else
    'https://github.com/concourse/concourse/releases/' \
      'download/v<%= @version %>/fly_<%= @platform_os_name %>_amd64'
  end
end

#versionObject



83
84
85
# File 'lib/rake_fly.rb', line 83

def version
  opts[:version] || '2.7.0'
end