Class: ResoTransport::Resource
- Inherits:
-
Struct
- Object
- Struct
- ResoTransport::Resource
- Defined in:
- lib/reso_transport/resource.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#entity_set ⇒ Object
Returns the value of attribute entity_set.
-
#local ⇒ Object
Returns the value of attribute local.
-
#localizations ⇒ Object
Returns the value of attribute localizations.
Instance Method Summary collapse
- #entity_type ⇒ Object
- #expandable ⇒ Object
- #get(params) ⇒ Object
- #inspect ⇒ Object
- #localization(name) ⇒ Object
- #md ⇒ Object
- #name ⇒ Object
- #parse(results) ⇒ Object
- #properties ⇒ Object
- #property(name) ⇒ Object
- #query ⇒ Object
- #request ⇒ Object
- #schema ⇒ Object
- #to_s ⇒ Object
- #url ⇒ Object
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client
2 3 4 |
# File 'lib/reso_transport/resource.rb', line 2 def client @client end |
#entity_set ⇒ Object
Returns the value of attribute entity_set
2 3 4 |
# File 'lib/reso_transport/resource.rb', line 2 def entity_set @entity_set end |
#local ⇒ Object
Returns the value of attribute local
2 3 4 |
# File 'lib/reso_transport/resource.rb', line 2 def local @local end |
#localizations ⇒ Object
Returns the value of attribute localizations
2 3 4 |
# File 'lib/reso_transport/resource.rb', line 2 def localizations @localizations end |
Instance Method Details
#entity_type ⇒ Object
23 24 25 |
# File 'lib/reso_transport/resource.rb', line 23 def entity_type @entity_type ||= schema.entity_types.detect { |et| et.name == entity_set.entity_type } end |
#expandable ⇒ Object
19 20 21 |
# File 'lib/reso_transport/resource.rb', line 19 def entity_type. end |
#get(params) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/reso_transport/resource.rb', line 39 def get(params) client.connection.get(url, params) do |req| req.headers['Accept'] = 'application/json' @request = req end end |
#inspect ⇒ Object
65 66 67 |
# File 'lib/reso_transport/resource.rb', line 65 def inspect to_s end |
#localization(name) ⇒ Object
56 57 58 59 |
# File 'lib/reso_transport/resource.rb', line 56 def localization(name) self.local = localizations[name] if localizations.key?(name) self end |
#md ⇒ Object
31 32 33 |
# File 'lib/reso_transport/resource.rb', line 31 def md client. end |
#name ⇒ Object
7 8 9 |
# File 'lib/reso_transport/resource.rb', line 7 def name entity_set.name end |
#parse(results) ⇒ Object
35 36 37 |
# File 'lib/reso_transport/resource.rb', line 35 def parse(results) results.map { |r| entity_type.parse(r) } end |
#properties ⇒ Object
15 16 17 |
# File 'lib/reso_transport/resource.rb', line 15 def properties entity_type.properties end |
#property(name) ⇒ Object
11 12 13 |
# File 'lib/reso_transport/resource.rb', line 11 def property(name) properties.detect { |p| p.name == name } end |
#query ⇒ Object
3 4 5 |
# File 'lib/reso_transport/resource.rb', line 3 def query Query.new(self) end |
#request ⇒ Object
69 70 71 72 73 |
# File 'lib/reso_transport/resource.rb', line 69 def request return @request.to_h if @request.respond_to? :to_h {} end |
#schema ⇒ Object
27 28 29 |
# File 'lib/reso_transport/resource.rb', line 27 def schema @schema ||= md.schemas.detect { |s| s.namespace == entity_set.schema } end |
#to_s ⇒ Object
61 62 63 |
# File 'lib/reso_transport/resource.rb', line 61 def to_s %(#<ResoTransport::Resource entity_set="#{name}", schema="#{schema&.namespace}">) end |
#url ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/reso_transport/resource.rb', line 46 def url return local['ResourcePath'].gsub(%r{^/}, '') if local raise LocalizationRequired, self if localizations.any? && local.nil? return "#{name}/replication" if client.use_replication_endpoint name end |