Module: Madeleine::Automatic::Interceptor
- Defined in:
- lib/madeleine/automatic.rb
Overview
should be made into commands
Class Method Summary collapse
-
.included(klass) ⇒ Object
keeping track of which methods are read only.
Instance Method Summary collapse
-
#read_only_methods ⇒ Object
Return the list of read only methods so Automatic_proxy#method_missing can find what to and what not to make into a command.
Class Method Details
.included(klass) ⇒ Object
keeping track of which methods are read only
74 75 76 77 78 79 80 81 82 83 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 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/madeleine/automatic.rb', line 74 def self.included(klass) class <<klass alias_method :_old_new, :new def new(*args, &block) @read_only_methods ||= [] Prox.new(_old_new(*args, &block)) end # # Called when a method added - remember symbol if read only # This is a good place to add in any superclass's read only methods also # def method_added(symbol) self.instance_eval { @read_only_methods ||= [] @auto_read_only_flag ||= false @read_only_methods << symbol if @auto_read_only_flag c = self while (c = c.superclass) if (c.instance_eval {instance_variables.include? "@read_only_methods"}) @read_only_methods |= c.instance_eval {@read_only_methods} end end } end # # Set the read only flag, or add read only methods # def automatic_read_only(*list) if (list == []) self.instance_eval {@auto_read_only_flag = true} else list.each {|s| self.instance_eval {@read_only_methods ||= []; @read_only_methods << s}} end end # # Clear the read only flag, or remove read only methods # def automatic_read_write(*list) if (list == []) self.instance_eval {@auto_read_only_flag = false} else list.each {|s| self.instance_eval {@read_only_methods ||= []; @read_only_methods.delete(s)}} end end end end |
Instance Method Details
#read_only_methods ⇒ Object
Return the list of read only methods so Automatic_proxy#method_missing can find what to and what not to make into a command
125 126 127 |
# File 'lib/madeleine/automatic.rb', line 125 def read_only_methods self.class.instance_eval {@read_only_methods} end |