Class: EPlat::Mapping::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/e_plat/mapping/base.rb

Instance Method Summary collapse

Instance Method Details

#aliasesObject



24
25
26
27
28
29
30
31
# File 'lib/e_plat/mapping/base.rb', line 24

def aliases
	native_attribute_aliases.map do |alias_hash|
		next unless alias_hash[:alias_attribute]
		
		keys = alias_hash[:alias_attribute].values[0..1]
		Hash[*keys]
	end.compact_blank.inject(&:merge) || {}
end

#mappable_keysObject



43
44
45
# File 'lib/e_plat/mapping/base.rb', line 43

def mappable_keys
	native_attribute_aliases.map{|a| a.values.first[:e_plat_key]}.presence || :all
end

#native_attribute_aliasesObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/e_plat/mapping/base.rb', line 13

def native_attribute_aliases
	[
		# {
		# 	alias_attribute: {native_key: "description",  e_plat_key: "body_html"}
		# },
		# {
		# 	alias_attribute_with_custom_getter: {native_key:, e_plat_key:, via: }
		# }
	]
end

#native_attributesObject



9
10
11
# File 'lib/e_plat/mapping/base.rb', line 9

def native_attributes
	[]
end

#native_top_keyObject



5
6
7
# File 'lib/e_plat/mapping/base.rb', line 5

def native_top_key
	:itself # or top key of JSON response e.g. "data", "product", 
end

#to_e_plat_keys(attributes) ⇒ Object



38
39
40
41
# File 'lib/e_plat/mapping/base.rb', line 38

def to_e_plat_keys(attributes)
	as = aliases
	attributes.transform_keys{|key| (as[key]) ? as[key] : key }
end

#to_native_keys(attributes) ⇒ Object



33
34
35
36
# File 'lib/e_plat/mapping/base.rb', line 33

def to_native_keys(attributes)
	as = aliases.invert
	attributes.transform_keys{|key| (as[key]) ? as[key] : key }
end