Module: Delineate::Schema

Extended by:
ActiveSupport::Concern
Included in:
AttributeMap
Defined in:
lib/delineate/schema.rb

Instance Method Summary collapse

Instance Method Details

#schema(access = nil, schema_classes = []) ⇒ Object

Returns a schema hash according to the attribute map. This information could be used to generate clients.

The schema hash has two keys: attributes and associations. The content for each varies depending on the access parameter which can take values of :read, :write, or nil. The attributes hash looks like this:

:read or :write   { :name => :string, :age => :integer }
:nil              { :name => {:type => :string, :access => :rw}, :age => { :type => :integer, :access => :rw} }

The associations hash looks like this:

:read or :write   { :posts => {}, :comments => {:optional => true} }
nil               { :posts => {:access => :rw}, :comments => {:optional => true, :access=>:ro} }

This method uses the columns_hash provided by ActiveRecord. You can implement that method in your models if you want to customize the schema output.



23
24
25
26
27
28
29
30
31
32
# File 'lib/delineate/schema.rb', line 23

def schema(access = nil, schema_classes = [])
  schema_classes.push(@klass_name)
  resolve

  attrs = schema_attributes(access)
  associations = schema_associations(access, schema_classes)

  schema_classes.pop
  {:attributes => attrs, :associations => associations}
end