Class: Eco::API::Organization::PresetsFactory
- Defined in:
- lib/eco/api/organization/presets_factory.rb
Constant Summary collapse
- ABILITIES =
File.join(__dir__, 'presets_values.json')
- INTEGRITY =
File.join(__dir__, 'presets_integrity.json')
Class Method Summary collapse
- .abilities ⇒ Object
- .abilities_model ⇒ Object
- .all_abilities(hash = {}) ⇒ Object
- .integrity_model ⇒ Object
Instance Method Summary collapse
-
#initialize(enviro: nil, policy_groups: nil) ⇒ PresetsFactory
constructor
A new instance of PresetsFactory.
-
#keys ⇒ Array<String>
All the abilities.
- #valid?(preset) ⇒ Boolean
- #validate(preset) ⇒ Object
Constructor Details
#initialize(enviro: nil, policy_groups: nil) ⇒ PresetsFactory
Returns a new instance of PresetsFactory.
26 27 28 29 30 31 32 |
# File 'lib/eco/api/organization/presets_factory.rb', line 26 def initialize(enviro: nil, policy_groups: nil) msg = "Expecting Environment object. Given: #{enviro.class}" fatal(msg) if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment) @enviro = enviro @policy_groups = policy_groups end |
Class Method Details
.abilities ⇒ Object
21 22 23 |
# File 'lib/eco/api/organization/presets_factory.rb', line 21 def abilities @abilities ||= abilities_model.keys end |
.abilities_model ⇒ Object
13 14 15 |
# File 'lib/eco/api/organization/presets_factory.rb', line 13 def abilities_model @abilities_model ||= JSON.load(File.open(ABILITIES)) end |
Instance Method Details
#keys ⇒ Array<String>
Returns all the abilities.
35 36 37 |
# File 'lib/eco/api/organization/presets_factory.rb', line 35 def keys self.class.abilities end |
#valid?(preset) ⇒ Boolean
39 40 41 |
# File 'lib/eco/api/organization/presets_factory.rb', line 39 def valid?(preset) validate(preset).empty? end |
#validate(preset) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/eco/api/organization/presets_factory.rb', line 43 def validate(preset) [].tap do |errors| if (err = preset_errors(preset)) errors << "{ '#{key}' preset -> #{err}}" end if (err = preset_integrity(preset)) errors << "{ '#{key}' preset -> #{err}}" end end end |