Sha256: e61aff70e6547468aa2378a1880a177b439d6fc71e507dcaa18f674239907d38
Contents?: true
Size: 1.22 KB
Versions: 6
Compression:
Stored size: 1.22 KB
Contents
# Generated code class <%= config[:class_name] %> < FWToolkit::Test::FrankModel # attributes attr_accessor <%= config[:model].attributes.map{|p| ":#{p.name.ruby_format}"}.join(', ') %> # relationships attr_reader <%= config[:model].relationships.select{|r| r.inverse != nil}.map{|r| ":#{r.name.ruby_format}"}.join(', ') %> # inverse relationship setters <% config[: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 <% config[: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 = config[:model].attributes + config[:model].relationships.select{|r| r.to_many? and r.inverse} %> {'<%= config[:model].name %>' => {<%= attributes_and_properties.map {|p| ":#{p.name} => self.#{p.name.ruby_format}"}.join(', ') %>}} end end
Version data entries
6 entries across 6 versions & 1 rubygems