class Redbreast::Command::Setup

Class for setting up the program

Public Class Methods

init(options = Commander::Command::Options.new) click to toggle source
# File lib/redbreast/commands/setup.rb, line 12
def self.init(options = Commander::Command::Options.new)
  new(options).call
end
new(options = Commander::Command::Options.new) click to toggle source
# File lib/redbreast/commands/setup.rb, line 16
def initialize(options = Commander::Command::Options.new)
  @options = options
end

Public Instance Methods

call() click to toggle source
# File lib/redbreast/commands/setup.rb, line 20
def call
  language = language_prompt
  app_name = app_name_prompt
  bundle_names = bundle_names_prompt(language).split(' ')
  assets_types = assets_types_prompt
  bundles = bundle_names.map do |bundle|
    reference = bundle_reference(bundle, language)
    assets_search_path = assets_search_path_prompt(bundle)
    output_source_path_images = assets_types == 1 ? nil : images_sources_path_prompt(bundle, language)
    output_source_path_colors = assets_types.zero? ? nil : colors_sources_path_prompt(bundle, language)
    include_tests = create_tests_path_prompt?(bundle)
    output_test_path_images = assets_types != 1 && include_tests ? images_tests_path_prompt(bundle, language) : nil
    output_test_path_colors = assets_types != 0 && include_tests ? colors_tests_path_prompt(bundle, language) : nil
    fields = {
      name: bundle,
      reference: reference,
      assetsSearchPath: assets_search_path,
      outputSourcePathImages: output_source_path_images,
      outputSourcePathColors: output_source_path_colors,
      outputTestPathImages: output_test_path_images,
      outputTestPathColors: output_test_path_colors,
      testableImport: include_tests ? testable_import_prompt(bundle, app_name, language) : nil
    }
    compact fields
  end
  config = {
    language: language,
    bundles: bundles,
    app_name: app_name
  }
  Redbreast::IO::Config.write(config)
  success
end

Private Instance Methods

app_name_prompt() click to toggle source

Application name propmt

# File lib/redbreast/commands/setup.rb, line 166
def app_name_prompt
  prompt.ask('Please enter application name')
end
assets_search_path_prompt(bundle) click to toggle source

Assets source path

# File lib/redbreast/commands/setup.rb, line 65
def assets_search_path_prompt(bundle)
  prompt_text = "Please enter assets folder search paths for bundle #{bundle}?"
  prompt.ask(prompt_text, default: '**/*.xcassets')
end
assets_types_prompt() click to toggle source

Assets type prompt

# File lib/redbreast/commands/setup.rb, line 172
def assets_types_prompt
  types = { 'Images' => 0, 'Colors' => 1, 'Both' => 2 }
  prompt.select('Choose a type: ', types)
end
bundle_names_prompt(language) click to toggle source

Bundle names promt

# File lib/redbreast/commands/setup.rb, line 72
def bundle_names_prompt(language)
  prompt_text = 'Please enter bundle names that you use separated by spaces'
  case language
  when 'objc'
    prompt.ask(prompt_text, default: 'mainBundle')
  when 'swift'
    prompt.ask(prompt_text, default: 'main')
  when 'swiftui'
    prompt.ask(prompt_text, default: 'main')
  end
end
bundle_reference(bundle_name, language) click to toggle source
# File lib/redbreast/commands/setup.rb, line 84
def bundle_reference(bundle_name, language)
  case language
  when 'objc'
    "[NSBundle #{bundle_name}]"
  when 'swift'
    ".#{bundle_name}"
  when 'swiftui'
    ".#{bundle_name}"
  end
end
colors_sources_path_prompt(bundle, language) click to toggle source

Colors source path

# File lib/redbreast/commands/setup.rb, line 111
def colors_sources_path_prompt(bundle, language)
  prompt_text = "Where would you like to store colors resources files for bundle #{bundle}?"
  case language
  when 'objc'
    prompt.ask(prompt_text, default: './Common/Categories/Colors')
  when 'swift'
    prompt.ask(prompt_text, default: './Common/Extensions/UIColorExtension.swift')
  when 'swiftui'
    prompt.ask(prompt_text, default: './Common/Extensions/ColorExtension.swift')
  end
end
colors_tests_path_prompt(bundle, language) click to toggle source
# File lib/redbreast/commands/setup.rb, line 141
def colors_tests_path_prompt(bundle, language)
  prompt_text = "Where would you like to store tests for bundle #{bundle}?"
  case language
  when 'objc'
    prompt.ask(prompt_text, default: './Common/Categories/ColorsTest')
  when 'swift'
    prompt.ask(prompt_text, default: './Common/Extensions/UIColorExtensionTest.swift')
  when 'swiftui'
    prompt.ask(prompt_text, default: './Common/Extensions/ColorExtensionTest.swift')
  end
end
create_tests_path_prompt?(bundle) click to toggle source

Tests

# File lib/redbreast/commands/setup.rb, line 125
def create_tests_path_prompt?(bundle)
  prompt.yes?("Would you like to create tests for bundle #{bundle}?")
end
images_sources_path_prompt(bundle, language) click to toggle source

Images source path

# File lib/redbreast/commands/setup.rb, line 97
def images_sources_path_prompt(bundle, language)
  prompt_text = "Where would you like to store images resources files for bundle #{bundle}?"
  case language
  when 'objc'
    prompt.ask(prompt_text, default: './Common/Categories/Images')
  when 'swift'
    prompt.ask(prompt_text, default: './Common/Extensions/UIImageExtension.swift')
  when 'swiftui'
    prompt.ask(prompt_text, default: './Common/Extensions/ImageExtension.swift')
  end
end
images_tests_path_prompt(bundle, language) click to toggle source
# File lib/redbreast/commands/setup.rb, line 129
def images_tests_path_prompt(bundle, language)
  prompt_text = "Where would you like to store tests for bundle #{bundle}?"
  case language
  when 'objc'
    prompt.ask(prompt_text, default: './Common/Categories/ImagesTest')
  when 'swift'
    prompt.ask(prompt_text, default: './Common/Extensions/UIImageExtensionTest.swift')
  when 'swiftui'
    prompt.ask(prompt_text, default: './Common/Extensions/ImageExtensionTest.swift')
  end
end
language_prompt() click to toggle source

Language

# File lib/redbreast/commands/setup.rb, line 58
def language_prompt
  languages = { 'Swift' => 'swift', 'SwiftUI' => 'swiftui', 'Objective-C' => 'objc', }
  prompt.select('Choose a language: ', languages)
end
testable_import_prompt(bundle, app_name, language) click to toggle source
# File lib/redbreast/commands/setup.rb, line 153
def testable_import_prompt(bundle, app_name, language)
  case language
  when 'objc'
    nil
  when 'swift'
    prompt.ask("Please enter a name that will be used for testable import in #{bundle} bundle?", default: "#{app_name}", required: true)
  when 'swiftui'
    prompt.ask("Please enter a name that will be used for testable import in #{bundle} bundle?", default: "#{app_name}", required: true)
  end
end