Module: Datacraft::MethodDef

Extended by:
Forwardable
Defined in:
lib/datacraft/definition.rb

Overview

method management

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#mandatoryObject (readonly)

Returns the value of attribute mandatory.



15
16
17
# File 'lib/datacraft/definition.rb', line 15

def mandatory
  @mandatory
end

#optionalObject (readonly)

Returns the value of attribute optional.



15
16
17
# File 'lib/datacraft/definition.rb', line 15

def optional
  @optional
end

Instance Method Details

#def_mandatory(*methods) ⇒ Object



17
18
19
20
21
22
# File 'lib/datacraft/definition.rb', line 17

def def_mandatory(*methods)
  @mandatory = methods
  methods.each do |method|
    def_delegator :instance, method
  end
end

#def_optional(*methods) ⇒ Object



24
25
26
27
28
29
# File 'lib/datacraft/definition.rb', line 24

def def_optional(*methods)
  @optional = methods
  methods.each do |method|
    def_delegator :instance, method
  end
end

#validate_methods(klass) ⇒ Object



31
32
33
34
35
# File 'lib/datacraft/definition.rb', line 31

def validate_methods(klass)
  mandatory.each do |m|
    fail InvalidInstruction, "Class <#{klass}> missing mandatory methods: #{m}." unless klass.method_defined?(m)
  end
end