Class: Squared::Workspace::Application
- Inherits:
-
Object
- Object
- Squared::Workspace::Application
- Defined in:
- lib/squared/workspace/application.rb
Constant Summary
Constants included from Common
Class Attribute Summary collapse
-
.impl_project ⇒ Object
readonly
Returns the value of attribute impl_project.
-
.impl_series ⇒ Object
readonly
Returns the value of attribute impl_series.
Instance Attribute Summary collapse
-
#exception ⇒ Object
Returns the value of attribute exception.
-
#home ⇒ Object
readonly
Returns the value of attribute home.
-
#main ⇒ Object
readonly
Returns the value of attribute main.
-
#pipe ⇒ Object
Returns the value of attribute pipe.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#series ⇒ Object
readonly
Returns the value of attribute series.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
-
#warning ⇒ Object
Returns the value of attribute warning.
Class Method Summary collapse
Instance Method Summary collapse
- #add(path, name = nil, **kwargs, &blk) ⇒ Object
- #apply(&blk) ⇒ Object
- #banner(*order, command: true, styles: [], border: [], group: nil, ref: nil) ⇒ Object
- #build(**kwargs) {|_self| ... } ⇒ Object
- #clean(script, group: @group, ref: @ref) ⇒ Object
- #compose(name, &blk) ⇒ Object
- #depend(script, group: @group, ref: @ref) ⇒ Object
- #dev?(**kwargs) ⇒ Boolean
- #doc(script, group: @group, ref: @ref) ⇒ Object
- #enabled? ⇒ Boolean
- #env(key, default = nil, equals: nil, ignore: nil) ⇒ Object
- #exclude(base, group: @group, ref: @ref) ⇒ Object
- #find_base(obj) ⇒ Object
- #group(path, name, override: {}, **kwargs) ⇒ Object
- #home_path(*args) ⇒ Object
-
#initialize(home = Dir.pwd, main: nil, prefix: nil, verbose: nil, common: , pipe: , exception: ) ⇒ Application
constructor
A new instance of Application.
- #inspect ⇒ Object
- #log(script, group: @group, ref: @ref) ⇒ Object
- #prod?(**kwargs) ⇒ Boolean
- #root_path(*args) ⇒ Object
- #run(script, group: @group, ref: @ref) ⇒ Object
- #script(*args, group: nil, ref: nil) ⇒ Object
- #style(name, *args, target: nil, empty: false) ⇒ Object
- #task_defined?(key) ⇒ Boolean
- #task_extend?(obj, key) ⇒ Boolean
- #task_name(val, desc: false) ⇒ Object
- #task_namespace(val, first: false) ⇒ Object
- #test(script, group: @group, ref: @ref) ⇒ Object
- #to_s ⇒ Object
- #with(*val, &blk) ⇒ Object
Methods included from Repo
Constructor Details
#initialize(home = Dir.pwd, main: nil, prefix: nil, verbose: nil, common: , pipe: , exception: ) ⇒ Application
Returns a new instance of Application.
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 80 81 82 83 84 |
# File 'lib/squared/workspace/application.rb', line 53 def initialize(home = Dir.pwd, *, main: nil, prefix: nil, verbose: nil, common: Common::KEY[:COMMON], pipe: Common::KEY[:PIPE], exception: Common::KEY[:FAIL], **) @home = (home = Pathname.new(home)).realdirpath @main = (main || home.basename).to_s @root = @home.parent @prefix = prefix @series = Application.impl_series.new(self) @project = {} @extensions = [] @pipe = env_pipe(pipe) @exception = env_bool(exception) @verbose = verbose.nil? ? @pipe > 0 : verbose @warning = @verbose != false @envname = @main.gsub(/[^\w]+/, '_').upcase if common @theme = __get__(:theme)[:workspace] __set__(:no_color, true) if @pipe == 0 else @theme = {} end @script = { group: {}, ref: {}, group!: {}, ref!: {} }.freeze @banner = { group: {}, ref: {} }.freeze end |
Class Attribute Details
.impl_project ⇒ Object (readonly)
Returns the value of attribute impl_project.
44 45 46 |
# File 'lib/squared/workspace/application.rb', line 44 def impl_project @impl_project end |
.impl_series ⇒ Object (readonly)
Returns the value of attribute impl_series.
44 45 46 |
# File 'lib/squared/workspace/application.rb', line 44 def impl_series @impl_series end |
Instance Attribute Details
#exception ⇒ Object
Returns the value of attribute exception.
51 52 53 |
# File 'lib/squared/workspace/application.rb', line 51 def exception @exception end |
#home ⇒ Object (readonly)
Returns the value of attribute home.
50 51 52 |
# File 'lib/squared/workspace/application.rb', line 50 def home @home end |
#main ⇒ Object (readonly)
Returns the value of attribute main.
50 51 52 |
# File 'lib/squared/workspace/application.rb', line 50 def main @main end |
#pipe ⇒ Object
Returns the value of attribute pipe.
51 52 53 |
# File 'lib/squared/workspace/application.rb', line 51 def pipe @pipe end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
50 51 52 |
# File 'lib/squared/workspace/application.rb', line 50 def prefix @prefix end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
50 51 52 |
# File 'lib/squared/workspace/application.rb', line 50 def root @root end |
#series ⇒ Object (readonly)
Returns the value of attribute series.
50 51 52 |
# File 'lib/squared/workspace/application.rb', line 50 def series @series end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
50 51 52 |
# File 'lib/squared/workspace/application.rb', line 50 def theme @theme end |
#verbose ⇒ Object
Returns the value of attribute verbose.
51 52 53 |
# File 'lib/squared/workspace/application.rb', line 51 def verbose @verbose end |
#warning ⇒ Object
Returns the value of attribute warning.
51 52 53 |
# File 'lib/squared/workspace/application.rb', line 51 def warning @warning end |
Class Method Details
.find(ref = nil, path: nil) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/squared/workspace/application.rb', line 32 def find(ref = nil, path: nil) if ref && (ret = impl_project.find { |proj| proj.ref == ref.to_sym }) ret elsif path impl_project.find { |proj| proj.is_a?(path) } end end |
.implement(*objs) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/squared/workspace/application.rb', line 21 def implement(*objs) objs.each do |obj| if obj < Project::Base @impl_project.unshift(obj) obj.tasks&.each { |task| @impl_series.add(task, obj) } elsif obj < Workspace::Series @impl_series = obj end end end |
.to_s ⇒ Object
40 41 42 |
# File 'lib/squared/workspace/application.rb', line 40 def to_s super.to_s.match(/[^:]+$/)[0] end |
Instance Method Details
#add(path, name = nil, **kwargs, &blk) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/squared/workspace/application.rb', line 156 def add(path, name = nil, **kwargs, &blk) ref = if kwargs.key?(:ref) kwargs.delete(:ref) elsif @ref.is_a?(::Symbol) @ref end kwargs[:group] = @group if !kwargs.key?(:group) && @group.is_a?(::String) path = root_path(path) name ||= path.basename.to_s proj = ((if !ref.is_a?(::Class) Application.find(ref, path: path) elsif ref < Project::Base ref end) || Project::Base).new(task_name(name), path, self, **kwargs) @project[name = name.to_sym] = proj __get__(:project)[name] = proj unless kwargs[:private] proj.instance_eval(&blk) if block_given? self end |
#apply(&blk) ⇒ Object
201 202 203 204 |
# File 'lib/squared/workspace/application.rb', line 201 def apply(&blk) instance_eval(&blk) self end |
#banner(*order, command: true, styles: [], border: [], group: nil, ref: nil) ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/squared/workspace/application.rb', line 221 def (*order, command: true, styles: [], border: [], group: nil, ref: nil) if order.empty? return (group && @banner[:group][group.to_sym]) || (ref && @banner[:ref][ref]) || @banner[:ref][:_] end data = { command: command, order: [], styles: check_style(styles, empty: false), border: check_style(border) } order.flatten.each do |val| case (val = val.to_sym) when :name, :project, :path, :ref, :group data[:order] << val end end if command || !data[:order].empty? if group ||= @group label = :group items = as_a(group) else label = :ref items = as_a(ref || @ref || :_) end items.each { |val| @banner[label][val.to_sym] = data } end self end |
#build(**kwargs) {|_self| ... } ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/squared/workspace/application.rb', line 86 def build(**kwargs) kwargs[:parallel] = kwargs.fetch(:parallel, []).map(&:to_s) return unless enabled? @project.each_value do |proj| next unless proj.enabled? proj.populate(**kwargs) series.__populate__(proj) end Application.impl_project.each { |obj| obj.populate(self, **kwargs) } @extensions.each { |ext| __send__(ext, **kwargs) } series.__build__(**kwargs) __build__(**kwargs) yield self if block_given? end |
#clean(script, group: @group, ref: @ref) ⇒ Object
136 137 138 |
# File 'lib/squared/workspace/application.rb', line 136 def clean(script, group: @group, ref: @ref) script_command :clean, script, group, ref end |
#compose(name, &blk) ⇒ Object
196 197 198 199 |
# File 'lib/squared/workspace/application.rb', line 196 def compose(name, &blk) namespace(task_name(name), &blk) self end |
#depend(script, group: @group, ref: @ref) ⇒ Object
132 133 134 |
# File 'lib/squared/workspace/application.rb', line 132 def depend(script, group: @group, ref: @ref) script_command :depend, script, group, ref end |
#dev?(**kwargs) ⇒ Boolean
308 309 310 |
# File 'lib/squared/workspace/application.rb', line 308 def dev?(**kwargs) script?(:dev, **kwargs) end |
#doc(script, group: @group, ref: @ref) ⇒ Object
140 141 142 |
# File 'lib/squared/workspace/application.rb', line 140 def doc(script, group: @group, ref: @ref) script_command :doc, script, group, ref end |
#enabled? ⇒ Boolean
296 297 298 |
# File 'lib/squared/workspace/application.rb', line 296 def enabled? !@extensions.empty? || @project.values.any?(&:enabled?) end |
#env(key, default = nil, equals: nil, ignore: nil) ⇒ Object
258 259 260 261 262 263 |
# File 'lib/squared/workspace/application.rb', line 258 def env(key, default = nil, equals: nil, ignore: nil) ret = (ENV["#{key}_#{@envname}"] || ENV[key]).to_s return ret == equals.to_s unless equals.nil? ret.empty? || (ignore && as_a(ignore).any? { |val| ret == val.to_s }) ? default : ret end |
#exclude(base, group: @group, ref: @ref) ⇒ Object
152 153 154 |
# File 'lib/squared/workspace/application.rb', line 152 def exclude(base, group: @group, ref: @ref) script_command :exclude, as_a(base, :to_sym).freeze, group, ref end |
#find_base(obj) ⇒ Object
273 274 275 |
# File 'lib/squared/workspace/application.rb', line 273 def find_base(obj) Application.impl_project.find { |proj| obj.instance_of?(proj) } end |
#group(path, name, override: {}, **kwargs) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/squared/workspace/application.rb', line 176 def group(path, name, override: {}, **kwargs) root_path(path).children.map do |ent| next unless (dir = Pathname.new(ent)).directory? index = 0 basename = dir.basename.to_s.to_sym while @project[basename] index += 1 basename = :"#{basename}-#{index}" end [basename, dir, override[basename]] end .each do |basename, dir, opts| args = kwargs.dup args.merge!(opts) if opts add(basename, dir, group: name, **args) end self end |
#home_path(*args) ⇒ Object
269 270 271 |
# File 'lib/squared/workspace/application.rb', line 269 def home_path(*args) home.join(*args) end |
#inspect ⇒ Object
292 293 294 |
# File 'lib/squared/workspace/application.rb', line 292 def inspect "#<#{self.class}: #{main} => #{self}>" end |
#log(script, group: @group, ref: @ref) ⇒ Object
148 149 150 |
# File 'lib/squared/workspace/application.rb', line 148 def log(script, group: @group, ref: @ref) script_command :log, script, group, ref end |
#prod?(**kwargs) ⇒ Boolean
312 313 314 |
# File 'lib/squared/workspace/application.rb', line 312 def prod?(**kwargs) script?(:prod, **kwargs) end |
#root_path(*args) ⇒ Object
265 266 267 |
# File 'lib/squared/workspace/application.rb', line 265 def root_path(*args) root.join(*args) end |
#run(script, group: @group, ref: @ref) ⇒ Object
128 129 130 |
# File 'lib/squared/workspace/application.rb', line 128 def run(script, group: @group, ref: @ref) script_command :run, script, group, ref end |
#script(*args, group: nil, ref: nil) ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/squared/workspace/application.rb', line 246 def script(*args, group: nil, ref: nil) return @script[:group][group.to_sym] if group return @script[:ref][ref] if ref args.reverse_each do |val| next unless val && (ret = val.is_a?(::Symbol) ? @script[:ref!][val] : @script[:group!][val.to_sym]) return ret end @script[:ref][:_] || SCRIPT_OBJ end |
#style(name, *args, target: nil, empty: false) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/squared/workspace/application.rb', line 206 def style(name, *args, target: nil, empty: false) data = nil if target as_a(target).each_with_index do |key, i| if i == 0 break unless (data = __get__(:theme)[key.to_sym]) else data = data[key.to_sym] ||= {} end end end apply_style(data || theme, name, *args, empty: empty) unless target && !data self end |
#task_defined?(key) ⇒ Boolean
304 305 306 |
# File 'lib/squared/workspace/application.rb', line 304 def task_defined?(key, *) ::Rake::Task.task_defined?(key) end |
#task_extend?(obj, key) ⇒ Boolean
300 301 302 |
# File 'lib/squared/workspace/application.rb', line 300 def task_extend?(obj, key) series.extend?(obj, key) end |
#task_name(val, desc: false) ⇒ Object
277 278 279 280 |
# File 'lib/squared/workspace/application.rb', line 277 def task_name(val, desc: false) ret = @prefix ? "#{@prefix}:#{val}" : val.to_s desc ? ret.split(':').join(' => ') : ret end |
#task_namespace(val, first: false) ⇒ Object
282 283 284 285 286 |
# File 'lib/squared/workspace/application.rb', line 282 def task_namespace(val, first: false) return nil unless (ret = val.to_s.split(':')).size > 1 first ? ret.first : ret[0..-2].join(':') end |
#test(script, group: @group, ref: @ref) ⇒ Object
144 145 146 |
# File 'lib/squared/workspace/application.rb', line 144 def test(script, group: @group, ref: @ref) script_command :test, script, group, ref end |
#to_s ⇒ Object
288 289 290 |
# File 'lib/squared/workspace/application.rb', line 288 def to_s root.to_s end |
#with(*val, &blk) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/squared/workspace/application.rb', line 106 def with(*val, &blk) @group = nil @ref = nil kind = val.first val = kind if val.size == 1 case kind when ::String @group = val if block_given? instance_eval(&blk) @group = nil end when ::Symbol @ref = val if block_given? instance_eval(&blk) @ref = nil end end self end |