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.



519
520
521
# File 'common/jsonmodel_client.rb', line 519

def initialize
  @enumerations = self.class.fetch_enumerations
end

Class Method Details

.fetch_enumerationsObject



507
508
509
510
511
512
513
514
515
516
# File 'common/jsonmodel_client.rb', line 507

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_for(name) ⇒ Object



533
534
535
# File 'common/jsonmodel_client.rb', line 533

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

#valid?(name, value) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#values_for(name) ⇒ Object



529
530
531
# File 'common/jsonmodel_client.rb', line 529

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