Module: EPlat::Concerns::Metafieldable

Included in:
Order, Product
Defined in:
lib/e_plat/resource/concerns/metafieldable.rb

Overview

< ActiveResource::CustomMethods

Instance Method Summary collapse

Instance Method Details

#add_metafield(metafield) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
# File 'lib/e_plat/resource/concerns/metafieldable.rb', line 18

def add_metafield(metafield)
	raise ArgumentError, "You can only add metafields to a resource that has been saved" if new?

	metafield.owner_id = id
	metafield.owner_resource = self.class.element_name
	metafield.save
	metafield
end

#find_metafield(id) ⇒ Object



14
15
16
# File 'lib/e_plat/resource/concerns/metafieldable.rb', line 14

def find_metafield(id)
	metafields.find { |m| m.id == id }
end

#metafields(**options) ⇒ Object



7
8
9
10
11
12
# File 'lib/e_plat/resource/concerns/metafieldable.rb', line 7

def metafields(**options)
	Metafield.find(:all, 
		from: current_resources_metafield_path, 
		params: options
	)
end