Sha256: f320ed7132617ca2771dfb227949c35ec8feae9b1537db7924b0420b82a3689c
Contents?: true
Size: 1.16 KB
Versions: 27
Compression:
Stored size: 1.16 KB
Contents
# 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(', ') %> # 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={}) <% attributes_and_properties = @model.attributes + @model.relationships.select{|r| r.to_many? and r.inverse} %> {'<%= @model.name %>' => {<%= attributes_and_properties.map {|p| ":#{p.name} => self.#{p.name.ruby_format}"}.join(', ') %>}} end end
Version data entries
27 entries across 27 versions & 1 rubygems