Class: Squared::Repo::Project::Base
- Inherits:
-
Object
- Object
- Squared::Repo::Project::Base
show all
- Extended by:
- Forwardable, Rake::DSL, Common::Task
- Includes:
- Rake::DSL, Shell, Common::System, Task
- Defined in:
- lib/squared/repo/project/base.rb
Direct Known Subclasses
Git
Constant Summary
collapse
- @@print_order =
0
- @@tasks =
{}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
collect_args, invoke, invoked?
#copy_d, #copy_f, #shell
Methods included from Common
#as_a, #finalize!, #get!, #message, #set!
Constructor Details
#initialize(name, project, workspace, **kwargs) ⇒ Base
Returns a new instance of Base.
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
71
72
73
74
75
76
77
78
79
|
# File 'lib/squared/repo/project/base.rb', line 44
def initialize(name, project, workspace, **kwargs)
@name = name.to_s
@path = workspace.root_path(project.to_s)
@project = @path.basename.to_s
@workspace = workspace
@group = kwargs[:group]&.to_s
@depend = kwargs[:depend]
@doc = kwargs[:doc]
@test = kwargs[:test]
@output = [kwargs[:run], nil]
@copy = kwargs[:copy]
@clean = kwargs[:clean]
log = kwargs[:log]
log = { file: log } unless log.is_a?(::Hash)
if (logfile = env('LOG_FILE')).nil? && (auto = env('LOG_AUTO'))
logfile = case auto
when 'y', 'year'
"#{@name}-#{Date.today.year}.log"
when 'm', 'month'
"#{@name}-#{Date.today.strftime('%Y-%m')}.log"
when 'd', 'day', '1'
"#{@name}-#{Date.today}.log"
end
end
if logfile ||= log[:file]
logfile = Date.today.strftime(logfile)
logfile = (dir = env('LOG_DIR')) ? Pathname.new(dir).join(logfile) : Pathname.new(logfile)
begin
logfile.realdirpath
rescue StandardError => e
logfile = nil
Warning.warn e
end
end
@logger = Logger.new(logfile, progname: @name, level: env('LOG_LEVEL') || log[:level] || Logger::INFO)
end
|
Instance Attribute Details
#group ⇒ Object
Returns the value of attribute group.
38
39
40
|
# File 'lib/squared/repo/project/base.rb', line 38
def group
@group
end
|
#name ⇒ Object
Returns the value of attribute name.
38
39
40
|
# File 'lib/squared/repo/project/base.rb', line 38
def name
@name
end
|
#path ⇒ Object
Returns the value of attribute path.
38
39
40
|
# File 'lib/squared/repo/project/base.rb', line 38
def path
@path
end
|
#project ⇒ Object
Returns the value of attribute project.
38
39
40
|
# File 'lib/squared/repo/project/base.rb', line 38
def project
@project
end
|
#workspace ⇒ Object
Returns the value of attribute workspace.
38
39
40
|
# File 'lib/squared/repo/project/base.rb', line 38
def workspace
@workspace
end
|
Class Method Details
.populate ⇒ Object
24
|
# File 'lib/squared/repo/project/base.rb', line 24
def populate(*); end
|
.tasks ⇒ Object
20
21
22
|
# File 'lib/squared/repo/project/base.rb', line 20
def tasks
[].freeze
end
|
.to_s ⇒ Object
26
27
28
|
# File 'lib/squared/repo/project/base.rb', line 26
def to_s
/[^:]+$/.match(super.to_s)[0]
end
|
.to_sym ⇒ Object
30
31
32
|
# File 'lib/squared/repo/project/base.rb', line 30
def to_sym
to_s.downcase.to_sym
end
|
Instance Method Details
#base_path(*args) ⇒ Object
209
210
211
|
# File 'lib/squared/repo/project/base.rb', line 209
def base_path(*args)
path.join(*args)
end
|
#build(*args) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/squared/repo/project/base.rb', line 127
def build(*args)
if args.empty?
cmd, opts = @output
opts &&= shell_escape(opts)
else
cmd = args.shift
opts = sanitize_args(*args)
end
if cmd
if opts
cmd = "#{cmd} #{opts}"
elsif cmd.is_a?(::Array)
cmd = cmd.join(' && ')
end
banner = verbose?
else
return unless respond_to?(:compose)
cmd = compose(opts)
banner = env('REPO_BUILD') == 'verbose'
end
run(cmd, exception: workspace.exception, banner: banner)
end
|
#build? ⇒ Boolean
233
234
235
|
# File 'lib/squared/repo/project/base.rb', line 233
def build?
!!@output[0]
end
|
#clean ⇒ Object
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
# File 'lib/squared/repo/project/base.rb', line 177
def clean
return unless @clean
if @clean.is_a?(::String)
run_s @clean
else
@clean.each do |val|
if (val = val.to_s).match?(%r{[\\/]$})
dir = Pathname.new(val)
dir = base_path(dir) unless dir.absolute?
next unless dir.directory?
warn "rm -rf #{dir}"
dir.rmtree(verbose: true)
else
files = val.include?('*') ? Dir[base_path(val)] : [base_path(val)]
files.each do |file|
begin
File.delete(file) if File.file?(file)
rescue StandardError => e
warn e
end
end
end
end
end
end
|
#clean? ⇒ Boolean
257
258
259
|
# File 'lib/squared/repo/project/base.rb', line 257
def clean?
!!@clean
end
|
#copy ⇒ Object
173
174
175
|
# File 'lib/squared/repo/project/base.rb', line 173
def copy(*)
run_s @copy
end
|
#copy? ⇒ Boolean
253
254
255
|
# File 'lib/squared/repo/project/base.rb', line 253
def copy?
@copy.is_a?(::String)
end
|
#depend ⇒ Object
161
162
163
|
# File 'lib/squared/repo/project/base.rb', line 161
def depend(*)
run(@depend, exception: workspace.exception) if @depend
end
|
#depend? ⇒ Boolean
241
242
243
|
# File 'lib/squared/repo/project/base.rb', line 241
def depend?
!!@depend
end
|
#doc ⇒ Object
165
166
167
|
# File 'lib/squared/repo/project/base.rb', line 165
def doc
build @doc if @doc
end
|
#doc? ⇒ Boolean
245
246
247
|
# File 'lib/squared/repo/project/base.rb', line 245
def doc?
!!@doc
end
|
#enabled? ⇒ Boolean
225
226
227
|
# File 'lib/squared/repo/project/base.rb', line 225
def enabled?
path.directory? && !path.empty?
end
|
#has?(method) ⇒ Boolean
229
230
231
|
# File 'lib/squared/repo/project/base.rb', line 229
def has?(method)
respond_to?(m = :"#{method}?") && __send__(m)
end
|
#initialize_build(ref, **kwargs) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/squared/repo/project/base.rb', line 81
def initialize_build(ref, **kwargs)
initialize_script(ref)
if (val = env('BUILD', strict: true))
@output[0] = val
elsif @script && @output[0] != false
@output[0] ||= @script[:run]
end
if env('BUILD', suffix: 'DEV', equals: '0')
@dev = false
else
@dev = kwargs.delete(:dev)
if env('BUILD', suffix: 'DEV')
@dev = true
elsif @dev.nil?
@dev = workspace.dev?
end
end
end
|
#initialize_script(ref) ⇒ Object
100
101
102
103
104
105
106
107
108
|
# File 'lib/squared/repo/project/base.rb', line 100
def initialize_script(ref)
return unless (script = workspace.script(group: group, ref: ref))
@depend = script[:depend] if @depend.nil?
@doc = script[:doc] if @doc.nil?
@test = script[:test] if @test.nil?
@clean = script[:clean] if @clean.nil?
@script = script
end
|
#inspect ⇒ Object
213
214
215
|
# File 'lib/squared/repo/project/base.rb', line 213
def inspect
"#<#{self.class}: #{name} => #{self}>"
end
|
#populate ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/squared/repo/project/base.rb', line 110
def populate(*)
namespace name do
workspace.series.each_key do |key|
case key
when :build, :refresh, :depend, :outdated, :doc, :test, :copy, :clean
next unless has?(key)
else
next unless workspace.task_defined?(self, key)
end
desc message(name, key)
task key do
__send__(key)
end
end
end
end
|
#refresh ⇒ Object
151
152
153
154
155
156
157
158
159
|
# File 'lib/squared/repo/project/base.rb', line 151
def refresh(*)
build
key = "#{name}:copy"
if ::Rake::Task.task_defined?(key)
invoke key
else
copy
end
end
|
#refresh? ⇒ Boolean
237
238
239
|
# File 'lib/squared/repo/project/base.rb', line 237
def refresh?
build? && (copy? || ::Rake::Task.task_defined?("#{name}:copy"))
end
|
#styles ⇒ Object
205
206
207
|
# File 'lib/squared/repo/project/base.rb', line 205
def styles
workspace.styles
end
|
#test ⇒ Object
169
170
171
|
# File 'lib/squared/repo/project/base.rb', line 169
def test
build @test if @test
end
|
#test? ⇒ Boolean
249
250
251
|
# File 'lib/squared/repo/project/base.rb', line 249
def test?
!!@test
end
|
#to_s ⇒ Object
217
218
219
|
# File 'lib/squared/repo/project/base.rb', line 217
def to_s
path.to_s
end
|
#to_sym ⇒ Object
221
222
223
|
# File 'lib/squared/repo/project/base.rb', line 221
def to_sym
name.to_sym
end
|