module Granite::Action::Subject
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/granite/action/subject.rb, line 34 def initialize(*args) if self.class._subject.blank? super return end reflection = self.class.reflect_on_association(self.class._subject) attributes = extract_initialize_attributes(args) subject_attributes = extract_subject_attributes!(attributes, reflection) assign_subject(args, subject_attributes, reflection) super attributes end
Private Instance Methods
assign_subject(args, attributes, reflection)
click to toggle source
# File lib/granite/action/subject.rb, line 59 def assign_subject(args, attributes, reflection) assign_attributes(attributes) self.subject = args.first unless args.empty? fail SubjectNotFoundError, self.class unless subject rescue ActiveData::AssociationTypeMismatch raise SubjectTypeMismatchError.new(self.class, args.first.class.name, reflection.klass) end
extract_initialize_attributes(args)
click to toggle source
# File lib/granite/action/subject.rb, line 51 def extract_initialize_attributes(args) if args.last.respond_to?(:to_unsafe_hash) args.pop.to_unsafe_hash else args.extract_options! end.symbolize_keys end
extract_subject_attributes!(attributes, reflection)
click to toggle source
# File lib/granite/action/subject.rb, line 68 def extract_subject_attributes!(attributes, reflection) attributes.extract!(:subject, :id, reflection.name, reflection.reference_key) end