Class: Alba::ConditionalAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/alba/conditional_attribute.rb,
sig/alba/conditional_attribute.rbs

Overview

Represents attribute with if option

Instance Method Summary collapse

Constructor Details

#initialize(body:, condition:) ⇒ ConditionalAttribute

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ConditionalAttribute.

Parameters:



12
13
14
15
# File 'lib/alba/conditional_attribute.rb', line 12

def initialize(body:, condition:)
  @body = body
  @condition = condition
end

Instance Method Details

#with_passing_condition(resource:, object: nil) {|arg0| ... } ⇒ Alba::REMOVE_KEY, Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns attribute body if condition passes

Parameters:

Yields:

Yield Parameters:

  • arg0 (Alba::Resource::attribute)

Yield Returns:

  • (Object)

Returns:

  • (Alba::REMOVE_KEY, Object) —

    REMOVE_KEY if condition is unmet, fetched attribute otherwise



22
23
24
25
26
27
28
29
30
31
# File 'lib/alba/conditional_attribute.rb', line 22

def with_passing_condition(resource:, object: nil)
  return Alba::REMOVE_KEY unless condition_passes?(resource, object)

  fetched_attribute = yield(@body)
  return fetched_attribute unless with_two_arity_proc_condition?

  return Alba::REMOVE_KEY unless resource.instance_exec(object, second_object(object, resource), &@condition)

  fetched_attribute
end