class BrainDamage::HasMany
Public Class Methods
new(options = {})
click to toggle source
# File lib/generators/brain_damage/lib/relation/has_many.rb, line 5 def initialize(options = {}) @options = options @name = @options[:field].name end
Public Instance Methods
model_lines()
click to toggle source
# File lib/generators/brain_damage/lib/relation/has_many.rb, line 10 def model_lines [relationship_line, nested_attributes_line, validates_associated_line ] end
nested_attributes_line()
click to toggle source
# File lib/generators/brain_damage/lib/relation/has_many.rb, line 19 def nested_attributes_line "accepts_nested_attributes_for :#{@name}, reject_if: proc { |attributes| attributes.values.uniq.first == '' }".indent unless @options[:skip_nested_form] end
relationship_line()
click to toggle source
# File lib/generators/brain_damage/lib/relation/has_many.rb, line 14 def relationship_line line = "has_many :#{@name}".indent add_options_to_line line, @options.slice(:class_name, :join_table, :as, :dependent, :foreign_key, :through) end
validates_associated_line()
click to toggle source
# File lib/generators/brain_damage/lib/relation/has_many.rb, line 23 def validates_associated_line "validates_associated :#{@name}".indent unless @options[:skip_nested_form] end
white_list()
click to toggle source
# File lib/generators/brain_damage/lib/relation/has_many.rb, line 27 def white_list if @options[:white_list] return ":#{@name.to_s.pluralize}_attributes => #{@options[:white_list].inspect}" else return ":#{@name.to_s.singularize}_ids => []" end end