Class: Schemable::Configuration
- Inherits:
-
Object
- Object
- Schemable::Configuration
- Defined in:
- lib/schemable/configuration.rb
Overview
The Configuration class provides a set of configuration options for the Schemable module. It includes options for setting the ORM, handling enums, custom type mappers, and more. It is worth noting that the configuration options are global, and will affect all Definitions.
Instance Attribute Summary collapse
-
#custom_defined_enum_method ⇒ Object
Returns the value of attribute custom_defined_enum_method.
-
#custom_meta_response_schema ⇒ Object
Returns the value of attribute custom_meta_response_schema.
-
#custom_type_mappers ⇒ Object
Returns the value of attribute custom_type_mappers.
-
#decimal_as_string ⇒ Object
Returns the value of attribute decimal_as_string.
-
#enum_prefix_for_simple_enum ⇒ Object
Returns the value of attribute enum_prefix_for_simple_enum.
-
#enum_suffix_for_simple_enum ⇒ Object
Returns the value of attribute enum_suffix_for_simple_enum.
-
#float_as_string ⇒ Object
Returns the value of attribute float_as_string.
-
#infer_attributes_from_custom_method ⇒ Object
Returns the value of attribute infer_attributes_from_custom_method.
-
#infer_attributes_from_jsonapi_serializable ⇒ Object
Returns the value of attribute infer_attributes_from_jsonapi_serializable.
-
#infer_expand_nested_from_expand ⇒ Object
Returns the value of attribute infer_expand_nested_from_expand.
-
#orm ⇒ Object
Returns the value of attribute orm.
-
#pagination_enabled ⇒ Object
Returns the value of attribute pagination_enabled.
-
#use_serialized_instance ⇒ Object
Returns the value of attribute use_serialized_instance.
Instance Method Summary collapse
-
#add_custom_type_mapper(type_name, mapping) ⇒ Object
Adds a custom type mapper for a given type name.
-
#initialize ⇒ Configuration
constructor
Initializes a new Configuration instance with default values.
-
#type_mapper(type_name) ⇒ Hash
Returns a type mapper for a given type name.
Constructor Details
#initialize ⇒ Configuration
Initializes a new Configuration instance with default values.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/schemable/configuration.rb', line 25 def initialize @orm = :active_record # orm options are :active_record, :mongoid @float_as_string = false @custom_type_mappers = {} @pagination_enabled = true @decimal_as_string = false @use_serialized_instance = false @custom_defined_enum_method = nil @custom_meta_response_schema = nil @enum_prefix_for_simple_enum = nil @enum_suffix_for_simple_enum = nil @infer_expand_nested_from_expand = false @infer_attributes_from_custom_method = nil @infer_attributes_from_jsonapi_serializable = false end |
Instance Attribute Details
#custom_defined_enum_method ⇒ Object
Returns the value of attribute custom_defined_enum_method.
8 9 10 |
# File 'lib/schemable/configuration.rb', line 8 def custom_defined_enum_method @custom_defined_enum_method end |
#custom_meta_response_schema ⇒ Object
Returns the value of attribute custom_meta_response_schema.
8 9 10 |
# File 'lib/schemable/configuration.rb', line 8 def @custom_meta_response_schema end |
#custom_type_mappers ⇒ Object
Returns the value of attribute custom_type_mappers.
8 9 10 |
# File 'lib/schemable/configuration.rb', line 8 def custom_type_mappers @custom_type_mappers end |
#decimal_as_string ⇒ Object
Returns the value of attribute decimal_as_string.
8 9 10 |
# File 'lib/schemable/configuration.rb', line 8 def decimal_as_string @decimal_as_string end |
#enum_prefix_for_simple_enum ⇒ Object
Returns the value of attribute enum_prefix_for_simple_enum.
8 9 10 |
# File 'lib/schemable/configuration.rb', line 8 def enum_prefix_for_simple_enum @enum_prefix_for_simple_enum end |
#enum_suffix_for_simple_enum ⇒ Object
Returns the value of attribute enum_suffix_for_simple_enum.
8 9 10 |
# File 'lib/schemable/configuration.rb', line 8 def enum_suffix_for_simple_enum @enum_suffix_for_simple_enum end |
#float_as_string ⇒ Object
Returns the value of attribute float_as_string.
8 9 10 |
# File 'lib/schemable/configuration.rb', line 8 def float_as_string @float_as_string end |
#infer_attributes_from_custom_method ⇒ Object
Returns the value of attribute infer_attributes_from_custom_method.
8 9 10 |
# File 'lib/schemable/configuration.rb', line 8 def infer_attributes_from_custom_method @infer_attributes_from_custom_method end |
#infer_attributes_from_jsonapi_serializable ⇒ Object
Returns the value of attribute infer_attributes_from_jsonapi_serializable.
8 9 10 |
# File 'lib/schemable/configuration.rb', line 8 def infer_attributes_from_jsonapi_serializable @infer_attributes_from_jsonapi_serializable end |
#infer_expand_nested_from_expand ⇒ Object
Returns the value of attribute infer_expand_nested_from_expand.
8 9 10 |
# File 'lib/schemable/configuration.rb', line 8 def @infer_expand_nested_from_expand end |
#orm ⇒ Object
Returns the value of attribute orm.
8 9 10 |
# File 'lib/schemable/configuration.rb', line 8 def orm @orm end |
#pagination_enabled ⇒ Object
Returns the value of attribute pagination_enabled.
8 9 10 |
# File 'lib/schemable/configuration.rb', line 8 def pagination_enabled @pagination_enabled end |
#use_serialized_instance ⇒ Object
Returns the value of attribute use_serialized_instance.
8 9 10 |
# File 'lib/schemable/configuration.rb', line 8 def use_serialized_instance @use_serialized_instance end |
Instance Method Details
#add_custom_type_mapper(type_name, mapping) ⇒ Object
Adds a custom type mapper for a given type name.
112 113 114 |
# File 'lib/schemable/configuration.rb', line 112 def add_custom_type_mapper(type_name, mapping) custom_type_mappers[type_name.to_sym] = mapping end |
#type_mapper(type_name) ⇒ Hash
If a custom type mapper is defined for the given type name, it will be returned.
Returns a type mapper for a given type name.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/schemable/configuration.rb', line 50 def type_mapper(type_name) return @custom_type_mappers[type_name] if @custom_type_mappers.key?(type_name.to_sym) { text: { type: :string }, string: { type: :string }, symbol: { type: :string }, integer: { type: :integer }, boolean: { type: :boolean }, date: { type: :string, format: :date }, time: { type: :string, format: :time }, json: { type: :object, properties: {} }, hash: { type: :object, properties: {} }, jsonb: { type: :object, properties: {} }, object: { type: :object, properties: {} }, binary: { type: :string, format: :binary }, trueclass: { type: :boolean, default: true }, falseclass: { type: :boolean, default: false }, datetime: { type: :string, format: :'date-time' }, big_decimal: { type: (@decimal_as_string ? :string : :number).to_s.to_sym, format: :double }, 'bson/objectid': { type: :string, format: :object_id }, 'mongoid/boolean': { type: :boolean }, 'mongoid/stringified_symbol': { type: :string }, 'active_support/time_with_zone': { type: :string, format: :date_time }, float: { type: (@float_as_string ? :string : :number).to_s.to_sym, format: :float }, decimal: { type: (@decimal_as_string ? :string : :number).to_s.to_sym, format: :double }, array: { type: :array, items: { anyOf: [ { type: :string }, { type: :integer }, { type: :boolean }, { type: :number, format: :float }, { type: :object, properties: {} }, { type: :number, format: :double } ] } } }[type_name.to_s.underscore.try(:to_sym)] end |