Class: LinkedRails::EnumValue
- Inherits:
-
Object
- Object
- LinkedRails::EnumValue
- Includes:
- ActiveModel::Model, Model
- Defined in:
- app/models/linked_rails/enum_value.rb
Constant Summary
Constants included from Model::Collections
Model::Collections::COLLECTION_CUSTOMIZABLE_OPTIONS, Model::Collections::COLLECTION_OPTIONS, Model::Collections::COLLECTION_STATIC_OPTIONS
Instance Attribute Summary collapse
-
#attr ⇒ Object
Returns the value of attribute attr.
-
#close_match ⇒ Object
Returns the value of attribute close_match.
-
#exact_match ⇒ Object
Returns the value of attribute exact_match.
-
#group_by ⇒ Object
Returns the value of attribute group_by.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
- #iri(**_opts) ⇒ Object
-
#key ⇒ Object
Returns the value of attribute key.
-
#klass ⇒ Object
Returns the value of attribute klass.
- #label ⇒ Object
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
- .class_for_params(params) ⇒ Object
- .enum_options(params) ⇒ Object
- .requested_resource(opts, _user_context) ⇒ Object
- .sanitized_sequence_iri(raw_iri) ⇒ Object
- .serializer_for_params(params) ⇒ Object
Instance Method Summary collapse
Methods included from Model
Methods included from Model::Singularable
#root_relative_iri, #root_relative_singular_iri, #singular_iri, #singular_iri?, #singular_iri_opts, #singular_iri_template, #singular_resource?
Methods included from Model::Serialization
#preview_includes, #show_includes
Methods included from Model::Menuable
Methods included from Model::IRI
#anonymous_iri, #anonymous_iri?, #iri_elements, #iri_opts, #reload, #root_relative_iri, #route_fragment
Methods included from Model::Enhancements
Methods included from Model::Dirty
Methods included from Model::Collections
#collection_for, #collection_iri, #collection_options_for, #collection_root_relative_iri, #parent_collections
Methods included from Model::Actionable
#action, #action_list, #action_triples, #actions, #collection_actions, #favorite_actions
Instance Attribute Details
#attr ⇒ Object
Returns the value of attribute attr.
8 9 10 |
# File 'app/models/linked_rails/enum_value.rb', line 8 def attr @attr end |
#close_match ⇒ Object
Returns the value of attribute close_match.
8 9 10 |
# File 'app/models/linked_rails/enum_value.rb', line 8 def close_match @close_match end |
#exact_match ⇒ Object
Returns the value of attribute exact_match.
8 9 10 |
# File 'app/models/linked_rails/enum_value.rb', line 8 def exact_match @exact_match end |
#group_by ⇒ Object
Returns the value of attribute group_by.
8 9 10 |
# File 'app/models/linked_rails/enum_value.rb', line 8 def group_by @group_by end |
#identifier ⇒ Object
Returns the value of attribute identifier.
8 9 10 |
# File 'app/models/linked_rails/enum_value.rb', line 8 def identifier @identifier end |
#iri(**_opts) ⇒ Object
15 16 17 |
# File 'app/models/linked_rails/enum_value.rb', line 15 def iri(**_opts) @iri || iri_with_root(RDF::URI("/enums/#{klass.name.tableize}/#{attr}##{key}")) end |
#key ⇒ Object
Returns the value of attribute key.
8 9 10 |
# File 'app/models/linked_rails/enum_value.rb', line 8 def key @key end |
#klass ⇒ Object
Returns the value of attribute klass.
8 9 10 |
# File 'app/models/linked_rails/enum_value.rb', line 8 def klass @klass end |
#label ⇒ Object
11 12 13 |
# File 'app/models/linked_rails/enum_value.rb', line 11 def label label_from_variable || LinkedRails.translate(:enum, :label, self) end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'app/models/linked_rails/enum_value.rb', line 8 def type @type end |
Class Method Details
.class_for_params(params) ⇒ Object
34 35 36 37 38 |
# File 'app/models/linked_rails/enum_value.rb', line 34 def class_for_params(params) LinkedRails.linked_models.detect do |klass| klass.to_s == ([params[:module]].compact + [params[:klass]&.singularize]).join('/').classify end end |
.enum_options(params) ⇒ Object
40 41 42 |
# File 'app/models/linked_rails/enum_value.rb', line 40 def (params) serializer_for_params(params)&.(params[:attribute]) end |
.requested_resource(opts, _user_context) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/linked_rails/enum_value.rb', line 44 def requested_resource(opts, _user_context) = (opts[:params]) return unless LinkedRails::Sequence.new( .values, id: sanitized_sequence_iri(opts[:iri]), scope: LinkedRails::EnumValuePolicy::Scope ) end |
.sanitized_sequence_iri(raw_iri) ⇒ Object
56 57 58 59 60 61 62 |
# File 'app/models/linked_rails/enum_value.rb', line 56 def sanitized_sequence_iri(raw_iri) iri = RDF::URI(raw_iri) iri.query = nil iri.fragment = nil iri.path = iri.path.split('.').first iri end |
.serializer_for_params(params) ⇒ Object
64 65 66 67 68 |
# File 'app/models/linked_rails/enum_value.rb', line 64 def serializer_for_params(params) klass = class_for_params(params) RDF::Serializers.serializer_for(klass) if klass end |
Instance Method Details
#rdf_type ⇒ Object
19 20 21 |
# File 'app/models/linked_rails/enum_value.rb', line 19 def rdf_type type end |
#to_param ⇒ Object
23 24 25 |
# File 'app/models/linked_rails/enum_value.rb', line 23 def to_param key end |