lib/torque/postgresql/attributes/builder/enum.rb in torque-postgresql-1.0.1 vs lib/torque/postgresql/attributes/builder/enum.rb in torque-postgresql-1.1.0

- old
+ new

@@ -1,19 +1,22 @@ module Torque module PostgreSQL module Attributes module Builder class Enum + VALID_TYPES = %i[enum enum_set].freeze + attr_accessor :klass, :attribute, :subtype, :options, :values, :enum_module # Start a new builder of methods for enum values on ActiveRecord::Base - def initialize(klass, attribute, subtype, options) + def initialize(klass, attribute, options) @klass = klass @attribute = attribute.to_s - @subtype = subtype + @subtype = klass.attribute_types[@attribute] @options = options + raise Interrupt unless subtype.respond_to?(:klass) @values = subtype.klass.values if @options[:only] @values &= Array(@options[:only]).map(&:to_s) end @@ -47,25 +50,23 @@ end # Check if any of the methods that will be created get in conflict # with the base class methods def conflicting? - return false if options[:force] == true + return if options[:force] == true attributes = attribute.pluralize dangerous?(attributes, true) dangerous?("#{attributes}_options", true) dangerous?("#{attributes}_texts", true) dangerous?("#{attribute}_text") values_methods.each do |attr, list| list.map(&method(:dangerous?)) end - - return false rescue Interrupt => err raise ArgumentError, <<-MSG.squish - #{subtype.class.name} was not able to generate requested + Enum #{subtype.name} was not able to generate requested methods because the method #{err} already exists in #{klass.name}. MSG end