Class: TYCiCore::TemplateConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/tuya/ci/core/template/template_configurator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ TemplateConfig

Returns a new instance of TemplateConfig.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/tuya/ci/core/template/template_configurator.rb', line 77

def initialize(json)
	@project = 'PROJECT'
	@templates_json = json['templates']
	@last_version = json['last_version']

	@sub_keys = Hash.new
	@type = ""
	@alias = ""
	@desc = ""

	@type_map = Hash.new
	@templates_json.each do |item|
		key = item['type'].downcase
		@type_map[key] = item
		sub_type_map = Hash.new
		sub_types = item['sub_types']
		if sub_types && sub_types.size > 0
			sub_types.each do |sub_item|
				sub_type_map[sub_item['type']] = sub_item
			end
			item['sub_types_map'] = sub_type_map
		end
	end
	@keys = @type_map.keys
end

Instance Attribute Details

#aliasObject

Returns the value of attribute alias.



75
76
77
# File 'lib/tuya/ci/core/template/template_configurator.rb', line 75

def alias
  @alias
end

#keysObject

Returns the value of attribute keys.



74
75
76
# File 'lib/tuya/ci/core/template/template_configurator.rb', line 74

def keys
  @keys
end

#last_versionObject

Returns the value of attribute last_version.



73
74
75
# File 'lib/tuya/ci/core/template/template_configurator.rb', line 73

def last_version
  @last_version
end

#projectObject

Returns the value of attribute project.



75
76
77
# File 'lib/tuya/ci/core/template/template_configurator.rb', line 75

def project
  @project
end

#sub_keysObject

Returns the value of attribute sub_keys.



74
75
76
# File 'lib/tuya/ci/core/template/template_configurator.rb', line 74

def sub_keys
  @sub_keys
end

#templates_jsonObject

Returns the value of attribute templates_json.



72
73
74
# File 'lib/tuya/ci/core/template/template_configurator.rb', line 72

def templates_json
  @templates_json
end

#typeObject

Returns the value of attribute type.



75
76
77
# File 'lib/tuya/ci/core/template/template_configurator.rb', line 75

def type
  @type
end

Instance Method Details

#log_sub_type(type) ⇒ Object



119
120
121
122
123
124
125
126
127
128
# File 'lib/tuya/ci/core/template/template_configurator.rb', line 119

def log_sub_type(type)
	puts "Here is the #{type} module type list".magenta.underline
	item = @type_map[type]
	sub_types = item['sub_types']
	if sub_types && sub_types.size > 0
		sub_types.each do |sub_item|
			puts "  #{sub_item['type']} : #{sub_item['desc']}".yellow
		end
	end
end

#log_typeObject



112
113
114
115
116
117
# File 'lib/tuya/ci/core/template/template_configurator.rb', line 112

def log_type
	puts "Here is the module type list".magenta.underline
	@templates_json.each do |item|
		puts "#{item['type']} : #{item['desc']}".green
	end
end

#setup(type, sub_type) ⇒ Object



130
131
132
133
134
135
136
# File 'lib/tuya/ci/core/template/template_configurator.rb', line 130

def setup(type, sub_type)
	item = @type_map[type]
	if sub_type
		item = item['sub_types_map'][sub_type]
	end
	setup_item item
end

#setup_item(item) ⇒ Object



138
139
140
141
142
# File 'lib/tuya/ci/core/template/template_configurator.rb', line 138

def setup_item(item)
	@type = item['type']
	@alias = item['alias']
	@desc = item['desc']
end

#sub_types(key) ⇒ Object



103
104
105
106
107
108
109
110
# File 'lib/tuya/ci/core/template/template_configurator.rb', line 103

def sub_types(key)
	sub_type_map = @type_map[key]['sub_types_map']
	if sub_type_map
		sub_type_map.keys
	else
		nil
	end
end