Class: GoldenFleece::Schema
- Inherits:
-
Object
- Object
- GoldenFleece::Schema
- Includes:
- Utility
- Defined in:
- lib/golden_fleece/schema.rb
Constant Summary
Constants included from Utility
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#json_path ⇒ Object
readonly
Returns the value of attribute json_path.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#normalizers ⇒ Object
readonly
Returns the value of attribute normalizers.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #[](subschema_name) ⇒ Object
- #[]=(subschema_name, subschema_definition) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(context, path, definitions) ⇒ Schema
constructor
A new instance of Schema.
- #keys ⇒ Object
- #parent? ⇒ Boolean
- #reduce(memo, &block) ⇒ Object
- #values ⇒ Object
Methods included from Utility
#build_json_path, #cast_boolean, #deep_stringify_keys, #error_suffix
Constructor Details
#initialize(context, path, definitions) ⇒ Schema
Returns a new instance of Schema.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/golden_fleece/schema.rb', line 11 def initialize(context, path, definitions) @context = context @path = path @name = path.split("/").last @attribute = path.split("/")[1] @json_path = path.split("/")[2..-1] @json_path = @json_path.join("/") if @json_path @subschemas = {} # .count == 1 means we're at the root # .count == 2 means we're at the attribute # .count >= 3 means we're cookin' if path.split("/").count <= 2 @types = [Definitions::TYPES[:object]] map_subschemas(definitions) else map_value map_types(definitions[:type], definitions[:types]) map_normalizers(definitions[:normalizer], definitions[:normalizers]) map_format(definitions[:format]) map_default(definitions[:default]) map_subschemas(definitions[:subschemas]) end end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
9 10 11 |
# File 'lib/golden_fleece/schema.rb', line 9 def attribute @attribute end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
9 10 11 |
# File 'lib/golden_fleece/schema.rb', line 9 def default @default end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
9 10 11 |
# File 'lib/golden_fleece/schema.rb', line 9 def format @format end |
#json_path ⇒ Object (readonly)
Returns the value of attribute json_path.
9 10 11 |
# File 'lib/golden_fleece/schema.rb', line 9 def json_path @json_path end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/golden_fleece/schema.rb', line 9 def name @name end |
#normalizers ⇒ Object (readonly)
Returns the value of attribute normalizers.
9 10 11 |
# File 'lib/golden_fleece/schema.rb', line 9 def normalizers @normalizers end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/golden_fleece/schema.rb', line 9 def path @path end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
9 10 11 |
# File 'lib/golden_fleece/schema.rb', line 9 def types @types end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
9 10 11 |
# File 'lib/golden_fleece/schema.rb', line 9 def value @value end |
Instance Method Details
#[](subschema_name) ⇒ Object
36 37 38 |
# File 'lib/golden_fleece/schema.rb', line 36 def [](subschema_name) subschemas[subschema_name] end |
#[]=(subschema_name, subschema_definition) ⇒ Object
40 41 42 |
# File 'lib/golden_fleece/schema.rb', line 40 def []=(subschema_name, subschema_definition) subschemas[subschema_name] = Schema.new(context, build_json_path(path, subschema_name), subschema_definition) end |
#each(&block) ⇒ Object
44 45 46 |
# File 'lib/golden_fleece/schema.rb', line 44 def each(&block) subschemas.each(&block) end |
#keys ⇒ Object
56 57 58 |
# File 'lib/golden_fleece/schema.rb', line 56 def keys subschemas.keys end |
#parent? ⇒ Boolean
52 53 54 |
# File 'lib/golden_fleece/schema.rb', line 52 def parent? subschemas.count > 0 end |
#reduce(memo, &block) ⇒ Object
48 49 50 |
# File 'lib/golden_fleece/schema.rb', line 48 def reduce(memo, &block) subschemas.reduce(memo, &block) end |
#values ⇒ Object
60 61 62 |
# File 'lib/golden_fleece/schema.rb', line 60 def values subschemas.values end |