Class: JSONAPI::CreateHasManyAssociationOperation

Inherits:
Operation
  • Object
show all
Defined in:
lib/jsonapi/operation.rb

Instance Attribute Summary collapse

Attributes inherited from Operation

#resource_klass

Instance Method Summary collapse

Constructor Details

#initialize(resource_klass, resource_id, association_type, key_values) ⇒ CreateHasManyAssociationOperation

Returns a new instance of CreateHasManyAssociationOperation.



110
111
112
113
114
115
# File 'lib/jsonapi/operation.rb', line 110

def initialize(resource_klass, resource_id, association_type, key_values)
  @resource_id = resource_id
  @key_values = key_values
  @association_type = association_type.to_sym
  super(resource_klass)
end

Instance Attribute Details

#association_typeObject (readonly)

Returns the value of attribute association_type.



108
109
110
# File 'lib/jsonapi/operation.rb', line 108

def association_type
  @association_type
end

#key_valuesObject (readonly)

Returns the value of attribute key_values.



108
109
110
# File 'lib/jsonapi/operation.rb', line 108

def key_values
  @key_values
end

#resource_idObject (readonly)

Returns the value of attribute resource_id.



108
109
110
# File 'lib/jsonapi/operation.rb', line 108

def resource_id
  @resource_id
end

Instance Method Details

#apply(context) ⇒ Object



117
118
119
120
121
122
# File 'lib/jsonapi/operation.rb', line 117

def apply(context)
  resource = @resource_klass.find_by_key(@resource_id, context: context)
  resource.create_has_many_links(@association_type, @key_values)

  return JSONAPI::OperationResult.new(:no_content)
end