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.
29 30 31 32 33 |
# File 'lib/eco/api/organization/presets_factory.rb', line 29 def initialize(enviro: nil, policy_groups: nil) fatal("Expecting Environment object. Given: #{enviro}") if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment) @enviro = enviro @policy_groups = policy_groups end |
Class Method Details
.abilities ⇒ Object
23 24 25 |
# File 'lib/eco/api/organization/presets_factory.rb', line 23 def abilities @abilities ||= abilities_model.keys end |
.abilities_model ⇒ Object
15 16 17 |
# File 'lib/eco/api/organization/presets_factory.rb', line 15 def abilities_model @abilities_model ||= JSON.load(File.open(ABILITIES)) end |
Instance Method Details
#keys ⇒ Array<String>
Returns all the abilities.
36 37 38 |
# File 'lib/eco/api/organization/presets_factory.rb', line 36 def keys self.class.abilities end |
#valid?(preset) ⇒ Boolean
40 41 42 |
# File 'lib/eco/api/organization/presets_factory.rb', line 40 def valid?(preset) validate(perset).length == 0 end |
#validate(preset) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/eco/api/organization/presets_factory.rb', line 44 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 |