Module: ShatteredPack::PreInitialize::InstanceMethods
- Defined in:
- lib/shattered_pack/pre_initialize/pre_initialize.rb
Instance Method Summary collapse
-
#call_object_function(actor, action, params, evaluate_symbols = true) ⇒ Object
TODO: This is bad - this method needs to be refactored and/or nuked.
- #call_object_function_for_each_key(actor, options, evaluate_symbols = true) ⇒ Object
-
#each_init_value(name) ⇒ Object
Used in pre_initialize.
-
#pre_initialize(options) ⇒ Object
This function is called after an object is allocated, but before it’s initialized.
-
#pre_initialize_call ⇒ Object
Used in pre_initialize for before_init_call.
-
#pre_initialize_set ⇒ Object
Used in pre_initialize for before_init_set.
Instance Method Details
#call_object_function(actor, action, params, evaluate_symbols = true) ⇒ Object
TODO: This is bad - this method needs to be refactored and/or nuked.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/shattered_pack/pre_initialize/pre_initialize.rb', line 84 def call_object_function(actor, action, params, evaluate_symbols=true) begin if params.is_a?(Symbol) && evaluate_symbols params = eval(params.to_s) end rescue NameError puts "It is not advisable to pass #{params.inspect} to #{action.inspect} for #{actor.inspect}." puts " It will try to be evaluated. Use a string instead." end begin if(actor.is_a?(String) || actor.is_a?(Symbol)) sendee = eval(actor.to_s) else sendee = actor end if(params.is_a? Array) sendee.send( action.to_sym, *params ) else sendee.send( action.to_sym, params ) end rescue NoMethodError, ArgumentError => bang ="Error upon #{actor.to_s}.send(#{action.to_sym.inspect}, #{params.inspect}):\n\r #{bang.class}: \n\r\t #{bang.}\n\r #{bang.backtrace[0]}\n\r" bang = ShatteredPack::RetossError.new(bang,) raise bang end end |
#call_object_function_for_each_key(actor, options, evaluate_symbols = true) ⇒ Object
77 78 79 80 81 |
# File 'lib/shattered_pack/pre_initialize/pre_initialize.rb', line 77 def call_object_function_for_each_key( actor, , evaluate_symbols=true ) .each_pair do |action, params| call_object_function actor, "#{action}=", params, evaluate_symbols end end |
#each_init_value(name) ⇒ Object
Used in pre_initialize
55 56 57 58 59 60 61 |
# File 'lib/shattered_pack/pre_initialize/pre_initialize.rb', line 55 def each_init_value(name) #:nodoc: startup_attributes = self.class.read_inheritable_attribute( name ) || [] startup_attributes.each do |actor, | next if .nil? yield actor, end end |
#pre_initialize(options) ⇒ Object
This function is called after an object is allocated, but before it’s initialized.
See ShatteredPack::ClassMethods#before_init_call for usage.
47 48 49 50 51 52 |
# File 'lib/shattered_pack/pre_initialize/pre_initialize.rb', line 47 def pre_initialize() #:nodoc: pre_initialize_set pre_initialize_call # Set the options for new(...) without evaluating symbols call_object_function_for_each_key("self",, false) end |
#pre_initialize_call ⇒ Object
Used in pre_initialize for before_init_call
71 72 73 74 75 |
# File 'lib/shattered_pack/pre_initialize/pre_initialize.rb', line 71 def pre_initialize_call #:nodoc: each_init_value(BEFORE_INIT_CALL_VALUES) do |function, args| call_object_function( :self, function, args ) end end |
#pre_initialize_set ⇒ Object
Used in pre_initialize for before_init_set
64 65 66 67 68 |
# File 'lib/shattered_pack/pre_initialize/pre_initialize.rb', line 64 def pre_initialize_set #:nodoc: each_init_value(BEFORE_INIT_SET_VALUES) do |variable, | call_object_function_for_each_key( variable, ) end end |