Class: Gerd::Model::GithubState
- Inherits:
-
Object
- Object
- Gerd::Model::GithubState
- Defined in:
- lib/gerd/model/model.rb
Instance Attribute Summary collapse
-
#failures ⇒ Object
Returns the value of attribute failures.
-
#members ⇒ Object
Returns the value of attribute members.
-
#organisation ⇒ Object
Returns the value of attribute organisation.
-
#repositories ⇒ Object
Returns the value of attribute repositories.
-
#teams ⇒ Object
Returns the value of attribute teams.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(state_content) ⇒ GithubState
constructor
A new instance of GithubState.
- #serialize ⇒ Object
Constructor Details
#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 |
Instance Attribute Details
#failures ⇒ Object
Returns the value of attribute failures.
9 10 11 |
# File 'lib/gerd/model/model.rb', line 9 def failures @failures end |
#members ⇒ Object
Returns the value of attribute members.
9 10 11 |
# File 'lib/gerd/model/model.rb', line 9 def members @members end |
#organisation ⇒ Object
Returns the value of attribute organisation.
9 10 11 |
# File 'lib/gerd/model/model.rb', line 9 def organisation @organisation end |
#repositories ⇒ Object
Returns the value of attribute repositories.
9 10 11 |
# File 'lib/gerd/model/model.rb', line 9 def repositories @repositories end |
#teams ⇒ Object
Returns the value of attribute teams.
9 10 11 |
# File 'lib/gerd/model/model.rb', line 9 def teams @teams end |
Class Method Details
.from_json(json) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/gerd/model/model.rb', line 11 def self.from_json(json) begin return Gerd::Model::GithubState.new(JSON.parse(json)) rescue => e puts json raise Gerd::Exceptions::ValidationException.new("Couldn't parse JSON") end end |
Instance Method Details
#serialize ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/gerd/model/model.rb', line 50 def serialize json = { 'organisation' => @organisation, 'teams' => @teams, 'members' => @members, 'repositories' => @repositories } json end |