Module: EPlat::Concerns::Metafieldable
Overview
< ActiveResource::CustomMethods
Instance Method Summary collapse
Instance Method Details
#add_metafield(metafield) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/e_plat/resource/concerns/metafieldable.rb', line 27 def () raise ArgumentError, "You can only add metafields to a resource that has been saved" if new? .owner_id ||= id .owner_resource ||= self.class.element_name if client.woocommerce? << save .find{ _1.key == .key }.then do |m| m.owner_id = id m.owner_resource = self.class.element_name m.owner = self m end else .save end end |
#find_metafield(id) ⇒ Object
23 24 25 |
# File 'lib/e_plat/resource/concerns/metafieldable.rb', line 23 def (id) .find { |m| m.id == id } end |
#metafields(**options) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/e_plat/resource/concerns/metafieldable.rb', line 7 def (**) if client.woocommerce? .map do |m| m.owner_id ||= id m.owner_resource ||= self.class.element_name m.owner = self m end else Metafield.find(:all, from: , params: ) || [] end end |