module TinyDyno::Fields

Public Class Methods

option(option_name, &block) click to toggle source

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.

@example

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

@param [ Symbol ] option_name the option name to match against @param [ Proc ] block the handler to execute when the option is

provided.

@since 2.1.0

# File lib/tiny_dyno/fields.rb, line 35
def option(option_name, &block)
  options[option_name] = block
end
options() click to toggle source

Return a map of custom option names to their handlers.

@example

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

@return [ Hash ] the option map

@since 2.1.0

# File lib/tiny_dyno/fields.rb, line 48
def options
  @options ||= {}
end

Public Instance Methods

database_field_name(name) click to toggle source

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

@example Get the database field name.

model.database_field_name(:authorization)

@param [ String, Symbol ] name The name to get.

@return [ String ] The name of the field as it's stored in the db.

@since 3.0.7

# File lib/tiny_dyno/fields.rb, line 64
def database_field_name(name)
  self.class.database_field_name(name)
end