Class: JSONAPI::Relationship::ToMany
- Inherits:
-
JSONAPI::Relationship
- Object
- JSONAPI::Relationship
- JSONAPI::Relationship::ToMany
- Defined in:
- lib/jsonapi/relationship.rb
Instance Attribute Summary collapse
-
#reflect ⇒ Object
readonly
Returns the value of attribute reflect.
Attributes inherited from JSONAPI::Relationship
#_routed, #_warned_missing_route, #acts_as_set, #allow_include, #always_include_optional_linkage_data, #class_name, #custom_methods, #eager_load_on_include, #foreign_key, #inverse_relationship, #name, #options, #parent_resource, #polymorphic
Instance Method Summary collapse
- #allow_include?(context = nil) ⇒ Boolean
- #include_optional_linkage_data? ⇒ Boolean
-
#initialize(name, options = {}) ⇒ ToMany
constructor
A new instance of ToMany.
- #to_s ⇒ Object
Methods inherited from JSONAPI::Relationship
#_exclude_links, #belongs_to?, #exclude_link?, #exclude_links, polymorphic_types, #primary_key, #readonly?, #relation_name, #resource_klass, #resource_types, #table_name, #type
Constructor Details
#initialize(name, options = {}) ⇒ ToMany
Returns a new instance of ToMany.
185 186 187 188 189 190 191 192 193 |
# File 'lib/jsonapi/relationship.rb', line 185 def initialize(name, = {}) super @class_name = .fetch(:class_name, name.to_s.camelize.singularize) @foreign_key ||= "#{name.to_s.singularize}_ids".to_sym @reflect = .fetch(:reflect, true) == true if parent_resource @inverse_relationship = .fetch(:inverse_relationship, parent_resource._type.to_s.singularize.to_sym) end end |
Instance Attribute Details
#reflect ⇒ Object (readonly)
Returns the value of attribute reflect.
183 184 185 |
# File 'lib/jsonapi/relationship.rb', line 183 def reflect @reflect end |
Instance Method Details
#allow_include?(context = nil) ⇒ Boolean
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/jsonapi/relationship.rb', line 207 def allow_include?(context = nil) strategy = if @allow_include.nil? JSONAPI.configuration.default_allow_include_to_many else @allow_include end if !!strategy == strategy #check for boolean return strategy elsif strategy.is_a?(Symbol) || strategy.is_a?(String) parent_resource.send(strategy, context) else strategy.call(context) end end |
#include_optional_linkage_data? ⇒ Boolean
201 202 203 204 205 |
# File 'lib/jsonapi/relationship.rb', line 201 def include_optional_linkage_data? # :nocov: @always_include_optional_linkage_data || JSONAPI::configuration.always_include_to_many_linkage_data # :nocov: end |
#to_s ⇒ Object
195 196 197 198 199 |
# File 'lib/jsonapi/relationship.rb', line 195 def to_s # :nocov: useful for debugging "#{parent_resource}.#{name}(ToMany)" # :nocov: end |