Module: ROM::Types::Coercible
- Defined in:
- core/lib/rom/types.rb
Constant Summary collapse
- JSON =
          
- Coercible.JSON 
- JSONHash =
          
- Coercible.JSONHash 
- HashJSON =
          
- Coercible.HashJSON 
Class Method Summary collapse
- 
  
    
      .HashJSON(type: Types::String)  ⇒ Dry::Types::Constructor 
    
    
  
  
  
  
  
  
  
  
  
    Define a hash-to-json attribute type. 
- 
  
    
      .JSON(symbol_keys: false)  ⇒ Dry::Types::Constructor 
    
    
  
  
  
  
  
  
  
  
  
    Define a json type with json-to-hash read type. 
- 
  
    
      .JSONHash(symbol_keys: false, type: Types::Hash)  ⇒ Dry::Types::Constructor 
    
    
  
  
  
  
  
  
  
  
  
    Define a json-to-hash attribute type. 
Class Method Details
.HashJSON(type: Types::String) ⇒ Dry::Types::Constructor
Define a hash-to-json attribute type
| 60 61 62 | # File 'core/lib/rom/types.rb', line 60 def Coercible.HashJSON(type: Types::String) Types.Constructor(type) { |value| ::JSON.dump(value) } end | 
.JSON(symbol_keys: false) ⇒ Dry::Types::Constructor
Define a json type with json-to-hash read type
| 69 70 71 | # File 'core/lib/rom/types.rb', line 69 def Coercible.JSON(symbol_keys: false) self.HashJSON.(read: self.JSONHash(symbol_keys: symbol_keys)) end | 
.JSONHash(symbol_keys: false, type: Types::Hash) ⇒ Dry::Types::Constructor
Define a json-to-hash attribute type
| 45 46 47 48 49 50 51 52 53 | # File 'core/lib/rom/types.rb', line 45 def Coercible.JSONHash(symbol_keys: false, type: Types::Hash) Types.Constructor(type) do |value| begin ::JSON.parse(value.to_s, symbolize_names: symbol_keys) rescue ::JSON::ParserError value end end end |