squared 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,19 +8,22 @@ module Squared
8
8
  include ::Rake::DSL
9
9
  extend Forwardable
10
10
 
11
- attr_reader :workspace, :sync, :multiple, :parallel
11
+ TASK_BASE = %i[build refresh depend outdated doc test copy clean].freeze
12
+ TASK_KEYS = TASK_BASE.dup
13
+ TASK_EXTEND = {}
14
+ private_constant :TASK_BASE, :TASK_KEYS, :TASK_EXTEND
15
+
16
+ def self.add(task, obj)
17
+ TASK_KEYS << task unless TASK_KEYS.include?(task)
18
+ (TASK_EXTEND[task] ||= []).push(obj)
19
+ end
12
20
 
13
- def_delegators :@data, :[], :each, :each_key, :keys, :fetch, :to_a, :to_s, :inspect, :merge!, :key?, :has_key?
21
+ attr_reader :sync, :multiple, :parallel
14
22
 
15
- def initialize(tasks, workspace, keys: Workspace::Application::WORKSPACE_KEYS)
16
- if tasks.is_a?(Array)
17
- @data = {}
18
- tasks.each { |key| __set__ key }
19
- else
20
- @data = tasks.dup
21
- end
22
- @workspace = workspace
23
- @keys = keys
23
+ def_delegators :@data, :[], :each, :each_key, :keys, :fetch, :to_a, :to_s, :inspect, :merge!, :key?
24
+
25
+ def initialize(prefix = nil)
26
+ @prefix = prefix
24
27
  @sync = []
25
28
  @multiple = []
26
29
  @parallel = []
@@ -29,67 +32,65 @@ module Squared
29
32
  parent: {},
30
33
  id: []
31
34
  }
35
+ @data = {}
36
+ TASK_KEYS.each { |key| @data[key] = [] }
32
37
  end
33
38
 
34
39
  def __set__(key)
35
40
  self[key.to_sym] ||= []
36
41
  end
37
42
 
38
- def populate(proj)
43
+ def __populate__(proj)
39
44
  return unless @session
40
45
 
41
46
  group, parent, id = @session.values
47
+ ws = proj.workspace
42
48
  each do |key, items|
43
- target = "#{proj.name}:#{key}"
44
- if @keys.include?(key)
45
- next unless proj.has?(key) || (target = workspace.task_base?(key, target))
46
- else
47
- next unless workspace.task_include?(proj, key)
48
- end
49
+ task = "#{proj.name}:#{key}"
50
+ next if include?(key) ? !proj.has?(key) && !(task = ws.task_base?(key, task)) : !ws.task_extend?(proj, key)
51
+ next unless ws.task_defined?(task)
52
+
49
53
  if (g = proj.group)
50
54
  id << g
51
- (group[:"#{key}:#{g}"] ||= []).push(target)
55
+ (group[:"#{key}:#{g}"] ||= []).push(task)
52
56
  else
53
- items << target
57
+ items << task
54
58
  end
55
- next unless (b = find_base(proj)) && (name = b.to_sym.to_s) != g
59
+ next unless (b = ws.find_base(proj)) && (name = b.ref.to_s) != g
56
60
 
57
61
  id << name
58
- (parent[:"#{key}:#{name}"] ||= []).push(target)
62
+ (parent[:"#{key}:#{name}"] ||= []).push(task)
59
63
  end
60
64
  end
61
65
 
62
- def method_missing(key, *)
63
- self[key]
64
- end
65
-
66
- def finalize!(thread = [])
67
- thread.map!(&:to_s)
66
+ def __build__(parallel: [], **)
68
67
  group, parent, id = @session.values
69
68
  merge!(parent) if id.uniq.size > 1
70
69
  merge!(group)
71
70
  each do |key, items|
72
71
  next if items.empty?
73
72
 
74
- key = key.to_s
73
+ name = key.to_s
74
+ key = @prefix ? "#{@prefix}:#{name}" : name
75
+ val = key.split(':').join(' => ')
75
76
  if items.size > 1
76
- multiple << key
77
- if thread.include?(key) || (key.include?(':') && thread.include?(key.split(':').first.to_sym))
78
- desc "#{key} (thread)"
77
+ @multiple << key
78
+ if parallel.include?(name) || (name.include?(':') && parallel.include?(name.split(':').first.to_sym))
79
+ desc "#{val} (thread)"
79
80
  multitask key => items
80
- parallel << key
81
+ @parallel << key
81
82
 
82
- desc "#{key} (sync)"
83
- task "#{key}:sync": items
84
- sync << "#{key}:sync"
85
- multiple << "#{key}:sync"
83
+ desc "#{val} (sync)"
84
+ task "#{key}:sync" => items
85
+ @sync << "#{key}:sync"
86
86
  next
87
87
  end
88
88
  end
89
89
 
90
- desc key
90
+ desc val
91
91
  task key => items
92
92
  end
93
+ @multiple += sync
93
94
  @session = nil
94
95
  end
95
96
 
@@ -97,6 +98,14 @@ module Squared
97
98
  !key.nil? && key?(key = key.to_sym) && !self[key].empty?
98
99
  end
99
100
 
101
+ def include?(key)
102
+ TASK_BASE.include?(key)
103
+ end
104
+
105
+ def extend?(obj, key)
106
+ TASK_EXTEND.fetch(key, []).any? { |kind| obj.is_a?(kind) && obj.ref?(kind.ref) }
107
+ end
108
+
100
109
  def multiple?(val = nil)
101
110
  already_invoked?(multiple, val)
102
111
  end
@@ -109,14 +118,16 @@ module Squared
109
118
  already_invoked?(parallel, val)
110
119
  end
111
120
 
112
- def respond_to_missing?(key, *)
113
- key?(key)
114
- end
115
-
116
121
  private
117
122
 
123
+ def method_missing(key, *)
124
+ raise NoMethodError, key unless key?(key)
125
+
126
+ self[key]
127
+ end
128
+
118
129
  def already_invoked?(list, val)
119
- return list.include?(val) && invoked?(val) if val
130
+ return list.include?(val) && Common::Task.invoked?(val) if val
120
131
 
121
132
  ::Rake::Task.tasks.any? { |item| item.already_invoked && list.include?(item.name) }
122
133
  end
@@ -5,12 +5,14 @@ require_relative 'common'
5
5
  module Squared
6
6
  module Workspace
7
7
  class << self
8
+ include Common
9
+
8
10
  def resolve(*args)
9
11
  ret = args.map do |id|
10
12
  if id.is_a?(::Symbol)
11
13
  project id
12
14
  else
13
- (id = Pathname.new(id).realdirpath.to_s) rescue nil if id.is_a?(::String)
15
+ id = dirpath(id) if id.is_a?(::String)
14
16
  __get__(:project).find { |_, val| val.path.to_s == id.to_s }
15
17
  end
16
18
  end
@@ -21,7 +23,13 @@ module Squared
21
23
  ret = project(name)
22
24
  return ret if ret&.path&.directory?
23
25
 
24
- raise NoMethodError, "project is not initialized (#{name})"
26
+ raise NoMethodError, message('project is not initialized', hint: name)
27
+ end
28
+
29
+ def dirpath(val, absolute: true)
30
+ Pathname.new(val).realdirpath
31
+ rescue StandardError
32
+ absolute ? Pathname.pwd.join(val) : Pathname.new(val)
25
33
  end
26
34
 
27
35
  def project?(name)
@@ -37,6 +45,6 @@ module Squared
37
45
  end
38
46
  end
39
47
 
40
- require_relative 'workspace/application'
41
48
  require_relative 'workspace/series'
49
+ require_relative 'workspace/application'
42
50
  require_relative 'workspace/project'
data/squared.gemspec CHANGED
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_dependency "rake"
28
28
  spec.add_dependency "logger"
29
+ spec.add_dependency "rexml"
29
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-10 00:00:00.000000000 Z
11
+ date: 2024-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rexml
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: Rake task generator for managing multi-language workspaces.
42
56
  email:
43
57
  - anpham6@gmail.com