Module: TinyDyno::Fields

Extended by:
ActiveSupport::Concern
Included in:
DocumentComposition
Defined in:
lib/tiny_dyno/fields.rb,
lib/tiny_dyno/fields/standard.rb

Defined Under Namespace

Modules: ClassMethods Classes: Standard

Constant Summary collapse

TYPE_MAPPINGS =
{
    # binary_blob: 'B',
    # bool: Boolean,
    # binary_set: Array,
    list: Array,
    map: Hash,
    number: Integer,
    number_set: Array,
    # null: Null,
    string: String,
    string_set: Array,
    time: Time,
}
SUPPORTED_FIELD_TYPES =
[Array, Hash, Integer, Array, String, Time].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.option(option_name, &block) ⇒ Object

Stores the provided block to be run when the option name specified is defined on a field.

No assumptions are made about what sort of work the handler might perform, so it will always be called if the option_name key is provided in the field definition – even if it is false or nil.

Examples:

TinyDyno::Fields.option :required do |model, field, value|
  model.validates_presence_of field if value
end

Parameters:

  • option_name (Symbol)

    the option name to match against

  • block (Proc)

    the handler to execute when the option is provided.

Since:

  • 2.1.0



50
51
52
# File 'lib/tiny_dyno/fields.rb', line 50

def option(option_name, &block)
  options[option_name] = block
end

.optionsHash

Return a map of custom option names to their handlers.

Examples:

TinyDyno::Fields.options
# => { :required => #<Proc:0x00000100976b38> }

Returns:

  • (Hash)

    the option map

Since:

  • 2.1.0



63
64
65
# File 'lib/tiny_dyno/fields.rb', line 63

def options
  @options ||= {}
end

Instance Method Details

#database_field_name(name) ⇒ String

Get the name of the provided field as it is stored in the database. Used in determining if the field is aliased or not.

Examples:

Get the database field name.

model.database_field_name(:authorization)

Parameters:

  • name (String, Symbol)

    The name to get.

Returns:

  • (String)

    The name of the field as it’s stored in the db.

Since:

  • 3.0.7



79
80
81
# File 'lib/tiny_dyno/fields.rb', line 79

def database_field_name(name)
  self.class.database_field_name(name)
end