lib/eco/api/organization/presets_factory.rb in eco-helpers-2.0.15 vs lib/eco/api/organization/presets_factory.rb in eco-helpers-2.0.16

- old
+ new

@@ -1,10 +1,31 @@ module Eco module API module Organization class PresetsFactory + + class << self + + def all_abilities(hash = {}) + Hash[abilities.each_with_object(nil).to_a].merge(hash) + end + + def abilities_model + @abilities_model ||= JSON.load(File.open(ABILITIES)) + end + + def integrity_model + @integrity_model ||= JSON.load(File.open(INTEGRITY)) + end + + def abilities + @abilities ||= abilities_model.keys + end + + end + ABILITIES = File.join(__dir__, 'presets_values.json') INTEGRITY = File.join(__dir__, 'presets_integrity.json') DEFAULT_CUSTOM = 'presets_custom.json' DEFAULT_MAP = 'presets_map.json' @@ -109,11 +130,11 @@ " Integrity errors: { #{errors.join(", ")} }" if errors.length > 0 end end def integrity_model - @integrity_model ||= JSON.load(File.open(INTEGRITY)) + self.class.integrity_model end def value_exists?(ability, value) abilities_model_inverted.dig(ability, value) end @@ -127,10 +148,10 @@ def ability_value_idx(ability, value) abilities_model[ability].index(value) end def abilities_model - @abilities_model ||= JSON.load(File.open(ABILITIES)) + self.class.abilities_model end def policy_groups return @policy_groups if @policy_groups.is_a?(Eco::API::Organization::PolicyGroups) @policy_groups ||= @enviro&.api&.policy_groups.to_a