Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/god.rb

Instance Method Summary collapse

Instance Method Details

#safe_attr_accessor(*args) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/god.rb', line 113

def safe_attr_accessor(*args)
  args.each do |arg|
    define_method((arg.to_s + "=").intern) do |other|
      if !self.running && self.inited
        abort "God.#{arg} must be set before any Tasks are defined"
      end
      
      if self.running && self.inited
        applog(nil, :warn, "God.#{arg} can't be set while god is running")
        return
      end
      
      instance_variable_set(('@' + arg.to_s).intern, other)
    end
    
    define_method(arg) do
      instance_variable_get(('@' + arg.to_s).intern)
    end
  end
end