Class: KStarter::Database::ConfigModel
- Defined in:
- lib/k_starter/database/config_model.rb
Overview
Handle access to configuration data files
Constant Summary collapse
- DEFAULT_FILE_NAME =
'k_starter.config.json'
Instance Attribute Summary
Attributes inherited from BaseModel
#backup_folder, #data, #filename, #folder
Instance Method Summary collapse
-
#get_project_type(type, variant = nil) ⇒ Object
rubocop:enable Naming/AccessorMethodName.
- #github_organizations ⇒ Object
- #github_user ⇒ Object
-
#initialize(**args) ⇒ ConfigModel
constructor
A new instance of ConfigModel.
- #project_variants(type) ⇒ Object
-
#set_project_type(project_type) ⇒ Object
rubocop:disable Naming/AccessorMethodName.
Constructor Details
#initialize(**args) ⇒ ConfigModel
Returns a new instance of ConfigModel.
9 10 11 12 13 14 |
# File 'lib/k_starter/database/config_model.rb', line 9 def initialize(**args) args = { file: DEFAULT_FILE_NAME }.merge(args) super(**args) initialize_model end |
Instance Method Details
#get_project_type(type, variant = nil) ⇒ Object
rubocop:enable Naming/AccessorMethodName
32 33 34 35 36 37 38 |
# File 'lib/k_starter/database/config_model.rb', line 32 def get_project_type(type, variant = nil) index = project_type_index(type, variant) return nil if index.nil? @data[:project_types][index] end |
#github_organizations ⇒ Object
54 55 56 |
# File 'lib/k_starter/database/config_model.rb', line 54 def github_organizations data[:github][:organizations] end |
#github_user ⇒ Object
50 51 52 |
# File 'lib/k_starter/database/config_model.rb', line 50 def github_user data[:github][:user] end |
#project_variants(type) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/k_starter/database/config_model.rb', line 40 def project_variants(type) type = as_sym(type) # project variants without nil or empty data[:project_types] .select { |t| t[:type]&.to_sym == type } .map { |t| t[:variant]&.to_sym } .compact end |
#set_project_type(project_type) ⇒ Object
rubocop:disable Naming/AccessorMethodName
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/k_starter/database/config_model.rb', line 17 def set_project_type(project_type) project_type = project_type.to_h unless project_type.is_a?(Hash) index = project_type_index(project_type[:type], project_type[:variant]) if index.nil? data[:project_types] << project_type else data[:project_types][index] = project_type end write end |