Class: Wizard::Spells::Base

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/wizard/spells/base.rb

Direct Known Subclasses

ExecuteShell, MakeDir, MakeFile

Constant Summary

Constants included from Helpers

Helpers::COLORS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#adjust, #colorize, #console_width, #print, #say, #say!

Class Method Details

.all_forced?Boolean

Should all actions be performed in force mode?

Returns:

  • (Boolean)


9
10
11
# File 'lib/wizard/spells/base.rb', line 9

def all_forced?
  defined?(@@force_all) and !!@@force_all
end

.attr_status(*statuses) ⇒ Object

Creates shortcuts for given statuses:

attr_status :my_status

will produce methods:

my_status! # => status!(:my_status)
my_status? # => status?(:my_status)


28
29
30
31
32
33
34
# File 'lib/wizard/spells/base.rb', line 28

def attr_status(*statuses)
  statuses.each do |status|
    define_method("#{status}!".to_sym) { status!(status.to_sym) }
    define_method("#{status}?".to_sym) { status?(status.to_sym) }
    protected "#{status}!".to_sym
  end
end

.force_all!Object

Set force mode for all apps. XXX. deadlocks can raise here.



15
16
17
# File 'lib/wizard/spells/base.rb', line 15

def force_all!
  @@force_all = true
end

Instance Method Details

#force!Object

Set force mode for current action.



67
68
69
# File 'lib/wizard/spells/base.rb', line 67

def force!
  @force = true
end

#force_all!Object

See Ryori::Makers::Base.force_all! for details.



62
63
64
# File 'lib/wizard/spells/base.rb', line 62

def force_all!
  self.class.force_all!
end

#forced?Boolean

Should be forced performing of current action?

Returns:

  • (Boolean)


57
58
59
# File 'lib/wizard/spells/base.rb', line 57

def forced?
  @force || self.class.all_forced?
end

#statusObject

Returns status of currently performed operation.



42
43
44
# File 'lib/wizard/spells/base.rb', line 42

def status
  @status
end

#status?(status) ⇒ Boolean

Returns true when actual status equals the given one.

status!(:success)
status?(:success) # => true
status?(:error)   # => false

Returns:

  • (Boolean)


52
53
54
# File 'lib/wizard/spells/base.rb', line 52

def status?(status)
  self.status == status.to_sym
end