Class: Baleen::Project

Inherits:
Object
  • Object
show all
Includes:
Default
Defined in:
lib/baleen/project.rb

Constant Summary collapse

@@projects =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Default

#default_baleen_server, #default_before_command, #default_branch, #default_ci_port, #default_concurrency, #default_daemon, #default_dir, #default_docker_host, #default_docker_port, #default_features, #default_log_level, #default_port, #default_project_file, #default_work_dir

Constructor Details

#initialize(name, cfg) ⇒ Project

Returns a new instance of Project.



70
71
72
73
# File 'lib/baleen/project.rb', line 70

def initialize(name, cfg)
  @name = name
  load_config(cfg)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/baleen/project.rb', line 8

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/baleen/project.rb', line 8

def name
  @name
end

Class Method Details

.find_project(name, attribute, params = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/baleen/project.rb', line 33

def self.find_project(name, attribute, params={})
  projects = Baleen::Project.projects

  if name && attribute
    raise "You cannot specify name and attribute at the same time"
  elsif name
    return projects[name.to_sym]
  elsif attribute
    projects.each do |project, attributes|
      attributes.config.each do |attr, values|
        if attr == attribute
          params.each do |_k, _v|
            return nil unless values[_k] == _v
          end
          return projects[project]
        end
      end
    end
  end
end

.find_project_by_ci(params) ⇒ Object



58
59
60
# File 'lib/baleen/project.rb', line 58

def self.find_project_by_ci(params)
  find_project(nil, :ci, params)
end

.find_project_by_framework(params) ⇒ Object



66
67
68
# File 'lib/baleen/project.rb', line 66

def self.find_project_by_framework(params)
  find_project(nil, :framework, params)
end

.find_project_by_name(name) ⇒ Object



54
55
56
# File 'lib/baleen/project.rb', line 54

def self.find_project_by_name(name)
  find_project(name.to_sym, nil)
end

.find_project_by_runner(params) ⇒ Object



62
63
64
# File 'lib/baleen/project.rb', line 62

def self.find_project_by_runner(params)
  find_project(nil, :runner, params)
end

.load_project(config) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/baleen/project.rb', line 18

def self.load_project(config)
  if File.exists?(config)
    yaml = Baleen::Serializable.symbolize_keys(YAML.load_file(config))
  else
    hl_error "Config file not found"
    raise Baleen::Error::ConfigMissing
  end

  yaml.each do |project, cfg|
    if Baleen::Validation::Validator.check(cfg)
      @@projects[project] = self.new(project, cfg)
    end
  end
end

.projects(name = nil) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/baleen/project.rb', line 10

def self.projects(name=nil)
  if name
    @@projects[name.to_sym]
  else
    @@projects
  end
end

Instance Method Details

#branchObject



100
101
102
# File 'lib/baleen/project.rb', line 100

def branch
  ci[:branch]
end

#ciObject



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

def ci
  @config[:ci]
end

#imageObject



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

def image
  @config[:runner][:image]
end

#load_config(cfg) ⇒ Object



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

def load_config(cfg)
  if Baleen::Validation::Validator.check(cfg)
    cfg[:runner][:before_command] ||= default_before_command
    cfg[:runner][:concurrency]    ||= default_concurrency
    cfg[:runner][:work_dir]       ||= default_work_dir
    cfg[:runner][:image]

    case cfg[:framework][:type]
      when "cucumber"
        cfg[:framework][:files] = cfg[:framework][:features] || default_features
      else
        raise "Passed unknown framework from config yml: #{cfg[:framework][:type]}"
    end
  end
  @config = cfg
end

#repoObject



104
105
106
# File 'lib/baleen/project.rb', line 104

def repo
  ci[:repo]
end

#taskObject



112
113
114
115
116
117
118
119
120
121
# File 'lib/baleen/project.rb', line 112

def task
  Baleen::Task::Cucumber.new(
    image: @config[:runner][:image],
    work_dir: @config[:runner][:work_dir],
    options: @config[:framework][:options],
    files: @config[:framework][:files],
    before_command: @config[:runner][:before_command],
    concurrency: @config[:runner][:concurrency].to_i,
  )
end

#urlObject



108
109
110
# File 'lib/baleen/project.rb', line 108

def url
  ci[:url]
end