Class: Omnitest::Project

Inherits:
Core::Dash
  • Object
show all
Includes:
Core::FileSystem, Core::Logging
Defined in:
lib/omnitest/project.rb

Defined Under Namespace

Classes: GitOptions

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Core::Dash

field, required_field

Instance Attribute Details

#basedirPathname

Attribute basedir.

Returns:

  • (Pathname)


18
# File 'lib/omnitest/project.rb', line 18

field :basedir, Pathname

#gitGitOptions

Attribute git.

Returns:



20
# File 'lib/omnitest/project.rb', line 20

field :git, GitOptions

#languageString

Attribute language.

Returns:

  • (String)


19
# File 'lib/omnitest/project.rb', line 19

field :language, String

#nameString

Attribute name.

Returns:

  • (String)


17
# File 'lib/omnitest/project.rb', line 17

field :name, String

#psychicObject

Returns the value of attribute psychic.



24
25
26
# File 'lib/omnitest/project.rb', line 24

def psychic
  @psychic
end

#skepticObject

Returns the value of attribute skeptic.



24
25
26
# File 'lib/omnitest/project.rb', line 24

def skeptic
  @skeptic
end

Instance Method Details

#bootstrapObject



92
93
94
# File 'lib/omnitest/project.rb', line 92

def bootstrap
  task('bootstrap', custom_banner: "Bootstrapping #{name}", fail_if_missing: false)
end

#cloneObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/omnitest/project.rb', line 46

def clone
  if git.nil? || git.repo.nil?
    logger.info 'Skipping clone because there are no git options'
    return
  end
  branch = git.branch ||= 'master'
  target_dir = git.to ||= basedir
  target_dir = Omnitest::Core::FileSystem.relativize(target_dir, Omnitest.basedir)
  if File.exist? target_dir
    logger.info "Skipping clone because #{target_dir} already exists"
  else
    clone_cmd = "git clone #{git.repo} -b #{branch} #{target_dir}"
    logger.info "Cloning: #{clone_cmd}"
    Omnitest.psychic.execute(clone_cmd)
  end
end

#cloned?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/omnitest/project.rb', line 96

def cloned?
  File.directory? basedir
end

#cwdPathname

Attribute basedir.

Returns:

  • (Pathname)


22
# File 'lib/omnitest/project.rb', line 22

field :basedir, Pathname

#execute(*args) ⇒ Object



34
35
36
# File 'lib/omnitest/project.rb', line 34

def execute(*args)
  psychic.execute(*args)
end

#loggerObject



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

def logger
  @logger ||= Omnitest.new_logger(self)
end

#task(task_name, opts = { fail_if_missing: true }) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/omnitest/project.rb', line 63

def task(task_name, opts = { fail_if_missing: true })
  banner_msg = opts[:custom_banner] || "Running task #{task_name} for #{name}"
  banner banner_msg
  fail "Project #{name} has not been cloned" unless cloned?
  psychic.task(task_name).execute
rescue Omnitest::Psychic::TaskNotImplementedError => e
  if opts[:fail_if_missing]
    logger.error("Could not run task #{task_name} for #{name}: #{e.message}")
    raise ActionFailed.new("Failed to run task #{task_name} for #{name}: #{e.message}", e)
  else
    logger.warn "Skipping #{task_name} for #{name}, no #{task_name} task exists"
  end
end

#workflow(workflow_name) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/omnitest/project.rb', line 77

def workflow(workflow_name)
  workflow_definition = Omnitest.configuration.project_set.workflows[workflow_name]
  fail UserError, "Workflow '#{workflow_name}' is not defined" if workflow_definition.nil?

  workflow = psychic.workflow(workflow_name) do
    workflow_definition.tasks.each do | task_name |
      task task_name
    end
  end

  workflow.execute
rescue Psychic::TaskNotImplementedError => e
  raise UserError, "Cannot run workflow '#{workflow_name}' for project '#{name}': #{e.message}"
end