lib/characterizable.rb in characterizable-0.0.11 vs lib/characterizable.rb in characterizable-0.0.12

- old
+ new

@@ -7,15 +7,13 @@ active_support/core_ext/class/attribute_accessors active_support/core_ext/object/blank active_support/core_ext/array/wrap active_support/core_ext/module/aliasing active_support/core_ext/module/delegation - active_support/json }.each do |active_support_3_requirement| require active_support_3_requirement end if ActiveSupport::VERSION::MAJOR == 3 -require 'to_json_fix' module Characterizable def self.included(klass) klass.cattr_accessor :characterizable_base klass.extend ClassMethods @@ -123,19 +121,23 @@ Blockenspiel.invoke block, characterizable_base end delegate :characteristics, :to => :characterizable_base end + class CharacteristicAlreadyDefined < ArgumentError + end + class Base attr_reader :klass def initialize(klass) @klass = klass end def characteristics @_characteristics ||= BetterHash.new end include Blockenspiel::DSL def has(name, options = {}, &block) + raise CharacteristicAlreadyDefined, "The characteristic #{name} has already been defined on #{klass}!" if characteristics.has_key?(name) characteristics[name] = Characteristic.new(self, name, options, &block) begin # quacks like an activemodel klass.define_attribute_methods if klass.respond_to?(:attribute_methods_generated?) and !klass.attribute_methods_generated? rescue