class Abyme::Model::AttributesBuilder
Public Class Methods
new(model, association, attributes, permit = true, association_class_name = nil)
click to toggle source
# File lib/abyme/model.rb, line 44 def initialize(model, association, attributes, permit = true, association_class_name = nil) @model = model @association = association @attributes_list = attributes @permit = permit @association_class = association_class_name&.safe_constantize || @association.to_s.classify.constantize end
Public Instance Methods
add_all_attributes()
click to toggle source
# File lib/abyme/model.rb, line 71 def add_all_attributes @association_class.column_names.map(&:to_sym).reject { |attr| [:id, :created_at, :updated_at].include?(attr) } end
build_all_attributes(authorized_attributes, nested_attributes)
click to toggle source
# File lib/abyme/model.rb, line 75 def build_all_attributes(authorized_attributes, nested_attributes) authorized_attributes += add_all_attributes authorized_attributes << nested_attributes unless nested_attributes.blank? || authorized_attributes.include?(nested_attributes) authorized_attributes end
build_attributes()
click to toggle source
# File lib/abyme/model.rb, line 52 def build_attributes nested_attributes = @association_class.abyme_attributes if @association_class.respond_to? :abyme_attributes authorized_attributes = build_default_attributes if @permit && @attributes_list == :all_attributes authorized_attributes = build_all_attributes(authorized_attributes, nested_attributes) elsif @permit @attributes_list << nested_attributes unless nested_attributes.blank? || @attributes_list.include?(nested_attributes) authorized_attributes += @attributes_list else authorized_attributes = build_all_attributes(authorized_attributes, nested_attributes) authorized_attributes -= @attributes_list end authorized_attributes end
build_default_attributes()
click to toggle source
# File lib/abyme/model.rb, line 81 def build_default_attributes attributes = [:id] attributes << :_destroy if destroy_allowed? attributes end
destroy_allowed?()
click to toggle source
# File lib/abyme/model.rb, line 67 def destroy_allowed? Abyme::Model.instance_variable_get(:@allow_destroy).dig(@model, @association) end