Permalink
Browse files

Go back to 100% doc coverage

  • Loading branch information...
1 parent 7ce6f99 commit 3615ab43ed42852b4448a408737889784b973467 @solnic committed Jun 8, 2012
View
8 lib/virtus.rb
@@ -16,7 +16,7 @@ module Virtus
# Represents an undefined parameter used by auto-generated option methods
Undefined = Object.new.freeze
- # Extends base class with class and instance methods
+ # Extends base class or a module with virtus methods
#
# @param [Class] descendant
#
@@ -34,6 +34,12 @@ def self.included(object)
end
private_class_method :included
+ # Extends an object with virtus extensions
+ #
+ # @param [Object] object
+ #
+ # @return [undefined]
+ #
# @api private
def self.extended(object)
object.extend(Extensions)
View
3 lib/virtus/attribute/embedded_value.rb
@@ -37,6 +37,9 @@ def self.merge_options(type, options)
# Determine type based on class
#
+ # Virtus::EmbeddedValue.determine_type(Struct) # => Virtus::EmbeddedValue::FromStruct
+ # Virtus::EmbeddedValue.determine_type(VirtusClass) # => Virtus::EmbeddedValue::FromOpenStruct
+ #
# @param [Class] klass
#
# @return [Virtus::Attribute::EmbeddedValue]
View
20 lib/virtus/class_inclusions.rb
@@ -1,18 +1,38 @@
module Virtus
+
+ # Class-level extensions
module ClassInclusions
+ # Extends a descendant with class and instance methods
+ #
+ # @param [Class] descendant
+ #
+ # @return [undefined]
+ #
+ # @api private
def self.included(descendant)
super
descendant.extend(ClassMethods)
descendant.send(:include, InstanceMethods)
end
+ private_class_method :included
private
+ # Return class' attribute set
+ #
+ # @return [Virtus::AttributeSet]
+ #
+ # @api private
def attribute_set
self.class.attribute_set
end
+ # Return a list of allowed writer method names
+ #
+ # @return [Set]
+ #
+ # @api private
def allowed_writer_methods
self.class.allowed_writer_methods
end
View
14 lib/virtus/extensions.rb
@@ -5,6 +5,12 @@ module Extensions
WRITER_METHOD_REGEXP = /=\z/.freeze
INVALID_WRITER_METHODS = %w[ == != === []= attributes= ].to_set.freeze
+ # A hook called when an object is extended with Virtus
+ #
+ # @param [Object] object
+ #
+ # @return [undefined]
+ #
# @api private
def self.extended(object)
object.extend(InstanceMethods)
@@ -65,11 +71,19 @@ def allowed_writer_methods
private
+ # Return an attribute set for that instance
+ #
+ # @return [AttributeSet]
+ #
# @api private
def attribute_set
@attribute_set ||= AttributeSet.new
end
+ # Add an attribute to the attribute set
+ #
+ # @return [AttributeSet]
+ #
# @api private
def virtus_add_attribute(attribute)
attribute_set << attribute
View
42 lib/virtus/module_extensions.rb
@@ -1,36 +1,62 @@
module Virtus
- # Virtus module class that can define attributes for later inclusion
+ # Virtus module that can define attributes for later inclusion
#
module ModuleExtensions
+ def attribute(*args)
+ attribute_definitions << args
+ end
+
+ private
+
+ # Extend an object with Virtus methods and define attributes
+ #
+ # @param [Object] object
+ #
+ # @return [undefined]
+ #
+ # @api private
def extended(object)
super
object.extend(Virtus)
define_attributes(object)
end
+ # Extend a class with Virtus methods and define attributes
+ #
+ # @param [Object] object
+ #
+ # @return [undefined]
+ #
+ # @api private
def included(object)
super
object.send(:include, ClassInclusions)
define_attributes(object)
end
- def attribute(*args)
- attribute_definitions << args
- end
-
- private
-
+ # Return attribute definitions
+ #
+ # @return [Array<Hash>]
+ #
+ # @api private
def attribute_definitions
@_attribute_definitions ||= []
end
+ # Define attributes on a class or instance
+ #
+ # @param [Object,Class] object
+ #
+ # @return [undefined]
+ #
+ # @api private
def define_attributes(object)
attribute_definitions.each do |attribute_args|
object.attribute(*attribute_args)
end
end
- end # class Module
+ end # class ModuleExtensions
end # module Virtus
View
9 lib/virtus/value_object.rb
@@ -41,6 +41,7 @@ def self.included(base)
private_class_method :included
module InstanceMethods
+
# the #get_attributes method accept a Proc object that will filter
# out an attribute when the block returns false. the ValueObject
# needs all the attributes, so we allow every attribute.
@@ -54,7 +55,13 @@ def with(attribute_updates)
self.class.new(get_attributes(&FILTER_NONE).merge(attribute_updates))
end
- # ValueObjects are immutable and can't be cloned. They always represent the same value.
+ # ValueObjects are immutable and can't be cloned
+ #
+ # They always represent the same value
+ #
+ # @example
+ #
+ # value_object.clone === value_object # => true
#
# @return [self]
#

0 comments on commit 3615ab4

Please sign in to comment.