Class: EPlat::Metafield

Inherits:
Base
  • Object
show all
Defined in:
lib/e_plat/resource/metafield.rb

Constant Summary collapse

BIGCOMMERCE_DEFAULT_PERMISSION_SET =
"read_and_sf_access"
READ_ONLY_ATTRIBUTES =
[:created_at, :id, :updated_at, :date_created, :date_modified]

Constants included from Concerns::GraphQLable

Concerns::GraphQLable::FILTER_ARGS, Concerns::GraphQLable::QUERY_ARG_ARGS

Instance Attribute Summary

Attributes inherited from Base

#mapped_attributes, #mapping

Attributes included from Concerns::Aliases

#type_coercer

Instance Method Summary collapse

Methods inherited from Base

cached_shopify_webhook?, client, #client, exclude_from_json, #formatted_id, #graphql_input, #headers, #include_root_in_json, inherited, #initialize, initialize_singleton!, #mapped?, #native_keys, platform_specific_class?, prefix=, #read_only?

Methods included from Countable

#count

Methods included from Concerns::GraphQLable

#graphql_mutation_string, #mutate_graphql, #remove_mutation_root_from

Methods included from Concerns::Aliases

#add_aliases!

Methods included from Concerns::FullJson

#as_full_json, #to_full_json

Methods included from Concerns::OverwriteRequestMethods

included

Methods included from Concerns::OverwriteInstanceMethods

#as_eplat_json, #as_json, #create, #create_resource_for, #to_eplat_json, #to_json, #update

Constructor Details

This class inherits a constructor from EPlat::Base

Instance Method Details

#collection_path(options = {}) ⇒ Object



28
29
30
31
32
# File 'lib/e_plat/resource/metafield.rb', line 28

def collection_path(options = {})
    raise "owner_id is not defined" unless owner_id.present?

    parents_metafield_path super(options)
end

#element_path(options = {}) ⇒ Object



22
23
24
25
26
# File 'lib/e_plat/resource/metafield.rb', line 22

def element_path(options = {})
    raise "owner_id is not defined" unless owner_id.present?

    parents_metafield_path super(options)
end

#normalize_attributesObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/e_plat/resource/metafield.rb', line 34

def normalize_attributes
    attributes.each {|k,v| attribute_will_change!(k) if READ_ONLY_ATTRIBUTES.exclude?(k.to_sym) }

    return unless client.bigcommerce?

    if permission_set.nil?
        self.permission_set = BIGCOMMERCE_DEFAULT_PERMISSION_SET 
    end

    if value?
        self.value = value.to_s
        self.value = "" if value == "false"
    end
end

#parent_classObject



49
50
51
52
53
# File 'lib/e_plat/resource/metafield.rb', line 49

def parent_class
    raise "owner_resource is not defined" unless owner_resource.present?
    
    client.platform_klass("EPlat::#{ owner_resource.classify }") || "EPlat::#{ owner_resource.classify }".constantize # e.g EPlat::Product
end