Module: ActiveInteraction

Defined in:
lib/active_interaction.rb,
lib/active_interaction/base.rb,
lib/active_interaction/errors.rb,
lib/active_interaction/filter.rb,
lib/active_interaction/version.rb,
lib/active_interaction/backports.rb,
lib/active_interaction/filter_column.rb,
lib/active_interaction/grouped_input.rb,
lib/active_interaction/concerns/hashable.rb,
lib/active_interaction/concerns/missable.rb,
lib/active_interaction/concerns/runnable.rb,
lib/active_interaction/modules/validation.rb,
lib/active_interaction/filters/date_filter.rb,
lib/active_interaction/filters/file_filter.rb,
lib/active_interaction/filters/hash_filter.rb,
lib/active_interaction/filters/time_filter.rb,
lib/active_interaction/filters/array_filter.rb,
lib/active_interaction/filters/float_filter.rb,
lib/active_interaction/filters/object_filter.rb,
lib/active_interaction/filters/string_filter.rb,
lib/active_interaction/filters/symbol_filter.rb,
lib/active_interaction/filters/boolean_filter.rb,
lib/active_interaction/filters/decimal_filter.rb,
lib/active_interaction/filters/integer_filter.rb,
lib/active_interaction/filters/abstract_filter.rb,
lib/active_interaction/modules/input_processor.rb,
lib/active_interaction/filters/date_time_filter.rb,
lib/active_interaction/filters/interface_filter.rb,
lib/active_interaction/concerns/active_modelable.rb,
lib/active_interaction/concerns/active_recordable.rb,
lib/active_interaction/filters/abstract_numeric_filter.rb,
lib/active_interaction/filters/abstract_date_time_filter.rb

Overview

Manage application specific business logic.

Since:

  • 1.0.0

Defined Under Namespace

Modules: ActiveModelable, ActiveRecordable, Hashable, InputProcessor, Missable, Runnable, Validation Classes: AbstractDateTimeFilter, AbstractFilter, AbstractNumericFilter, ArrayFilter, Base, BooleanFilter, DateFilter, DateTimeFilter, DecimalFilter, Errors, FileFilter, Filter, FilterColumn, FloatFilter, GroupedInput, HashFilter, IntegerFilter, InterfaceFilter, InvalidNestedValueError, ObjectFilter, StringFilter, SymbolFilter, TimeFilter

Constant Summary collapse

Error =

Top-level error class. All other errors subclass this.

Returns:

  • (Class)

Since:

  • 1.0.0

Class.new(StandardError)
InvalidClassError =

Raised if a class name is invalid.

Returns:

  • (Class)

Since:

  • 1.0.0

Class.new(Error)
InvalidDefaultError =

Raised if a default value is invalid.

Returns:

  • (Class)

Since:

  • 1.0.0

Class.new(Error)
InvalidFilterError =

Raised if a filter has an invalid definition.

Returns:

  • (Class)

Since:

  • 1.0.0

Class.new(Error)
InvalidInteractionError =

Raised if an interaction is invalid.

Returns:

  • (Class)

Since:

  • 1.0.0

Class.new(Error)
InvalidValueError =

Raised if a user-supplied value is invalid.

Returns:

  • (Class)

Since:

  • 1.0.0

Class.new(Error)
MissingFilterError =

Raised if a filter cannot be found.

Returns:

  • (Class)

Since:

  • 1.0.0

Class.new(Error)
MissingValueError =

Raised if no value is given.

Returns:

  • (Class)

Since:

  • 1.0.0

Class.new(Error)
NoDefaultError =

Raised if there is no default value.

Returns:

  • (Class)

Since:

  • 1.0.0

Class.new(Error)
ReservedNameError =

Raised if a reserved name is used.

Returns:

  • (Class)

Since:

  • 1.2.0

Class.new(Error)
VERSION =

The version number.

Returns:

  • (Gem::Version)

Since:

  • 1.0.0

Gem::Version.new('3.2.0')

Class Method Summary collapse

Class Method Details

.array(*attributes, options = {}, &block) ⇒ Object

Creates accessors for the attributes and ensures that values passed to

the attributes are Arrays.

Examples:

array :ids
array :ids do
  integer
end
array :ids do
  integer default: nil
end

Parameters:

  • *attributes (Array<Symbol>)

    Attributes to create.

  • options (Hash{Symbol => Object}) (defaults to: {})
  • block (Proc)

    filter method to apply to each element

Options Hash (options):

  • :default (Object)

    Fallback value if nil is given.

  • :desc (String)

    Human-readable description of this input.



# File 'lib/active_interaction/filters/array_filter.rb', line 6


.boolean(*attributes, options = {}) ⇒ Object

Creates accessors for the attributes and ensures that values passed to

the attributes are Booleans. The strings `"1"` and `"true"`
(case-insensitive) are converted to `true` while the strings `"0"`
and `"false"` are converted to `false`.

Examples:

boolean :subscribed

Parameters:

  • *attributes (Array<Symbol>)

    Attributes to create.

  • options (Hash{Symbol => Object}) (defaults to: {})

Options Hash (options):

  • :default (Object)

    Fallback value if nil is given.

  • :desc (String)

    Human-readable description of this input.



# File 'lib/active_interaction/filters/boolean_filter.rb', line 6


.date(*attributes, options = {}) ⇒ Object

Creates accessors for the attributes and ensures that values passed to

the attributes are Dates. String values are processed using `parse`
unless the format option is given, in which case they will be
processed with `strptime`.

Examples:

date :birthday
date :birthday, format: '%Y-%m-%d'

Parameters:

  • *attributes (Array<Symbol>)

    Attributes to create.

  • options (Hash{Symbol => Object}) (defaults to: {})

Options Hash (options):

  • :default (Object)

    Fallback value if nil is given.

  • :desc (String)

    Human-readable description of this input.

  • :format (String)

    parse strings using this format string



# File 'lib/active_interaction/filters/date_filter.rb', line 6


.date_time(*attributes, options = {}) ⇒ Object

Creates accessors for the attributes and ensures that values passed to

the attributes are DateTimes. String values are processed using
`parse` unless the format option is given, in which case they will be
processed with `strptime`.

Examples:

date_time :start_date
date_time :start_date, format: '%Y-%m-%dT%H:%M:%SZ'

Parameters:

  • *attributes (Array<Symbol>)

    Attributes to create.

  • options (Hash{Symbol => Object}) (defaults to: {})

Options Hash (options):

  • :default (Object)

    Fallback value if nil is given.

  • :desc (String)

    Human-readable description of this input.

  • :format (String)

    parse strings using this format string



# File 'lib/active_interaction/filters/date_time_filter.rb', line 6


.decimal(*attributes, options = {}) ⇒ Object

Creates accessors for the attributes and ensures that values passed to

the attributes are BigDecimals. Numerics and String values are
converted into BigDecimals.

Examples:

decimal :amount, digits: 4

Parameters:

  • *attributes (Array<Symbol>)

    Attributes to create.

  • options (Hash{Symbol => Object}) (defaults to: {})

Options Hash (options):

  • :default (Object)

    Fallback value if nil is given.

  • :desc (String)

    Human-readable description of this input.

Since:

  • 1.2.0



# File 'lib/active_interaction/filters/decimal_filter.rb', line 8


.file(*attributes, options = {}) ⇒ Object

Creates accessors for the attributes and ensures that values passed to the attributes respond to the rewind method. This is useful when passing in Rails params that include a file upload or another generic IO object.

Examples:

file :image

Parameters:

  • *attributes (Array<Symbol>)

    Attributes to create.

  • options (Hash{Symbol => Object}) (defaults to: {})

Options Hash (options):

  • :default (Object)

    Fallback value if nil is given.

  • :desc (String)

    Human-readable description of this input.



# File 'lib/active_interaction/filters/file_filter.rb', line 6


.float(*attributes, options = {}) ⇒ Object

Creates accessors for the attributes and ensures that values passed to

the attributes are Floats. Integer and String values are converted
into Floats.

Examples:

float :amount

Parameters:

  • *attributes (Array<Symbol>)

    Attributes to create.

  • options (Hash{Symbol => Object}) (defaults to: {})

Options Hash (options):

  • :default (Object)

    Fallback value if nil is given.

  • :desc (String)

    Human-readable description of this input.



# File 'lib/active_interaction/filters/float_filter.rb', line 6


.hash(*attributes, options = {}, &block) ⇒ Object

Creates accessors for the attributes and ensures that values passed to

the attributes are Hashes.

Examples:

hash :order
hash :order do
  object :item
  integer :quantity, default: 1
end

Parameters:

  • *attributes (Array<Symbol>)

    Attributes to create.

  • options (Hash{Symbol => Object}) (defaults to: {})
  • block (Proc)

    filter methods to apply for select keys

Options Hash (options):

  • :default (Object)

    Fallback value if nil is given.

  • :desc (String)

    Human-readable description of this input.

  • :strip (Boolean) — default: true

    remove unknown keys



# File 'lib/active_interaction/filters/hash_filter.rb', line 6


.integer(*attributes, options = {}) ⇒ Object

Creates accessors for the attributes and ensures that values passed to

the attributes are Integers. String values are converted into
Integers.

Examples:

integer :quantity

Parameters:

  • *attributes (Array<Symbol>)

    Attributes to create.

  • options (Hash{Symbol => Object}) (defaults to: {})

Options Hash (options):

  • :default (Object)

    Fallback value if nil is given.

  • :desc (String)

    Human-readable description of this input.



# File 'lib/active_interaction/filters/integer_filter.rb', line 6


.interface(*attributes, options = {}) ⇒ Object

Creates accessors for the attributes and ensures that values passed to the attributes implement an interface.

Examples:

interface :anything
interface :serializer,
  methods: i[dump load]

Parameters:

  • *attributes (Array<Symbol>)

    Attributes to create.

  • options (Hash{Symbol => Object}) (defaults to: {})

Options Hash (options):

  • :default (Object)

    Fallback value if nil is given.

  • :desc (String)

    Human-readable description of this input.

  • :methods (Array<String,Symbol>) — default: []

    the methods that objects conforming to this interface should respond to



# File 'lib/active_interaction/filters/interface_filter.rb', line 6


.object(*attributes, options = {}) ⇒ Object

Creates accessors for the attributes and ensures that values passed to

the attributes are the correct class.

Examples:

object :account
object :account, class: User

Parameters:

  • *attributes (Array<Symbol>)

    Attributes to create.

  • options (Hash{Symbol => Object}) (defaults to: {})

Options Hash (options):

  • :default (Object)

    Fallback value if nil is given.

  • :desc (String)

    Human-readable description of this input.

  • :class (Class, String, Symbol) — default: use the attribute name

    Class name used to ensure the value.



# File 'lib/active_interaction/filters/object_filter.rb', line 6


.string(*attributes, options = {}) ⇒ Object

Creates accessors for the attributes and ensures that values passed to

the attributes are Strings.

Examples:

string :first_name
string :first_name, strip: false

Parameters:

  • *attributes (Array<Symbol>)

    Attributes to create.

  • options (Hash{Symbol => Object}) (defaults to: {})

Options Hash (options):

  • :default (Object)

    Fallback value if nil is given.

  • :desc (String)

    Human-readable description of this input.

  • :strip (Boolean) — default: true

    strip leading and trailing whitespace



# File 'lib/active_interaction/filters/string_filter.rb', line 6


.symbol(*attributes, options = {}) ⇒ Object

Creates accessors for the attributes and ensures that values passed to

the attributes are Symbols. Strings will be converted to Symbols.

Examples:

symbol :condiment

Parameters:

  • *attributes (Array<Symbol>)

    Attributes to create.

  • options (Hash{Symbol => Object}) (defaults to: {})

Options Hash (options):

  • :default (Object)

    Fallback value if nil is given.

  • :desc (String)

    Human-readable description of this input.



# File 'lib/active_interaction/filters/symbol_filter.rb', line 6


.time(*attributes, options = {}) ⇒ Object

Creates accessors for the attributes and ensures that values passed to

the attributes are Times. Numeric values are processed using `at`.
Strings are processed using `parse` unless the format option is
given, in which case they will be processed with `strptime`. If
`Time.zone` is available it will be used so that the values are time
zone aware.

Examples:

time :start_date
time :start_date, format: '%Y-%m-%dT%H:%M:%S%Z'

Parameters:

  • *attributes (Array<Symbol>)

    Attributes to create.

  • options (Hash{Symbol => Object}) (defaults to: {})

Options Hash (options):

  • :default (Object)

    Fallback value if nil is given.

  • :desc (String)

    Human-readable description of this input.

  • :format (String)

    parse strings using this format string



# File 'lib/active_interaction/filters/time_filter.rb', line 6