Sha256: 42c8df9f0a2e639f26d83244d992a104652812576dd17d99391cb9181a2ad4de
Contents?: true
Size: 1.38 KB
Versions: 1
Compression:
Stored size: 1.38 KB
Contents
require 'jbuilder' # Generated code class <%= @class_name %> < FWToolkit::Test::FrankModel # attributes attr_accessor <%= @model.attributes.map{|p| ":#{p.name.ruby_format}"}.join(', ') %> # relationships attr_reader <%= @model.relationships.select{|r| r.inverse != nil}.map{|r| ":#{r.name.ruby_format}"}.join(', ') %> def initialize @core_data_entity = '<%= @model.name %>' end # inverse relationship setters <% @model.relationships.select{|r| not r.to_many? and r.inverse}.each do |r| %><% name = r.name.ruby_format %> def <%= name %>=(_<%= name %>) @<%= name %> = _<%= name %> unless @<%= name %>.<%= r.inverse.ruby_format %> @<%= name %>.<%= r.inverse.ruby_format %> = [] end @<%= name %>.<%= r.inverse.ruby_format %> << self end <% end %> # lazy initialisation of to_many relationships <% @model.relationships.select{|r| r.to_many? and r.inverse}.each do |r| %><% name = r.name.ruby_format %> def <%= name %> @<%= name %> ||= [] end <% end %> def as_json(options={}) Jbuilder.encode do |json| json.<%= @model.name %> do <% @model.attributes.each do |a| %> json.<%= a.name %> self.<%= a.name.ruby_format %> <% end %> <% @model.relationships.select{|r| r.to_many? and r.inverse}.each do |r| %> json.<%= r.name %> self.<%= r.name.ruby_format %> do |obj| # fill out object properties end <% end %> end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fwtoolkit-0.5.0 | templates/models/model.rb.erb |