Module: RSpecApi::Resource::HasAttribute

Included in:
RSpecApi::Resource
Defined in:
lib/rspec-api/resource/has_attribute.rb

Instance Method Summary collapse

Instance Method Details

#has_attribute(name, options, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rspec-api/resource/has_attribute.rb', line 7

def has_attribute(name, options, &block)
  if block_given?
    options[:type] = Hash[options[:type], {}]
    nest_attributes options[:type], &Proc.new
  end
  if @attribute_ancestors.present?
    hash = @attribute_ancestors.last
    hash.each{|type, _| (hash[type] ||= {})[name] = options}
  else
    (rspec_api_resource[:attributes] ||= {})[name] = options
  end
end