Module: Hospodar::Builder::ClassMethods

Defined in:
lib/hospodar/builder.rb

Overview

DSL for describing objects schemas

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.__mf_assembler_name__Object

Returns the value of attribute mf_assembler_name.



62
63
64
# File 'lib/hospodar/builder.rb', line 62

def __mf_assembler_name__
  @__mf_assembler_name__
end

Class Method Details

.extended(receiver) ⇒ Object



69
70
71
72
# File 'lib/hospodar/builder.rb', line 69

def self.extended(receiver)
  receiver.produces :flatten_structs, :wrapped_structs, :nested_structs
  receiver.extend Helpers
end

.included(receiver) ⇒ Object



65
66
67
# File 'lib/hospodar/builder.rb', line 65

def self.included(receiver)
  receiver.extend self
end

Instance Method Details

#flat(title, base_class: Class.new(Object), init: nil, on_exception: nil, &block) ⇒ Object



86
87
88
89
90
# File 'lib/hospodar/builder.rb', line 86

def flat(title, base_class: Class.new(Object), init: nil, on_exception: nil, &block)
  flatten_struct(title, base_class: base_class.include(Exceptional), init: init)
  class_eval(&block)
  Flatten.new(self, on_exception).for(title, &block).inject_method
end

#nest(title, base_class: Class.new(Object), init: nil, delegate: false, on_exception: nil, &block) ⇒ Object



80
81
82
83
84
# File 'lib/hospodar/builder.rb', line 80

def nest(title, base_class: Class.new(Object), init: nil, delegate: false, on_exception: nil, &block)
  nested_struct(title, base_class: base_class.include(Exceptional), init: init)
  class_eval(&block)
  Nested.new(self, on_exception, delegate).for(title, &block).inject_method
end

#on_exception(&block) ⇒ Object



92
93
94
# File 'lib/hospodar/builder.rb', line 92

def on_exception(&block)
  block ? @on_exception = block : @on_exception
end

#wrap(title, base_class: Class.new(Object), init: nil, delegate: false, on_exception: nil, &block) ⇒ Object



74
75
76
77
78
# File 'lib/hospodar/builder.rb', line 74

def wrap(title, base_class: Class.new(Object), init: nil, delegate: false, on_exception: nil, &block)
  wrapped_struct(title, base_class: base_class.include(Exceptional), init: init)
  class_eval(&block)
  Wrapped.new(self, on_exception, delegate).for(title, &block).inject_method
end