Module: Squared::Workspace::Git
- Included in:
- Application
- Defined in:
- lib/squared/workspace/project/git.rb
Instance Attribute Summary collapse
-
#revfile ⇒ Object
readonly
Returns the value of attribute revfile.
Instance Method Summary collapse
- #git(name, uri = nil, base: nil, repo: [], options: {}, cache: nil) ⇒ Object
- #git_clone?(path, name = nil) ⇒ Boolean
- #git_repo(name) ⇒ Object
- #rev_clear(name) ⇒ Object
- #rev_entry(*keys, val: nil, create: true) ⇒ Object
- #rev_timesince(*keys, clock: false) ⇒ Object
- #rev_timeutc(*keys) ⇒ Object
- #rev_write(name = nil, data = nil, utc: nil) ⇒ Object
- #revbuild(file: nil) ⇒ Object
Instance Attribute Details
#revfile ⇒ Object (readonly)
Returns the value of attribute revfile.
14 15 16 |
# File 'lib/squared/workspace/project/git.rb', line 14 def revfile @revfile end |
Instance Method Details
#git(name, uri = nil, base: nil, repo: [], options: {}, cache: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 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 67 68 69 70 |
# File 'lib/squared/workspace/project/git.rb', line 16 def git(name, uri = nil, base: nil, repo: [], options: {}, cache: nil) data = {} check = ->(proj) { proj.is_a?(Project::Git) && !proj.exclude?(Project::Git.ref) && git_clone?(proj.path) } if uri.is_a?(Array) base = name uri.each { |val| repo << proj if (proj = @project[val.to_s]) && check.(proj) } elsif uri data[name.to_s] = uri elsif name.is_a?(Enumerable) data = name.to_h elsif name.is_a?(String) && name.match?(GIT_PROTO) base = name @project.each_value { |proj| repo << proj if !proj.parent && check.(proj) } else warn (Logger::WARN, name, subject: 'git', hint: 'invalid', pass: true) if warning return self end if base base = base.match?(GIT_PROTO) ? "#{base.chomp('/')}/" : @root.join(base) repo.each do |target| if target.is_a?(Project::Git) data[target.localname] = target.project else data[target.to_s] = nil end end end data.each do |key, val| if val.is_a?(Hash) uri = val.fetch(:uri, '') opts = val.fetch(:options, {}) else uri = val.is_a?(String) ? val : key.to_s opts = end unless uri.match?(GIT_PROTO) || Pathname.new(uri).absolute? if uri.start_with?('.') uri = @root.join(uri) elsif base uri = base.is_a?(Pathname) ? base.join(uri) : base + uri else next end end key = task_name(key) (GIT_REPO[main] ||= {})[key] = [uri.to_s, opts] (@kind[key] ||= []) << Project::Git end if cache == true revbuild elsif cache revbuild(file: cache) end self end |
#git_clone?(path, name = nil) ⇒ Boolean
135 136 137 138 139 |
# File 'lib/squared/workspace/project/git.rb', line 135 def git_clone?(path, name = nil) return false if name && !git_repo(name) !path.exist? || path.empty? end |
#git_repo(name) ⇒ Object
84 85 86 |
# File 'lib/squared/workspace/project/git.rb', line 84 def git_repo(name) (ret = GIT_REPO[main]) && ret[name] end |
#rev_clear(name) ⇒ Object
118 119 120 121 122 123 |
# File 'lib/squared/workspace/project/git.rb', line 118 def rev_clear(name) if Dir.exist?(name) && (proj = find(name)) name = proj.name end rev_write if rev_entry(name, 'revision', val: '', create: false) end |
#rev_entry(*keys, val: nil, create: true) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/squared/workspace/project/git.rb', line 88 def rev_entry(*keys, val: nil, create: true) return unless @revdoc return @revdoc.dig(*keys) unless val data = @revdoc last = keys.pop for key in keys if data[key].is_a?(Hash) data = data[key] elsif create data = data[key] = {} else return end end data[last] = val end |
#rev_timesince(*keys, clock: false) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/squared/workspace/project/git.rb', line 110 def rev_timesince(*keys, clock: false) epoch = rev_timenow - rev_entry(*keys).to_i rescue StandardError nil else time_format(epoch, clock: clock) end |
#rev_timeutc(*keys) ⇒ Object
106 107 108 |
# File 'lib/squared/workspace/project/git.rb', line 106 def rev_timeutc(*keys) rev_entry(*keys, val: rev_timenow) end |
#rev_write(name = nil, data = nil, utc: nil) ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/squared/workspace/project/git.rb', line 125 def rev_write(name = nil, data = nil, utc: nil) return unless @revfile if name data&.each { |key, val| rev_entry(name, key, val: val) } rev_timeutc(name, utc) if utc end File.write(@revfile, JSON.pretty_generate(@revdoc)) end |
#revbuild(file: nil) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/squared/workspace/project/git.rb', line 72 def revbuild(file: nil) @revfile = @home.join(file || "#{@main}.revb") @revdoc = JSON.parse(@revfile.read) if @revfile.exist? rescue StandardError => e @revfile = nil warn (Logger::WARN, e, pass: true) if @warning self else @revdoc = {} unless @revdoc.is_a?(Hash) self end |