Skip to content

Commit

Permalink
fix hash to handle nested array and hash values, add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
schorsch committed Dec 29, 2012
1 parent 4f50d9a commit 6f921f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions README.md
Expand Up @@ -6,7 +6,7 @@ Set of tools to help working with JSON Schemata:

* read schema files into a ruby hash
* add schema properties to a class
* convert any object into it's schema json markup
* convert any object into it's schema JSON markup
* clean parameters according to a schema (e.g. in an api controller)

## Usage
Expand All @@ -23,12 +23,16 @@ schema.json files are located.

SchemaTools.schema_path = '/path/to/schema-json-files'

Now you can read a single or multiple schemas:
Read a single schema:

schema = SchemaTools::Reader.read :client
# read all *.json files in schema path

Read multiple schemas, all *.json files in schema path

schemata = SchemaTools::Reader.read_all
# see schema cached in registry

Schemata are cached in registry

SchemaTools::Reader.registry[:client]

Read files from a custom path?
Expand All @@ -43,7 +47,7 @@ Don't like the global path and registry? Go local:
reader.registry


## Object to Schema
## Object to Schema JSON

A schema provides a (public) contract about an object definition. Therefore an
internal object is converted to it's schema version on delivery(API access).
Expand Down
4 changes: 2 additions & 2 deletions lib/schema_tools/modules/hash.rb
Expand Up @@ -41,8 +41,8 @@ def from_schema(obj, opts={})
# get objects class name without inheritance
real_class_name = obj.class.name.split('::').last.underscore
class_name = opts[:class_name] || real_class_name

return obj if ['Array', 'Hash'].include? class_name
# directly return array & hash values
return obj if ['array', 'hash'].include? class_name

data = {}
# get schema
Expand Down

0 comments on commit 6f921f0

Please sign in to comment.