Method: Brief::Briefcase#as_default

Defined in:
lib/brief/briefcase.rb

#as_default(params = {}) ⇒ Object

TODO The serialization of an entire briefcase at once is important enough to be its own module



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/brief/briefcase.rb', line 75

def as_default(params={})
  params.symbolize_keys!

  base = info_hash

  if params[:include_data] || params[:data]
    base[:data] = data.as_json
  end

  if params[:include_schema] || params[:schema]
    base[:schema] = schema_map
  end

  if params[:include_documentation] || params[:documentation]
    base[:documentation] = render_documentation
  end

  if params[:include_models] || params[:models]
    model_settings = {
      docs_path: docs_path
    }

    %w(urls content rendered attachments).each do |opt|
      model_settings[opt.to_sym] = !!(params[opt.to_sym] || params["include_#{opt}".to_sym])
    end

    all = all_models.compact

    base[:models] = all.map do |m|
      m.document.refresh! if params[:refresh_models]
      m.as_json(model_settings)
    end
  end

  base
end