Skip to content
Browse files

Add missing docs

  • Loading branch information...
1 parent d8ee43f commit 5c7cbcff8d168e2fe282239b71a877abe43c4584 @solnic committed Mar 9, 2013
View
10 lib/virtus.rb
@@ -40,6 +40,16 @@ def self.extended(object)
end
private_class_method :extended
+ # Setup coercer
+ #
+ # @example
+ #
+ # Virtus.coercer do |config|
+ # config.string.boolea_map = { true => '1', false => '0' }
+ # end
+ #
+ # @return [Coercible::Coercer]
+ #
# @api public
def self.coercer(&block)
@coercer ||= Coercible::Coercer.new(&block)
View
52 lib/virtus/attribute.rb
@@ -57,32 +57,62 @@ def self.build(name, type = Object, options = {})
klass.new(name, accessor)
end
+ # Build coercer wrapper
+ #
+ # @example
+ #
+ # Virtus::Attribute.coercer # => #<Virtus::Attribute::Coercer ...>
+ #
+ # @return [Coercer]
+ #
# @api public
def self.coercer(*)
Coercer.new(Virtus.coercer, coercion_method)
end
+ # Return default reader class
+ #
+ # @return [::Class]
+ #
# @api private
def self.reader_class(*)
Reader
end
+ # Return default writer class
+ #
+ # @param [::Class] attribute type
+ # @param [::Hash] attribute options
+ #
+ # @return [::Class]
+ #
# @api private
def self.writer_class(type, options)
options[:coerce] ? coercible_writer_class(type, options) : Writer
end
+ # Return default coercible writer class
+ #
+ # @param [::Class] attribute type
+ # @param [::Hash] attribute options
+ #
+ # @return [::Class]
+ #
# @api private
def self.coercible_writer_class(_type, _options)
Writer::Coercible
end
+ # Return default options for writer class
+ #
+ # @return [::Hash]
+ #
# @api private
def self.reader_options(*)
{}
end
- # Return options accepted by Writer
+ # Return options accepted by writer class
#
# @return [Array<Symbol>]
#
@@ -91,6 +121,10 @@ def self.writer_options(attribute_options)
::Hash[writer_option_names.zip(attribute_options.values_at(*writer_option_names))]
end
+ # Return acceptable option names for write class
+ #
+ # @return [Array<Symbol>]
+ #
# @api private
def self.writer_option_names
[ :coercer, :primitive, :default ]
@@ -161,11 +195,27 @@ def initialize(name, accessor)
@accessor = accessor
end
+ # Return reader object
+ #
+ # @example
+ #
+ # attribute.reader # => #<Virtus::Attribute::Reader ...>
+ #
+ # @return [Reader]
+ #
# @api public
def reader
accessor.reader
end
+ # Return writer object
+ #
+ # @example
+ #
+ # attribute.writer # => #<Virtus::Attribute::Writer ...>
+ #
+ # @return [Writer]
+ #
# @api public
def writer
accessor.writer
View
12 lib/virtus/attribute/accessor.rb
@@ -80,7 +80,7 @@ def initialize(reader, writer)
#
# @return [Object]
#
- # @api public
+ # @api private
def get(instance)
reader.call(instance)
end
@@ -89,7 +89,7 @@ def get(instance)
#
# @return [Object]
#
- # @api public
+ # @api private
def set(*args)
writer.call(*args)
end
@@ -98,7 +98,7 @@ def set(*args)
#
# @return [Boolean]
#
- # @api public
+ # @api private
def public_reader?
reader.public?
end
@@ -107,11 +107,15 @@ def public_reader?
#
# @return [Boolean]
#
- # @api public
+ # @api private
def public_writer?
writer.public?
end
+ # Return if this accessor is lazy
+ #
+ # @return [FalseClass]
+ #
# @api private
def lazy?
false
View
2 lib/virtus/attribute/accessor/lazy_accessor.rb
@@ -11,6 +11,8 @@ class LazyAccessor < self
#
# @see Accessor#get
#
+ # @return [Object]
+ #
# @api private
def get(instance)
if instance.instance_variable_defined?(reader.instance_variable_name)
View
8 lib/virtus/attribute/accessor_method.rb
@@ -19,21 +19,21 @@ class AccessorMethod
#
# @return [Symbol]
#
- # @api public
+ # @api private
attr_reader :name
# Return visibility
#
# @return [Symbol]
#
- # @api public
+ # @api private
attr_reader :visibility
# Return instance variable name
#
# @return [Symbol]
#
- # @api public
+ # @api private
attr_reader :instance_variable_name
# Initialize accessor method instance
@@ -55,7 +55,7 @@ def initialize(name, options = {})
#
# @return [TrueClass,FalseClass]
#
- # @api public
+ # @api private
def public?
visibility == :public
end
View
8 lib/virtus/attribute/collection.rb
@@ -31,11 +31,19 @@ def self.merge_options(type, _options)
merged_options
end
+ # @see Virtus::Attribute.coercible_writer_class
+ #
+ # @return [::Class]
+ #
# @api private
def self.coercible_writer_class(_type, options)
options[:member_type] ? CoercibleWriter : super
end
+ # @see Virtus::Attribute.writer_option_names
+ #
+ # @return [Array<Symbol>]
+ #
# @api private
def self.writer_option_names
super << :member_type
View
19 lib/virtus/attribute/embedded_value/open_struct_coercer.rb
@@ -2,15 +2,30 @@ module Virtus
class Attribute
class EmbeddedValue < Object
- # EmbeddedValue attribute handling OpenStruct primitive or Virtus object
+ # EmbeddedValue coercer handling OpenStruct primitive or Virtus object
#
class OpenStructCoercer
+
+ # Return primitive class
+ #
+ # @return [::Class]
+ #
+ # @api private
attr_reader :primitive
+ # Initialize coercer object
+ #
+ # @return [undefined]
+ #
+ # @api private
def initialize(primitive)
@primitive = primitive
end
+ # Build object from attribute hash
+ #
+ # @return [::Object]
+ #
# @api private
def call(attributes)
if attributes.kind_of?(primitive)
@@ -20,7 +35,7 @@ def call(attributes)
end
end
- end # class FromOpenStruct
+ end # class OpenStructCoercer
end # class EmbeddedValue
end # class Attribute
end # module Virtus
View
18 lib/virtus/attribute/embedded_value/struct_coercer.rb
@@ -2,15 +2,29 @@ module Virtus
class Attribute
class EmbeddedValue < Object
- # EmbeddedValue attribute handling Struct primitive
+ # EmbeddedValue coercer handling Struct primitive
#
class StructCoercer
+ # Return primitive class
+ #
+ # @return [::Class]
+ #
+ # @api private
attr_reader :primitive
+ # Initialize coercer instance
+ #
+ # @return [undefined]
+ #
+ # @api private
def initialize(primitive)
@primitive = primitive
end
+ # Build a struct object from attributes
+ #
+ # @return [Struct]
+ #
# @api private
def call(attributes)
if attributes.kind_of?(primitive)
@@ -20,7 +34,7 @@ def call(attributes)
end
end
- end # class FromStruct
+ end # class StructCoercer
end # class EmbeddedValue
end # class Attribute
end # module Virtus
View
10 lib/virtus/attribute/hash.rb
@@ -17,7 +17,7 @@ class Hash < Object
coercion_method :to_hash
default primitive.new
- # Handles hashes with [key_type => value_type] syntax.
+ # Handles hashes with [key_type => value_type] syntax
#
# @param [Class] type
#
@@ -41,11 +41,19 @@ def self.merge_options(type, _options)
merged_options
end
+ # @see Virtus::Attribute.coercible_writer_class
+ #
+ # @return [::Class]
+ #
# @api private
def self.coercible_writer_class(_type, options)
options[:key_type] && options[:value_type] ? CoercibleWriter : super
end
+ # @see Virtus::Attribute.writer_option_names
+ #
+ # @return [Array<Symbol>]
+ #
# @api private
def self.writer_option_names
super << :key_type << :value_type

0 comments on commit 5c7cbcf

Please sign in to comment.
Something went wrong with that request. Please try again.