module Konstructor
Constants
- DEFAULT_NAMES
- RESERVED_NAMES
- VERSION
Public Class Methods
declare(klass, new_method_names)
click to toggle source
# File lib/konstructor/main.rb, line 93 def declare(klass, new_method_names) setup_method_added_hook(klass) synchronize do get_or_init_factory(klass).declare(new_method_names) end end
declared?(klass, method_name)
click to toggle source
Once method is a konstructor, it is always a konstructor, this differs from the way private, protected works. If overriding method isn't repeatedly marked as private it becomes public.
# File lib/konstructor/main.rb, line 84 def declared?(klass, method_name) konstructor = get_factory(klass) if konstructor konstructor.declared?(method_name.to_sym) else false end end
default?(name)
click to toggle source
# File lib/konstructor/main.rb, line 77 def default?(name) DEFAULT_NAMES.include?(name.to_sym) end
is?(klass, method_name)
click to toggle source
# File lib/konstructor/main.rb, line 106 def is?(klass, method_name) default?(method_name) || declared?(klass, method_name) end
method_added_to_klass(klass, method_name)
click to toggle source
# File lib/konstructor/main.rb, line 100 def method_added_to_klass(klass, method_name) synchronize do get_or_init_factory(klass).method_added_to_klass(method_name) end end
reserved?(name)
click to toggle source
# File lib/konstructor/main.rb, line 73 def reserved?(name) RESERVED_NAMES.include?(name.to_sym) end
Private Class Methods
append_features(klass)
click to toggle source
Overriden append_features
prevents default behavior of including all the constants, variables to the base class. It adds only one method 'konstructor'.
# File lib/konstructor/main.rb, line 132 def append_features(klass) unless klass.is_a? Class raise IncludingInModuleError, klass end klass.extend(KonstructorMethod) end
get_factory(klass)
click to toggle source
# File lib/konstructor/main.rb, line 112 def get_factory(klass) klass.instance_variable_get(:@konstructor) end
get_or_init_factory(klass)
click to toggle source
# File lib/konstructor/main.rb, line 121 def get_or_init_factory(klass) get_factory(klass) || init_factory(klass) end
init_factory(klass)
click to toggle source
# File lib/konstructor/main.rb, line 116 def init_factory(klass) # using variable @konstructor to minimize footprint, although saving factory there klass.instance_variable_set(:@konstructor, Factory.new(klass)) end
setup_method_added_hook(klass)
click to toggle source
# File lib/konstructor/main.rb, line 125 def setup_method_added_hook(klass) SimpleMethodHook.setup(klass) end