Initialize things in the initialize method and define readers

This commit is contained in:
Santiago Pastorino 2013-05-15 16:13:26 -07:00
parent ea6d712cc8
commit eb5b27de69

View File

@ -3,29 +3,26 @@ module ActiveModel
module Associations #:nodoc:
class Base #:nodoc:
def initialize(name, options={}, serializer_options={})
@name = name
@name = name
@object = options[:value]
@embed = options[:embed]
@embed_key = options[:embed_key] || :id
@embed_in_root = options[:include]
@options = options
@serializer_options = serializer_options
end
def name
options[:name] || @name
end
def root
options[:root] || @name
end
attr_reader :root, :name, :embed_in_root
alias :embed_in_root? :embed_in_root
def embed_ids?
[:id, :ids].include? options[:embed]
[:id, :ids].include? embed
end
def embed_objects?
[:object, :objects].include? options[:embed]
end
def embed_in_root?
options[:include]
[:object, :objects].include? embed
end
def embeddable?
@ -34,17 +31,7 @@ module ActiveModel
private
def object
options[:value]
end
def embed_key
if key = options[:embed_key]
key
else
:id
end
end
attr_reader :object, :embed, :embed_key
def target_serializer
serializer = options[:serializer]
@ -75,6 +62,10 @@ module ActiveModel
end
end
def root
options[:root] || name
end
def id_key
"#{@name.to_s.singularize}_ids".to_sym
end