module Representable::Expandable
Constants
- VERSION
Public Class Methods
add_expandable(name, options = {})
click to toggle source
# File lib/representable/expandable.rb, line 15 def self.add_expandable(name, options = {}) if options.delete :expandable # if collection already had if, and it with expandable if condition existing_if = options[:if] || ->(_opts) { true } options[:if] = ->(opts) { opts[:expand] && opts[:expand].include?(name.to_s) && existing_if.call(opts) } end end
collection(name, options = {}, &block)
click to toggle source
Calls superclass method
# File lib/representable/expandable.rb, line 5 def self.collection(name, options = {}, &block) add_expandable(name, options) super end
included(base)
click to toggle source
# File lib/representable/expandable.rb, line 3 def self.included(base) base.class_eval do def self.collection(name, options = {}, &block) add_expandable(name, options) super end def self.property(name, options = {}, &block) add_expandable(name, options) super end def self.add_expandable(name, options = {}) if options.delete :expandable # if collection already had if, and it with expandable if condition existing_if = options[:if] || ->(_opts) { true } options[:if] = ->(opts) { opts[:expand] && opts[:expand].include?(name.to_s) && existing_if.call(opts) } end end end end
property(name, options = {}, &block)
click to toggle source
Calls superclass method
# File lib/representable/expandable.rb, line 10 def self.property(name, options = {}, &block) add_expandable(name, options) super end