Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update docs

  • Loading branch information...
commit 120285063f2d4c2744038cd0f10a46e7cafaed2b 1 parent bff187e
@schorsch schorsch authored
Showing with 10 additions and 11 deletions.
  1. +8 −10 README.md
  2. +2 −1  lib/schema_tools/klass_factory.rb
View
18 README.md
@@ -97,7 +97,7 @@ For example in a client controller
## Object attributes from Schema
-The use-case here is to add methods, defined in schema properties, to an object.
+Add methods, defined in schema properties, to an existing class.
Very usefull if you are building a API client and don't want to manually add
methods to you local classes .. like people NOT using JSON schema
@@ -111,10 +111,11 @@ methods to you local classes .. like people NOT using JSON schema
# raw access
contact.schema_attrs
-## Objects from Schema - KlassFactory
+## Classes from Schema - KlassFactory
Use the KlassFactory to directly create classes, with all attributes from a
-schema. The classes are named after each schema[name] found in from global path.
+schema. Instead of adding attributes to an existing class like in above example.
+The classes are named after each schema's [name] (in global path).
So lets assume you have a 'client.json' schema with a name attribute in it, for
the following examples:
@@ -123,19 +124,16 @@ the following examples:
client.name = 'Mändy'
-Rather like a namespace? Good idea, but the class or module must be defined.
+Rather like a namespace? Good idea, but don't forget the class or module must
+be defined.
- module SalesKing; end
SchemaTools::KlassFactory.build namespace: SalesKing
client = SalesKing::Client.new
-Add a custom schema reader
+Add a custom schema reader most likely usefull in conjunction with a custom path
reader = SchemaTools::Reader.new
- reader.path = HappyPdf::Schema.path
- SchemaTools::KlassFactory.build reader: reader
-
-
+ SchemaTools::KlassFactory.build reader: reader, path: HappyPdf::Schema.path
## Real world examples
View
3  lib/schema_tools/klass_factory.rb
@@ -8,9 +8,10 @@ class << self
# Build classes from schema inside the given namespace. Uses all classes
# found in schema path
#
- # @param [String|Symbol|Module] namespace of the new classes e.g. MyCustomNamespace::MySchemaClass
# @param [Hash] opts
# @options opts [SchemaTools::Reader] :reader to use instead of global one
+ # @options opts [SchemaTools::Reader] :path to schema files instead of global one
+ # @options opts [SchemaTools::Reader] :namespace of the new classes e.g. MyCustomNamespace::MySchemaClass
def build(opts={})
reader = opts[:reader] || SchemaTools::Reader
schemata = reader.read_all( opts[:path] || SchemaTools.schema_path )
Please sign in to comment.
Something went wrong with that request. Please try again.