Class: ServiceTypeValue
- Inherits:
-
Object
- Object
- ServiceTypeValue
- Defined in:
- app/models/service_type_value.rb
Overview
This model is the actual list of valid service types. Not ActiveRecord, just load from config files into memory (loaded on file load).
ServiceTypeValue’s also have displable strings, stored in the display_name attribute, and possibly custom display_name_plural
Constant Summary collapse
- @@distro_conf_file =
File.join(Umlaut::Engine.root, "db", "orig_fixed_data", "service_type_values.yml")
- @@local_conf_file =
File.join(Rails.root, "config", "umlaut_service_type_values.yml")
Class Attribute Summary collapse
-
.values ⇒ Object
Returns the value of attribute values.
Instance Attribute Summary collapse
-
#display_name ⇒ Object
Returns the value of attribute display_name.
-
#display_name_plural ⇒ Object
Returns the value of attribute display_name_plural.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
- .[](name) ⇒ Object
- .find(name) ⇒ Object
-
.load_values! ⇒ Object
Loads from config files, distro and local, into memory.
Instance Method Summary collapse
- #display_name_pluralize ⇒ Object
-
#initialize(hash) ⇒ ServiceTypeValue
constructor
A new instance of ServiceTypeValue.
Constructor Details
#initialize(hash) ⇒ ServiceTypeValue
Returns a new instance of ServiceTypeValue.
14 15 16 17 18 |
# File 'app/models/service_type_value.rb', line 14 def initialize(hash) hash.each_pair do |key, value| self.send(key.to_s+"=", value) end end |
Class Attribute Details
.values ⇒ Object
Returns the value of attribute values.
12 13 14 |
# File 'app/models/service_type_value.rb', line 12 def values @values end |
Instance Attribute Details
#display_name ⇒ Object
Returns the value of attribute display_name.
10 11 12 |
# File 'app/models/service_type_value.rb', line 10 def display_name @display_name end |
#display_name_plural ⇒ Object
Returns the value of attribute display_name_plural.
10 11 12 |
# File 'app/models/service_type_value.rb', line 10 def display_name_plural @display_name_plural end |
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'app/models/service_type_value.rb', line 10 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'app/models/service_type_value.rb', line 10 def name @name end |
Class Method Details
.[](name) ⇒ Object
24 25 26 |
# File 'app/models/service_type_value.rb', line 24 def self.[](name) find(name) end |
.find(name) ⇒ Object
20 21 22 23 |
# File 'app/models/service_type_value.rb', line 20 def self.find(name) load_values! if values.nil? values[name.to_sym] or raise ArgumentError.new("No ServiceTypeValue found for #{name}") end |
.load_values! ⇒ Object
Loads from config files, distro and local, into memory.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/service_type_value.rb', line 37 def self.load_values! # Load in starting set of ServiceTypeValue, merge in local defines. service_type_values = YAML.load_file( @@distro_conf_file ) local_overrides = File.exists?( @@local_conf_file ) ? YAML.load_file(@@local_conf_file) : nil # Merge in the params for each service type with possible # existing params. if ( local_overrides ) local_overrides.each do |name, params| service_type_values[name] ||= {} service_type_values[name].merge!( params ) end end self.values = {} service_type_values.each_pair do |name, hash| self.values[name.to_sym] = ServiceTypeValue.new(hash.merge(:name => name)) end end |
Instance Method Details
#display_name_pluralize ⇒ Object
28 29 30 |
# File 'app/models/service_type_value.rb', line 28 def display_name_pluralize return self.display_name_plural || self.display_name.pluralize end |