Class: Docker::Template::Parser
- Inherits:
-
Object
- Object
- Docker::Template::Parser
- Defined in:
- lib/docker/template/parser.rb
Constant Summary collapse
- SLASH_REGEXP =
/\//- SPLIT_REGEXP =
/:|\//- COLON_REGEXP =
/:/
Class Method Summary collapse
-
.from_tag_to_repo_hash(val) ⇒ Object
–.
-
.full_name?(val) ⇒ Boolean
–.
-
.to_repo_hash(val) ⇒ Object
– rubocop:enable Metrics/AbcSize –.
Instance Method Summary collapse
-
#all ⇒ Object
– Return
raw_reposif you send us a list of repos you wish to build, otherwise we get the children of the repo folder and ship that off so you can build every repo, I don’t know if you want that. -
#initialize(raw_repos = [], argv = {}) ⇒ Parser
constructor
A new instance of Parser.
-
#parse ⇒ Object
– rubocop:disable Metrics/AbcSize –.
Constructor Details
#initialize(raw_repos = [], argv = {}) ⇒ Parser
Returns a new instance of Parser.
12 13 14 15 |
# File 'lib/docker/template/parser.rb', line 12 def initialize(raw_repos = [], argv = {}) @raw_repos = raw_repos @argv = argv end |
Class Method Details
.from_tag_to_repo_hash(val) ⇒ Object
–
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/docker/template/parser.rb', line 84 def self.from_tag_to_repo_hash(val) data = val.to_s.split(SPLIT_REGEXP) return "tag" => data[0] if data.one? return "name" => data[0], "tag" => data[1] if val =~ COLON_REGEXP && data.size == 2 return "user" => data[0], "name" => data[1] if val =~ SLASH_REGEXP && data.size == 2 return "user" => data[0], "name" => data[1], "tag" => data[2] if data.size == 3 {} end |
.full_name?(val) ⇒ Boolean
–
97 98 99 100 101 102 |
# File 'lib/docker/template/parser.rb', line 97 def self.full_name?(val) parsed = to_repo_hash(val) parsed.key?("name") && (parsed.key?("user") || parsed.key?( "tag" )) end |
.to_repo_hash(val) ⇒ Object
– rubocop:enable Metrics/AbcSize –
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/docker/template/parser.rb', line 71 def self.to_repo_hash(val) data = val.to_s.split(SPLIT_REGEXP) return "name" => data[0] if data.one? return "name" => data[0], "tag" => data[1] if val =~ COLON_REGEXP && data.size == 2 return "user" => data[0], "name" => data[1] if val =~ SLASH_REGEXP && data.size == 2 return "user" => data[0], "name" => data[1], "tag" => data[2] if data.size == 3 {} end |
Instance Method Details
#all ⇒ Object
– Return raw_repos if you send us a list of repos you wish to build, otherwise we get the children of the repo folder and ship that off so you can build every repo, I don’t know if you want that. –
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/docker/template/parser.rb', line 22 def all return @raw_repos unless @raw_repos.empty? return [Template.root.basename.to_s] if Template.project? Template.root.join(Meta.new({}).repos_dir).children.map do |path| path.basename.to_s end rescue Errno::ENOENT then raise( Error::RepoNotFound ) end |
#parse ⇒ Object
– rubocop:disable Metrics/AbcSize –
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/docker/template/parser.rb', line 38 def parse scratch = [] simple = [] aliases = [] all.each do |v| hash = self.class.to_repo_hash(v) raise Error::BadRepoName, v if hash.empty? Repo.new(hash, @argv).to_repos.each do |r| scratch << r if r.builder.scratch? && !r.alias? simple << r unless r.alias? || r.builder.scratch? aliases << r if r.alias? end end out = aliases.each_with_object(scratch | simple) do |alias_, repos| index = repos.rindex { |v| v.name == alias_.name } if index repos.insert(index + 1, alias_ ) else repos.push( alias_ ) end end end |