Class: GithubSnapBuilder::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/github_snap_builder/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(config_file_contents) ⇒ Config

Returns a new instance of Config.



7
8
9
# File 'lib/github_snap_builder/config.rb', line 7

def initialize(config_file_contents)
	@config = YAML.safe_load(config_file_contents) || {}
end

Instance Method Details

#bindObject



31
32
33
# File 'lib/github_snap_builder/config.rb', line 31

def bind
	@config.fetch('bind', '0.0.0.0')
end

#build_typeObject



23
24
25
# File 'lib/github_snap_builder/config.rb', line 23

def build_type
	@config['build_type']
end

#github_app_idObject



15
16
17
# File 'lib/github_snap_builder/config.rb', line 15

def github_app_id
	@config['github_app_id']
end

#github_app_private_keyObject



19
20
21
# File 'lib/github_snap_builder/config.rb', line 19

def github_app_private_key
	@config['github_app_private_key']
end

#github_webhook_secretObject



11
12
13
# File 'lib/github_snap_builder/config.rb', line 11

def github_webhook_secret
	@config['github_webhook_secret']
end

#portObject



27
28
29
# File 'lib/github_snap_builder/config.rb', line 27

def port
	@config.fetch('port', 3000)
end

#repo(repo_name) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/github_snap_builder/config.rb', line 43

def repo(repo_name)
	repos.each do | repo |
		if repo.name == repo_name
			return repo
		end
	end
end

#reposObject



35
36
37
# File 'lib/github_snap_builder/config.rb', line 35

def repos
	@repos ||= initialize_repos
end

#repos_include?(repo_name) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/github_snap_builder/config.rb', line 39

def repos_include?(repo_name)
	@config.fetch('repos', {}).include? repo_name
end

#valid?Boolean

Returns:

  • (Boolean)


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/github_snap_builder/config.rb', line 81

def valid?
	begin
		validate
	rescue ConfigurationError
		return false
	end

	begin
		repos.each do | repo |
			repo.validate
		end
	rescue ConfigurationError
		return false
	end

	true
end

#validateObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/github_snap_builder/config.rb', line 51

def validate
	if @config.nil? or @config.empty?
		raise ConfigurationError, "Config seems completely empty"
	end

	if github_webhook_secret.nil? || !github_webhook_secret.is_a?(String) || github_webhook_secret.empty?
		raise ConfigurationFieldError, "github_webhook_secret"
	end

	if github_app_id.nil? || !github_app_id.is_a?(Integer) || github_app_id == 0
		raise ConfigurationFieldError, "github_app_id"
	end

	if github_app_private_key.nil? || !github_app_private_key.is_a?(String) || github_app_private_key.empty?
		raise ConfigurationFieldError, "github_app_private_key"
	end

	if build_type.nil? || !build_type.is_a?(String) || build_type.empty? || !SnapBuilder.supported_build_types.include?(build_type)
		raise ConfigurationFieldError, "build_type"
	end

	if port.nil? || !port.is_a?(Integer) || port == 0
		raise ConfigurationFieldError, "port"
	end

	if bind.nil? || !bind.is_a?(String) || bind.empty?
		raise ConfigurationFieldError, "bind"
	end
end