Class: LinkedData::Client::Base
- Inherits:
-
Object
- Object
- LinkedData::Client::Base
- Defined in:
- lib/ontologies_api_client/base.rb
Direct Known Subclasses
Models::Category, Models::Class, Models::Group, Models::Mapping, Models::Metrics, Models::Note, Models::Ontology, Models::OntologySubmission, Models::Project, Models::Reply, Models::Review, Models::Slice, Models::User
Constant Summary collapse
- HTTP =
LinkedData::Client::HTTP
Class Attribute Summary collapse
-
.attrs_always_present ⇒ Object
Returns the value of attribute attrs_always_present.
-
.include_attrs ⇒ Object
Returns the value of attribute include_attrs.
-
.include_attrs_full ⇒ Object
Returns the value of attribute include_attrs_full.
-
.media_type ⇒ Object
Returns the value of attribute media_type.
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#instance_values ⇒ Object
writeonly
Sets the attribute instance_values.
-
#links ⇒ Object
Returns the value of attribute links.
Class Method Summary collapse
-
.attributes(full = false) ⇒ Object
Passing full: true to explore methods will give you more attributes.
- .class_for_type(media_type) ⇒ Object
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#explore ⇒ Object
Retrieve a set of data using a link provided on an object This instantiates an instance of this class and uses method missing to determine which link to follow.
- #id ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #marshal_dump ⇒ Object
- #marshal_load(data) ⇒ Object
- #method_missing(meth, *args, &block) ⇒ Object
- #respond_to?(meth, private = false) ⇒ Boolean
- #to_hash ⇒ Object (also: #to_param)
- #to_jsonld ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
31 32 33 34 35 36 37 38 39 |
# File 'lib/ontologies_api_client/base.rb', line 31 def initialize( = {}) read_only = .delete(:read_only) || false values = [:values] if values.is_a?(Hash) && !values.empty? create_attributes(values.keys) populate_attributes(values) end create_attributes(self.class.attrs_always_present || []) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ontologies_api_client/base.rb', line 82 def method_missing(meth, *args, &block) if meth.to_s[-1].eql?("=") # This enables OpenStruct-like behavior for setting attributes that aren't defined attr = meth.to_s.chomp("=").to_sym create_attributes([attr]) populate_attributes(attr => args.first) else nil end end |
Class Attribute Details
.attrs_always_present ⇒ Object
Returns the value of attribute attrs_always_present.
9 10 11 |
# File 'lib/ontologies_api_client/base.rb', line 9 def attrs_always_present @attrs_always_present end |
.include_attrs ⇒ Object
Returns the value of attribute include_attrs.
9 10 11 |
# File 'lib/ontologies_api_client/base.rb', line 9 def include_attrs @include_attrs end |
.include_attrs_full ⇒ Object
Returns the value of attribute include_attrs_full.
9 10 11 |
# File 'lib/ontologies_api_client/base.rb', line 9 def include_attrs_full @include_attrs_full end |
.media_type ⇒ Object
Returns the value of attribute media_type.
9 10 11 |
# File 'lib/ontologies_api_client/base.rb', line 9 def media_type @media_type end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
6 7 8 |
# File 'lib/ontologies_api_client/base.rb', line 6 def context @context end |
#instance_values=(value) ⇒ Object (writeonly)
Sets the attribute instance_values
5 6 7 |
# File 'lib/ontologies_api_client/base.rb', line 5 def instance_values=(value) @instance_values = value end |
#links ⇒ Object
Returns the value of attribute links.
6 7 8 |
# File 'lib/ontologies_api_client/base.rb', line 6 def links @links end |
Class Method Details
.attributes(full = false) ⇒ Object
Passing full: true to explore methods will give you more attributes
14 15 16 17 18 19 20 |
# File 'lib/ontologies_api_client/base.rb', line 14 def self.attributes(full = false) if full && @include_attrs_full @include_attrs_full else @include_attrs end end |
.class_for_type(media_type) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/ontologies_api_client/base.rb', line 22 def self.class_for_type(media_type) classes = LinkedData::Client::Models.constants classes.each do |cls| media_type_cls = LinkedData::Client::Models.const_get(cls) return media_type_cls if media_type_cls.media_type.eql?(media_type) end nil end |
Instance Method Details
#[](key) ⇒ Object
97 98 99 100 |
# File 'lib/ontologies_api_client/base.rb', line 97 def [](key) key = "@#{key}" unless key.to_s.start_with?("@") instance_variable_get(key) end |
#[]=(key, value) ⇒ Object
102 103 104 105 |
# File 'lib/ontologies_api_client/base.rb', line 102 def []=(key, value) create_attributes([key]) populate_attributes({key.to_sym => value}) end |
#explore ⇒ Object
Retrieve a set of data using a link provided on an object This instantiates an instance of this class and uses method missing to determine which link to follow
53 54 55 |
# File 'lib/ontologies_api_client/base.rb', line 53 def explore LinkedData::Client::LinkExplorer.new(@links, self) end |
#id ⇒ Object
41 42 43 |
# File 'lib/ontologies_api_client/base.rb', line 41 def id @id end |
#marshal_dump ⇒ Object
72 73 74 |
# File 'lib/ontologies_api_client/base.rb', line 72 def marshal_dump Hash[self.instance_variables.map { |v| [v, self.instance_variable_get("#{v}")] }] end |
#marshal_load(data) ⇒ Object
76 77 78 79 80 |
# File 'lib/ontologies_api_client/base.rb', line 76 def marshal_load(data) data ||= {} create_attributes(data.keys) populate_attributes(data) end |
#respond_to?(meth, private = false) ⇒ Boolean
93 94 95 |
# File 'lib/ontologies_api_client/base.rb', line 93 def respond_to?(meth, private = false) true end |
#to_hash ⇒ Object Also known as: to_param
57 58 59 60 61 62 63 64 65 |
# File 'lib/ontologies_api_client/base.rb', line 57 def to_hash dump = marshal_dump dump.keys.each do |k| next unless k.to_s[0].eql?("@") dump[k[1..-1].to_sym] = dump[k] dump.delete(k) end dump end |
#to_jsonld ⇒ Object
68 69 70 |
# File 'lib/ontologies_api_client/base.rb', line 68 def to_jsonld HTTP.get(self.id, {}, {raw: true}) end |
#type ⇒ Object
45 46 47 |
# File 'lib/ontologies_api_client/base.rb', line 45 def type @type end |