Module: Nandi::Formatting
- Included in:
- CheckConstraintGenerator, ForeignKeyGenerator, IndexGenerator, NotNullCheckGenerator, Renderers::ActiveRecord::Instructions::Base
- Defined in:
- lib/nandi/formatting.rb
Defined Under Namespace
Modules: ClassMethods Classes: UnsupportedValueError
Class Method Summary collapse
Instance Method Summary collapse
-
#format_value(value, opts = {}) ⇒ Object
Create a string representation of the value that is a valid and correct Ruby literal for that value.
Class Method Details
.included(base) ⇒ Object
48 49 50 |
# File 'lib/nandi/formatting.rb', line 48 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#format_value(value, opts = {}) ⇒ Object
Create a string representation of the value that is a valid and correct Ruby literal for that value. Please note that the exact representation is not guaranteed to be the same between different platforms and Ruby versions. The guarantee is merely that calling this method with any supported type will produce a string that produces an equal value when it is passed to Kernel::eval
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/nandi/formatting.rb', line 34 def format_value(value, opts = {}) case value when Hash format_hash(value, opts) when Array "[#{value.map { |v| format_value(v, opts) }.join(', ')}]" when String, Symbol, Integer, Float, NilClass, TrueClass, FalseClass value.inspect else raise UnsupportedValueError, "Cannot format value of type #{value.class.name}" end end |