lib/assertion/guard.rb in assertion-0.1.0 vs lib/assertion/guard.rb in assertion-0.2.0
- old
+ new
@@ -30,34 +30,12 @@
# AdultOnly[john]
# # => #<User @name="John", @age=59>
#
class Guard
- extend Attributes
+ extend GuardDSL
- class << self
-
- # Initializes and guard for the provided object and calls it immediately
- #
- # @param [Object] object The object whose state should be tested
- #
- # @return (see #call)
- #
- # @raise (see #call)
- #
- def [](object)
- new(object).call
- end
-
- private
-
- def __forbidden_attributes__
- [:state]
- end
-
- end # eigenclass
-
# @!attribute [r] object
#
# @return [Object] The object whose state should be tested
#
attr_reader :object
@@ -71,11 +49,10 @@
# @return [Assertion::Guard]
# @private
def initialize(object)
@object = object
- self.class.attributes.each(&method(:__set_attribute__))
freeze
end
# Validates the state of the [#object] and returns valid object back
#
@@ -84,15 +61,9 @@
# @raise [Assertion::InvalidError] if the [#object] is invalid
#
def call
state.validate!
object
- end
-
- private
-
- def __set_attribute__(name)
- singleton_class.instance_eval { alias_method name, :object }
end
end # class Guard
end # module Assertion