Class: Mockolate::Request::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/mockolate/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ DSL

Returns a new instance of DSL.



39
40
41
42
# File 'lib/mockolate/request.rb', line 39

def initialize(options)
  @attributes = []
  @options    = options  
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(type, *args, &block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/mockolate/request.rb', line 49

def method_missing(type, *args, &block)
     = Mockolate::Register.get(type)
  field_name = args.first
  type_options    = args[1]
  
  attibute = .create(name: field_name, options: type_options)
  if block_given?
    attibute.children = Mockolate::Request.payload_parser(options, &block)
  end
  attributes << attibute
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



36
37
38
# File 'lib/mockolate/request.rb', line 36

def attributes
  @attributes
end

#optionsObject (readonly)

Returns the value of attribute options.



37
38
39
# File 'lib/mockolate/request.rb', line 37

def options
  @options
end

Instance Method Details

#hash(*args, &block) ⇒ Object



44
45
46
47
# File 'lib/mockolate/request.rb', line 44

def hash(*args, &block)
  raise Mockolate::Errors::MissingHashBlockError unless block_given?
  method_missing(:hash, *args, &block)
end