Skip to content
This repository has been archived by the owner on Jul 28, 2020. It is now read-only.

Commit

Permalink
Fix docs (#86)
Browse files Browse the repository at this point in the history
* Fix docs

* Lint :(
  • Loading branch information
idabmat authored Sep 10, 2019
1 parent f50e012 commit 58ae096
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added

- Added missing documentation for serialization

### Fixed

## [0.5.0] - 2019-08-27
Expand Down
6 changes: 6 additions & 0 deletions lib/zenaton/refinements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@
require 'zenaton/refinements/struct'
require 'zenaton/refinements/symbol'
require 'zenaton/refinements/time'

module Zenaton
# Reimplements json encoding from `json/add` as refinements
module Refinements
end
end
2 changes: 2 additions & 0 deletions lib/zenaton/refinements/big_decimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Zenaton
# :nodoc
module Refinements
refine BigDecimal do
# Convert to a simple hash
def to_zenaton
{
'b' => _dump
Expand All @@ -19,6 +20,7 @@ def to_zenaton

# Reimplements `json/add/bigdecimal`
class BigDecimal
# Parse from simple hash
def self.from_zenaton(props)
BigDecimal._load props['b']
end
Expand Down
2 changes: 2 additions & 0 deletions lib/zenaton/refinements/class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Zenaton
# :nodoc
module Refinements
refine Class do
# Convert to a simple hash
def to_zenaton
{
'n' => name
Expand All @@ -15,6 +16,7 @@ def to_zenaton

# Load an instance of class from zenaton properties
class Class
# Parse from simple hash
def self.from_zenaton(props)
Object.const_get(props['n'])
end
Expand Down
2 changes: 2 additions & 0 deletions lib/zenaton/refinements/complex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Zenaton
# :nodoc
module Refinements
refine Complex do
# Convert to a simple hash
def to_zenaton
{
'r' => real,
Expand All @@ -16,6 +17,7 @@ def to_zenaton

# Reimplements `json/add/complex`
class Complex
# Parse from simple hash
def self.from_zenaton(props)
Complex(props['r'], props['i'])
end
Expand Down
2 changes: 2 additions & 0 deletions lib/zenaton/refinements/date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Zenaton
# :nodoc
module Refinements
refine Date do
# Convert to a simple hash
def to_zenaton
{
'y' => year,
Expand All @@ -20,6 +21,7 @@ def to_zenaton

# Reimplements `json/add/date`
class Date
# Parse from simple hash
def self.from_zenaton(props)
civil(*props.values_at('y', 'm', 'd', 'sg'))
end
Expand Down
2 changes: 2 additions & 0 deletions lib/zenaton/refinements/date_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Zenaton
# :nodoc
module Refinements
refine DateTime do
# Convert to a simple hash
def to_zenaton
{
'y' => year,
Expand All @@ -24,6 +25,7 @@ def to_zenaton

# Reimplements `json/add/date_time`
class DateTime
# Parse from simple hash
def self.from_zenaton(props)
args = props.values_at('y', 'm', 'd', 'H', 'M', 'S')
of_a, of_b = props['of'].split('/')
Expand Down
2 changes: 2 additions & 0 deletions lib/zenaton/refinements/exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Zenaton
# :nodoc
module Refinements
refine Exception do
# Convert to a simple hash
def to_zenaton
{
'm' => message,
Expand All @@ -16,6 +17,7 @@ def to_zenaton

# Reimplements `json/add/exception`
class Exception
# Parse from simple hash
def self.from_zenaton(props)
result = new(props['m'])
result.set_backtrace props['b']
Expand Down
1 change: 1 addition & 0 deletions lib/zenaton/refinements/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Zenaton
# :nodoc
module Refinements
refine Object do
# Convert to a simple hash
def to_zenaton
instance_variables.map do |ivar|
value = instance_variable_get(ivar)
Expand Down
2 changes: 2 additions & 0 deletions lib/zenaton/refinements/open_struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Zenaton
# :nodoc
module Refinements
refine OpenStruct do
# Convert to a simple hash
def to_zenaton
class_name = self.class.name.to_s
error_message = 'Only named structs are supported'
Expand All @@ -20,6 +21,7 @@ def to_zenaton

# Reimplements `json/add/ostruct`
class OpenStruct
# Parse from simple hash
def self.from_zenaton(props)
new(props['t'] || props[:t])
end
Expand Down
2 changes: 2 additions & 0 deletions lib/zenaton/refinements/range.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Zenaton
# :nodoc
module Refinements
refine Range do
# Convert to a simple hash
def to_zenaton
{
'a' => [first, last, exclude_end?]
Expand All @@ -15,6 +16,7 @@ def to_zenaton

# Reimplements `json/add/range`
class Range
# Parse from simple hash
def self.from_zenaton(props)
new(*props['a'])
end
Expand Down
2 changes: 2 additions & 0 deletions lib/zenaton/refinements/rational.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Zenaton
# :nodoc
module Refinements
refine Rational do
# Convert to a simple hash
def to_zenaton
{
'n' => numerator,
Expand All @@ -16,6 +17,7 @@ def to_zenaton

# Reimplements `json/add/rational`
class Rational
# Parse from simple hash
def self.from_zenaton(props)
Rational(props['n'], props['d'])
end
Expand Down
2 changes: 2 additions & 0 deletions lib/zenaton/refinements/regexp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Zenaton
# :nodoc
module Refinements
refine Regexp do
# Convert to a simple hash
def to_zenaton
{
'o' => options,
Expand All @@ -16,6 +17,7 @@ def to_zenaton

# Reimplements `json/add/regexp`
class Regexp
# Parse from simple hash
def self.from_zenaton(props)
new(props['s'], props['o'])
end
Expand Down
2 changes: 2 additions & 0 deletions lib/zenaton/refinements/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Zenaton
# :nodoc
module Refinements
refine Struct do
# Convert to a simple hash
def to_zenaton
class_name = self.class.name.to_s
error_message = 'Only named structs are supported'
Expand All @@ -18,6 +19,7 @@ def to_zenaton

# Reimplements `json/add/struct`
class Struct
# Parse from simple hash
def self.from_zenaton(props)
new(*props['v'])
end
Expand Down
2 changes: 2 additions & 0 deletions lib/zenaton/refinements/symbol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Zenaton
# :nodoc
module Refinements
refine Symbol do
# Convert to a simple hash
def to_zenaton
{
's' => to_s
Expand All @@ -15,6 +16,7 @@ def to_zenaton

# Reimplements `json/add/symbol`
class Symbol
# Parse from simple hash
def self.from_zenaton(props)
props['s'].to_sym
end
Expand Down
2 changes: 2 additions & 0 deletions lib/zenaton/refinements/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Zenaton
# :nodoc
module Refinements
refine Time do
# Convert to a simple hash
def to_zenaton
nanoseconds = [tv_usec * 1000]
respond_to?(:tv_nsec) && nanoseconds << tv_nsec
Expand All @@ -19,6 +20,7 @@ def to_zenaton

# Reimplements `json/add/time`
class Time
# Parse from simple hash
def self.from_zenaton(props)
if (usec = props.delete('u')) # used to be tv_usec -> tv_nsec
props['n'] = usec * 1000
Expand Down
2 changes: 1 addition & 1 deletion lib/zenaton/traits/with_timestamp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module WithTimestamp
end

# Calculates the timestamp based on either timestamp or duration methods
# @return Array<Integer, NilClass>
# @return [Array<Integer, NilClass>]
def _get_timestamp_or_duration
return [nil, nil] unless @buffer

Expand Down

0 comments on commit 58ae096

Please sign in to comment.