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

Version Path
fwtoolkit-0.9.3 templates/models/model.rb.erb
fwtoolkit-0.9.2 templates/models/model.rb.erb
fwtoolkit-0.9.1 templates/models/model.rb.erb
fwtoolkit-0.9.0 templates/models/model.rb.erb
fwtoolkit-0.8.7 templates/models/model.rb.erb
fwtoolkit-0.8.6 templates/models/model.rb.erb
fwtoolkit-0.8.5 templates/models/model.rb.erb
fwtoolkit-0.8.4 templates/models/model.rb.erb
fwtoolkit-0.8.3 templates/models/model.rb.erb
fwtoolkit-0.8.2 templates/models/model.rb.erb
fwtoolkit-0.8.1 templates/models/model.rb.erb
fwtoolkit-0.8.0 templates/models/model.rb.erb
fwtoolkit-0.7.3 templates/models/model.rb.erb
fwtoolkit-0.7.2 templates/models/model.rb.erb
fwtoolkit-0.7.1 templates/models/model.rb.erb
fwtoolkit-0.7.0 templates/models/model.rb.erb
fwtoolkit-0.6.6 templates/models/model.rb.erb
fwtoolkit-0.6.5 templates/models/model.rb.erb
fwtoolkit-0.6.4 templates/models/model.rb.erb
fwtoolkit-0.6.3 templates/models/model.rb.erb