Module: ServiceOperation::Params::ClassMethods

Defined in:
lib/service_operation/params.rb

Overview

ClassMethods

Instance Method Summary collapse

Instance Method Details

#attribute_namesObject

should only be called by Instance after all attributes have been defined



56
57
58
# File 'lib/service_operation/params.rb', line 56

def attribute_names
  @attribute_names ||= attributes.map(&:name)
end

#attributesObject



51
52
53
# File 'lib/service_operation/params.rb', line 51

def attributes
  (returns + params).uniq(&:name) # returns first to preserve log: option
end

#params(&block) ⇒ Object Also known as: input

Examples:

params do
  param1, :integer, coerce: true
end


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/service_operation/params.rb', line 23

def params(&block)
  @params ||= superclass && superclass.respond_to?(:params) ? superclass.params.dup : []

  if block_given?
    @params += Params::DSL.run(&block)
    define_params_hooks
  end

  @params = @params.reverse.uniq(&:name).reverse
  @params
end

#remove_params(*args) ⇒ Object



62
63
64
# File 'lib/service_operation/params.rb', line 62

def remove_params(*args)
  params.delete_if { |a| args.include?(a.name) }
end

#returns(&block) ⇒ Object Also known as: output

Examples:

returns do
  result, [:string]
  log_data, [:string], optional: true
end


42
43
44
45
46
47
48
49
# File 'lib/service_operation/params.rb', line 42

def returns(&block)
  @returns ||= superclass && superclass.respond_to?(:returns) ? superclass.returns.dup : []

  @returns += Params::DSL.run(&block) if block_given?

  @returns = @returns.reverse.uniq(&:name).reverse
  @returns
end