Class: Module

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

Instance Method Summary collapse

Instance Method Details

#safe_attr_accessor(*args) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/god.rb', line 140

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