Module: Konstructor

Defined in:
lib/konstructor/main.rb,
lib/konstructor/factory.rb,
lib/konstructor/version.rb,
lib/konstructor/exceptions.rb,
lib/konstructor/simple_method_hook.rb,
lib/konstructor/konstructor_method_hook.rb

Defined Under Namespace

Modules: KonstructorMethod Classes: DeclaringInheritedError, Error, IncludingInModuleError, ReservedNameError

Constant Summary collapse

DEFAULT_NAMES =
[:initialize]
RESERVED_NAMES =
[:new, :initialize]
VERSION =
'1.0.1'

Class Method Summary collapse

Class Method Details

.declare(klass, new_method_names) ⇒ Object



91
92
93
94
# File 'lib/konstructor/main.rb', line 91

def declare(klass, new_method_names)
  setup_method_added_hook(klass)
  get_or_init_factory(klass).declare(new_method_names)
end

.declared?(klass, method_name) ⇒ Boolean

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.

Returns:

  • (Boolean)


82
83
84
85
86
87
88
89
# File 'lib/konstructor/main.rb', line 82

def declared?(klass, method_name)
  konstructor = get_factory(klass)
  if konstructor
    konstructor.declared?(method_name.to_sym)
  else
    false
  end
end

.default?(name) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/konstructor/main.rb', line 75

def default?(name)
  DEFAULT_NAMES.include?(name.to_sym)
end

.is?(klass, method_name) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/konstructor/main.rb', line 100

def is?(klass, method_name)
  default?(method_name) || declared?(klass, method_name)
end

.method_added_to_klass(klass, method_name) ⇒ Object



96
97
98
# File 'lib/konstructor/main.rb', line 96

def method_added_to_klass(klass, method_name)
  get_or_init_factory(klass).method_added_to_klass(method_name)
end

.reserved?(name) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/konstructor/main.rb', line 71

def reserved?(name)
  RESERVED_NAMES.include?(name.to_sym)
end