Class: Dpl::Example

Inherits:
Struct
  • Object
show all
Defined in:
lib/dpl/provider/examples.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#constObject

Returns the value of attribute const

Returns:

  • (Object)

    the current value of const



84
85
86
# File 'lib/dpl/provider/examples.rb', line 84

def const
  @const
end

#optsObject

Returns the value of attribute opts

Returns:

  • (Object)

    the current value of opts



84
85
86
# File 'lib/dpl/provider/examples.rb', line 84

def opts
  @opts
end

Instance Method Details

#==(other) ⇒ Object



99
100
101
# File 'lib/dpl/provider/examples.rb', line 99

def ==(other)
  const == other.const && opts == other.opts
end

#cmdObject



95
96
97
# File 'lib/dpl/provider/examples.rb', line 95

def cmd
  "dpl #{name} #{strs_for(opts)}"
end

#compact(hash) ⇒ Object



128
129
130
# File 'lib/dpl/provider/examples.rb', line 128

def compact(hash)
  hash.reject { |_, value| value.nil? }
end

#configObject



85
86
87
88
89
# File 'lib/dpl/provider/examples.rb', line 85

def config
  config = opts_for(opts)
  config = config.merge(strategy: strategy) # hmm.
  compact(config)
end

#nameObject



103
104
105
# File 'lib/dpl/provider/examples.rb', line 103

def name
  const.registry_key.to_s.split(':').join(' ')
end

#opts_for(opts) ⇒ Object



107
108
109
# File 'lib/dpl/provider/examples.rb', line 107

def opts_for(opts)
  opts.map { |opt| [opt.name, value_for(opt)] }.to_h
end

#str_for(opt) ⇒ Object



115
116
117
# File 'lib/dpl/provider/examples.rb', line 115

def str_for(opt)
  "--#{opt.name} #{value_for(opt)}".strip
end

#strategyObject



91
92
93
# File 'lib/dpl/provider/examples.rb', line 91

def strategy
  const.registry_key.to_s.split(':').last if const.registry_key.to_s.include?(':')
end

#strs_for(opts) ⇒ Object



111
112
113
# File 'lib/dpl/provider/examples.rb', line 111

def strs_for(opts)
  opts.map { |opt| str_for(opt) }.join(' ')
end

#value_for(opt) ⇒ Object



119
120
121
122
123
124
125
126
# File 'lib/dpl/provider/examples.rb', line 119

def value_for(opt)
  return if opt.type == :flag
  return 1 if opt.type == :integer
  return opt.enum.first if opt.enum?

  str = opt.strs.detect { |str| str =~ /^--#{opt.name} (.*)$/ } && ::Regexp.last_match(1)
  str ? str.downcase : 'str'
end