class RBT::CreateSnapcraftFile

Public Class Methods

[](i = ARGV) click to toggle source
#

RBT::CreateSnapcraftFile[]

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 423
def self.[](i = ARGV)
  new(i)
end
new( program_name = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 38
def initialize(
    program_name = nil,
    run_already  = true
  )
  reset
  set_program_name(
    program_name
  )
  run if run_already
end

Public Instance Methods

add( i = '', add_newline = true ) click to toggle source
#

add (add tag)

Add onto the main string through this method.

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 116
def add(
    i           = '',
    add_newline = true
  )
  @snapcraft_file_content << i
  @snapcraft_file_content << N if add_newline
end
add_apps() click to toggle source
#

add_apps (apps tag)

This refers essentially to the binaries of a program.

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 375
def add_apps
  _ = "apps:\n".dup
  binaries?.each {|this_binary|
    _ << " #{this_binary}:\n"
    _ << "  command: bin/#{this_binary}\n"
  }
  add(_)
end
add_confinement( use_this_confinement = 'strict' ) click to toggle source
#

add_confinement

Confinement describes the level of confinement that can be applied to the given app.

Can be either ‘devmode’ or ‘strict’.

Unconfined applications, specified with ‘devmode’, can only be released to the hidden “edge” channel.

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 206
def add_confinement(
    use_this_confinement = 'strict'
  )
  add('confinement: '+use_this_confinement)
end
add_everything() click to toggle source
#

add_everything

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 387
def add_everything
  add_name
  add_program_version
  add_program_summary
  add_program_licence
  add_program_description
  add_the_proper_base
  add_grade
  add_confinement
  add_newline
  add_apps
  add_parts
end
add_grade( use_this_grade = 'stable' ) click to toggle source
#

add_grade (grade tag)

The grade can be ‘devel’ or ‘stable’. Only stable will be used for release into candidate/stable channels.

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 189
def add_grade(
    use_this_grade = 'stable'
  )
  add("grade: #{use_this_grade}")
end
add_name() click to toggle source
#

add_name

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 169
def add_name
  add('name: '+short_name?)
end
add_newline() click to toggle source
#

add_newline

This method will simply add a newline to the snapcraft file.

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 129
def add_newline
  add
end
add_parts() click to toggle source
#

add_parts (parts tag)

This method denotes the necessary parts (components) of our program at hand.

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 280
  def add_parts
    heredoc_variable = <<-EOF
parts:
 #{name_of_this_individual_program?}:
  # See 'snapcraft plugins' for more information.
  plugin: #{plugin_type?}
  source: #{remote_url?}
EOF
    add(heredoc_variable)
  end
add_program_description() click to toggle source
#

add_program_description (desc tag)

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 332
def add_program_description
  description_to_use = "description: |#{N}".dup
  _ = @dataset.description?
  _.split(N).each {|line|
    description_to_use << ' '+line+N
  }
  add(description_to_use.strip.chomp)
end
add_program_licence() click to toggle source
#

add_program_licence

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 229
def add_program_licence
  if licence?
    add("license: #{licence?}")
  end
end
add_program_summary() click to toggle source
#

add_program_summary

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 222
def add_program_summary
  add('summary: |'+N+' '+short_desc?)
end
add_program_version() click to toggle source
#

add_program_version (version tag)

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 215
def add_program_version
  add("version: '#{program_version?}'")
end
add_the_proper_base() click to toggle source
#

add_the_proper_base

This will add a String such as:

'base: core18'

The base keyword declares which base snap to use with your project. A base snap is a special kind of snap that provides a run-time environment alongside a minimal set of libraries that are common to most applications.

For more documentation see:

https://snapcraft.io/docs/ruby-applications
#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 324
def add_the_proper_base
  add('base: core18')
  add_newline
end
binaries?() click to toggle source
#

binaries?

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 294
def binaries?
  @dataset.binaries?
end
generate_the_snapcraft_file( into = into? ) click to toggle source
#

generate_the_snapcraft_file

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 361
def generate_the_snapcraft_file(
    into = into?
  )
  what = what?
  remove_file(into) if File.exist? into
  opne "Now saving the content into the file `#{sfile(into)}`."
  write_what_into(what, into)
end
into?() click to toggle source
#

into?

Where to store into - a file.

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 107
def into?
  @internal_hash[:store_into_this_file]
end
licence?() click to toggle source
#

licence?

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 249
def licence?
  @dataset.licence?
end
name_of_this_individual_program?() click to toggle source
#

name_of_this_individual_program?

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 263
def name_of_this_individual_program?
  @name_of_this_individual_program
end
notify_the_user_that_we_will_create_a_new_snapcraft_file_next( _ = programs? ) click to toggle source
#

notify_the_user_that_we_will_create_a_new_snapcraft_file_next

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 344
def notify_the_user_that_we_will_create_a_new_snapcraft_file_next(
    _ = programs?
  )
  result = 'Creating a snapcraft file next for the program'.dup
  if _.is_a?(Array) and (_.size > 1)
    result << 's'
  end
  if _.is_a? Array
    _ = _.join(', ').strip
  end
  result << " called #{royalblue(_)}."
  opne result
end
plugin_type?() click to toggle source
#

plugin_type?

This is currently hardcoded.

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 303
def plugin_type?
  'autotools'
end
program_name?() click to toggle source
#

program_name?

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 143
def program_name?
  @program_name
end
Also aliased as: programs?
program_version?() click to toggle source
#

program_version?

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 162
def program_version?
  @dataset.program_version?
end
programs?()
Alias for: program_name?
remote_url?() click to toggle source
#

remote_url?

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 256
def remote_url?
  @dataset.remote_url?
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::LeanPrototype#reset
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 52
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @snapcraft_file_content
  #
  # The following instance variable, a String, is the one that is used
  # to store all content that will be written into the snapcraft yaml
  # file. It will be used to store the file in the current directory.
  # ======================================================================= #
  @snapcraft_file_content = ''.dup
  # ======================================================================= #
  # === :store_into_this_file
  #
  # Denote into which file we will store that content.
  # ======================================================================= #
  @internal_hash[:store_into_this_file] = 'snapcraft.yaml' 
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 404
def run
  programs?.each {|this_program|
    reset
    try_to_find_corresponding_program(this_program) # <- Must come first as it sets the @dataset variable.
    set_name_of_this_individual_program(this_program)
    set_store_into_this_file(
      this_program+'-'+program_version?+'-snapcraft'
    )
    notify_the_user_that_we_will_create_a_new_snapcraft_file_next(
      this_program
    )
    add_everything
    generate_the_snapcraft_file
  }
end
set_name_of_this_individual_program(i) click to toggle source
#

set_name_of_this_individual_program

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 270
def set_name_of_this_individual_program(i)
  @name_of_this_individual_program = i
end
set_program_name(i = '') click to toggle source
#

set_program_name

Denote onto which program we will work on.

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 85
def set_program_name(i = '')
  if i.nil?
    opne 'Please provide a valid name for a program to this class.'
    exit
  end
  i = [i].flatten.compact
  if i.first.is_a?(String) and i.first.include?(',')
    i = i.map {|entry|
      if entry.include? ','
        entry = entry.split(',')
      end
      entry
    }.flatten.compact
  end
  @program_name = i
end
set_store_into_this_file(i) click to toggle source
#

set_store_into_this_file

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 74
def set_store_into_this_file(i)
  i = i.dup if i.frozen?
  i << '.yaml' unless i.end_with? '.yaml'
  @internal_hash[:store_into_this_file] = i
end
short_desc?() click to toggle source
#

short_desc?

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 238
def short_desc?
  _ = @dataset.short_desc?
  if _.size > 66
    _ = _[0 .. 60] # Truncate it in this case.
  end
  return _
end
short_name?() click to toggle source
#

short_name?

Tap into @dataset to find out the short name of the program at hand.

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 179
def short_name?
  @dataset.short_name?
end
try_to_find_corresponding_program( program_name = program_name? ) click to toggle source
#

try_to_find_corresponding_program

This method attempts to find a corresponding entry from the individual yaml files.

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 153
def try_to_find_corresponding_program(
    program_name = program_name?
  )
  @dataset = action(:SanitizeCookbook, program_name) { :fast }
end
what?() click to toggle source
#

what?

#
# File lib/rbt/generate_files/create_snapcraft_file.rb, line 136
def what?
  @snapcraft_file_content
end