Class: JSONModel::Client::EnumSource

Inherits:
Object
  • Object
show all
Defined in:
common/jsonmodel_client.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEnumSource

Returns a new instance of EnumSource.



511
512
513
# File 'common/jsonmodel_client.rb', line 511

def initialize
  @enumerations = self.class.fetch_enumerations
end

Class Method Details

.fetch_enumerationsObject



499
500
501
502
503
504
505
506
507
508
# File 'common/jsonmodel_client.rb', line 499

def self.fetch_enumerations
  enumerations = {}
  enumerations[:defaults] = {}
  JSONModel::JSONModel(:enumeration).all.each do |enumeration|
    enumerations[enumeration.name] = enumeration.values
    enumerations[:defaults][enumeration.name] = enumeration.default_value
  end

  enumerations
end

Instance Method Details

#default_value_forObject



525
526
527
# File 'common/jsonmodel_client.rb', line 525

def default_value_for
  @enumerations[:defaults].fetch(name)
end

#valid?(name, value) ⇒ Boolean

Returns:

  • (Boolean)


516
517
518
# File 'common/jsonmodel_client.rb', line 516

def valid?(name, value)
  values_for(name).include?(value)
end

#values_for(name) ⇒ Object



521
522
523
# File 'common/jsonmodel_client.rb', line 521

def values_for(name)
  @enumerations.fetch(name)
end