Method: Gerd::Model::GithubState#initialize
- Defined in:
- lib/gerd/model/model.rb
#initialize(state_content) ⇒ GithubState
Returns a new instance of GithubState.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/gerd/model/model.rb', line 21 def initialize(state_content) validators = [] validators << Gerd::Model::SchemaValidator.new( Proc.new { | data | data['organisation'] != nil }, "Should have an organisation present") validators << Gerd::Model::SchemaValidator.new( Proc.new { | data | data['teams'].class == Hash }, "Should have a teams element present") validators << Gerd::Model::SchemaValidator.new( Proc.new { | data | data['repositories'].class == Hash }, "Should have a repositories element present") validators << Gerd::Model::SchemaValidator.new( Proc.new { | data | data['members'].class == Hash }, "Should have a members element present") failures = [] validators.each do | validator | result = validator.evaluate(state_content) failures << result unless result.valid? end @failures = failures if failures.length != 0 failures.each do | failure | puts failure. end puts state_content raise Gerd::Exceptions::ValidationException.new("Failed to validate #{failures}") end @organisation = state_content['organisation'] @teams = state_content['teams'] @members = state_content['members'] @repositories = state_content['repositories'] end |