Class: JSONAPIonify::Api::Relationship
- Inherits:
-
Object
- Object
- JSONAPIonify::Api::Relationship
- Extended by:
- Blocks, JSONAPIonify::Autoload
- Includes:
- Documentation
- Defined in:
- lib/jsonapionify/api/relationship.rb
Defined Under Namespace
Modules: Blocks, Documentation Classes: Many, One
Instance Attribute Summary collapse
-
#class_proc ⇒ Object
readonly
Returns the value of attribute class_proc.
-
#hidden ⇒ Object
readonly
Returns the value of attribute hidden.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#resolve ⇒ Object
readonly
Returns the value of attribute resolve.
Instance Method Summary collapse
- #hidden_for_action?(action_name) ⇒ Boolean
-
#initialize(owner, name, resource: nil, hidden: :list, resolve: proc { |n, o| o.send(n) }, &block) ⇒ Relationship
constructor
A new instance of Relationship.
- #resource ⇒ Object
- #resource_class ⇒ Object
Methods included from JSONAPIonify::Autoload
autoload_all, eager_load!, unloaded
Methods included from Blocks
append_class, extended, prepend_class
Methods included from Documentation
#documentation_object, #options_json
Constructor Details
#initialize(owner, name, resource: nil, hidden: :list, resolve: proc { |n, o| o.send(n) }, &block) ⇒ Relationship
Returns a new instance of Relationship.
68 69 70 71 72 73 74 75 |
# File 'lib/jsonapionify/api/relationship.rb', line 68 def initialize(owner, name, resource: nil, hidden: :list, resolve: proc { |n, o| o.send(n) }, &block) @class_proc = block || proc {} @owner = owner @name = name @resource = resource || name @resolve = resolve @hidden = !!hidden && (hidden == true || Array.wrap(hidden)) end |
Instance Attribute Details
#class_proc ⇒ Object (readonly)
Returns the value of attribute class_proc.
66 67 68 |
# File 'lib/jsonapionify/api/relationship.rb', line 66 def class_proc @class_proc end |
#hidden ⇒ Object (readonly)
Returns the value of attribute hidden.
66 67 68 |
# File 'lib/jsonapionify/api/relationship.rb', line 66 def hidden @hidden end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
66 67 68 |
# File 'lib/jsonapionify/api/relationship.rb', line 66 def name @name end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
66 67 68 |
# File 'lib/jsonapionify/api/relationship.rb', line 66 def owner @owner end |
#resolve ⇒ Object (readonly)
Returns the value of attribute resolve.
66 67 68 |
# File 'lib/jsonapionify/api/relationship.rb', line 66 def resolve @resolve end |
Instance Method Details
#hidden_for_action?(action_name) ⇒ Boolean
77 78 79 80 |
# File 'lib/jsonapionify/api/relationship.rb', line 77 def hidden_for_action?(action_name) return false if hidden == false Array.wrap(hidden).any? { |h| h == true || h.to_s == action_name.to_s } end |
#resource ⇒ Object
97 98 99 |
# File 'lib/jsonapionify/api/relationship.rb', line 97 def resource owner.api.resource(@resource) end |
#resource_class ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/jsonapionify/api/relationship.rb', line 82 def resource_class @resource_class ||= begin rel = self Class.new(resource) do define_singleton_method(:rel) do rel end rel.class_prepends.each { |prepend| class_eval(&prepend) } class_eval(&rel.class_proc) rel.class_appends.each { |append| class_eval(&append) } end end end |