Module: Domainic

Defined in:
lib/domainic/attributer.rb,
lib/domainic/attributer/attribute.rb,
lib/domainic/attributer/undefined.rb,
lib/domainic/attributer/errors/error.rb,
lib/domainic/attributer/attribute_set.rb,
lib/domainic/attributer/class_methods.rb,
lib/domainic/attributer/dsl/initializer.rb,
lib/domainic/attributer/instance_methods.rb,
lib/domainic/attributer/attribute/coercer.rb,
lib/domainic/attributer/attribute/callback.rb,
lib/domainic/attributer/attribute/signature.rb,
lib/domainic/attributer/attribute/validator.rb,
lib/domainic/attributer/dsl/method_injector.rb,
lib/domainic/attributer/dsl/attribute_builder.rb,
lib/domainic/attributer/errors/aggregate_error.rb,
lib/domainic/attributer/errors/callback_execution_error.rb,
lib/domainic/attributer/errors/coercion_execution_error.rb,
lib/domainic/attributer/errors/validation_execution_error.rb,
lib/domainic/attributer/dsl/attribute_builder/option_parser.rb,
lib/domainic/attributer/attribute/mixin/belongs_to_attribute.rb

Defined Under Namespace

Modules: Attributer

Class Method Summary collapse

Class Method Details

.Attributer(**options) ⇒ Module

Provides a convenient way to include Attributer with customized method names

Examples:

Customizing method names

class Person
  include Domainic.Attributer(argument: :param, option: :opt)

  param :name, String
  opt :age, Integer
end

Person.respond_to?(:argument) # => false
Person.respond_to?(:param)  # => true
Person.respond_to?(:option) # => false
Person.respond_to?(:opt)  # => true

person = Person.new('Alice', age: 30)
# => #<Person:0x000000010865d188 @age=30, @name="Alice">

Turning off a method


class Person
  include Domainic.Attributer(argument: nil)

  option :name, String
  option :age, Integer
end

Person.respond_to?(:argument)  # => false
Person.respond_to?(:option) # => true

person = Person.new(name: 'Alice', age: 30)
# => #<Person:0x000000010865d188 @age=30, @name="Alice">

Parameters:

  • options (Hash{Symbol => String, Symbol, nil})

    method name customization options

Options Hash (**options):

  • :argument (String, Symbol, nil)

    custom name for the argument method. Set to nil to disable the method entirely

  • :option (String, Symbol, nil)

    custom name for the option method. Set to nil to disable the method entirely

Returns:



172
173
174
# File 'lib/domainic/attributer.rb', line 172

def self.Attributer(**options) # rubocop:disable Naming/MethodName
  Domainic::Attributer.call(**options)
end