Class: RGovData::Service
- Inherits:
-
Object
- Object
- RGovData::Service
- Includes:
- CommonConfig, Dn
- Defined in:
- lib/rgovdata/service/service.rb
Overview
A Service describes a specific service It encapsulates access to the underlying service implementation
Direct Known Subclasses
Instance Attribute Summary collapse
-
#native_instance ⇒ Object
readonly
Returns the native service object if applicable By default, returns self.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
-
.get_instance(options = {}) ⇒ Object
Returns the appropriate Service class for the given uri and type +options may be a RGovData::ServiceListing or a Hash If
options
is a hash, it requires the following members:uri
type
credentialset
.
Instance Method Summary collapse
- #credentialset ⇒ Object
-
#dataset_keys ⇒ Object
Returns an array of DataSets (keys) for the service => needs to be overridden for each service type.
-
#datasets ⇒ Object
Returns an array of DataSets for the service => may need to be overridden for a specific service type.
-
#find(id) ⇒ Object
(also: #find_by_id)
Returns the first dataset matching
key
. -
#get_dataset(key) ⇒ Object
Returns the dataset(s) matching
key
. -
#initialize(options) ⇒ Service
constructor
new
requires +options may be a RGovData::ServiceListing or a Hash Ifoptions
is a hash, it requires the following members:uri
type
transport
credentialset
. -
#meta_attributes ⇒ Object
Returns array of attributes that describe the specific entity => overrides RGovData::Dn.meta_attributes.
-
#realm ⇒ Object
attribute accessors.
- #service_key ⇒ Object
- #transport ⇒ Object
- #type ⇒ Object
- #uri ⇒ Object
Methods included from Dn
#attributes, #id, #initialization_hash, #records, #to_param, #to_s
Methods included from CommonConfig
Constructor Details
#initialize(options) ⇒ Service
new
requires +options may be a RGovData::ServiceListing or a Hash If options
is a hash, it requires the following members: uri
type
transport
credentialset
35 36 37 38 39 40 41 42 43 |
# File 'lib/rgovdata/service/service.rb', line 35 def initialize() @options = if .is_a?(Hash) OpenStruct.new() elsif .class <= RGovData::ServiceListing .dup # avoid circular refs else OpenStruct.new end end |
Instance Attribute Details
#native_instance ⇒ Object (readonly)
Returns the native service object if applicable By default, returns self
10 11 12 |
# File 'lib/rgovdata/service/service.rb', line 10 def native_instance @native_instance end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/rgovdata/service/service.rb', line 9 def @options end |
Class Method Details
.get_instance(options = {}) ⇒ Object
Returns the appropriate Service class for the given uri and type +options may be a RGovData::ServiceListing or a Hash If options
is a hash, it requires the following members: uri
type
credentialset
19 20 21 22 23 24 25 |
# File 'lib/rgovdata/service/service.rb', line 19 def get_instance(={}) type = (.class <= RGovData::ServiceListing) ? .type : [:type] service_class = "RGovData::#{type.to_s.capitalize}Service".constantize service_class.new() rescue # invalid or not a supported type nil end |
Instance Method Details
#credentialset ⇒ Object
51 |
# File 'lib/rgovdata/service/service.rb', line 51 def credentialset ; .credentialset ; end |
#dataset_keys ⇒ Object
Returns an array of DataSets (keys) for the service
> needs to be overridden for each service type
76 77 78 |
# File 'lib/rgovdata/service/service.rb', line 76 def dataset_keys [] end |
#datasets ⇒ Object
Returns an array of DataSets for the service
> may need to be overridden for a specific service type
67 68 69 70 71 72 |
# File 'lib/rgovdata/service/service.rb', line 67 def datasets dataset_class = "RGovData::#{type.to_s.capitalize}DataSet".constantize @datasets ||= dataset_class.load_datasets(self) rescue [] end |
#find(id) ⇒ Object Also known as: find_by_id
Returns the first dataset matching key
87 88 89 |
# File 'lib/rgovdata/service/service.rb', line 87 def find(id) Array(get_dataset(id)).first end |
#get_dataset(key) ⇒ Object
Returns the dataset(s) matching key
81 82 83 84 85 |
# File 'lib/rgovdata/service/service.rb', line 81 def get_dataset(key) return nil unless datasets && !datasets.empty? matches = datasets.select {|s| s.dataset_key =~ /#{key}/} matches.count == 1 ? matches.first : matches end |
#meta_attributes ⇒ Object
Returns array of attributes that describe the specific entity
> overrides RGovData::Dn.meta_attributes
55 56 57 |
# File 'lib/rgovdata/service/service.rb', line 55 def [:id,:realm,:service_key,:uri,:type,:transport,:credentialset] end |
#realm ⇒ Object
attribute accessors
46 |
# File 'lib/rgovdata/service/service.rb', line 46 def realm ; .realm ; end |
#service_key ⇒ Object
47 |
# File 'lib/rgovdata/service/service.rb', line 47 def service_key ; .service_key ; end |
#transport ⇒ Object
50 |
# File 'lib/rgovdata/service/service.rb', line 50 def transport ; .transport ; end |
#type ⇒ Object
49 |
# File 'lib/rgovdata/service/service.rb', line 49 def type ; .type ; end |
#uri ⇒ Object
48 |
# File 'lib/rgovdata/service/service.rb', line 48 def uri ; .uri ; end |