Class: Onsi::Includes

Inherits:
Object
  • Object
show all
Defined in:
lib/onsi/includes.rb

Overview

Used to include other objects in a root Resource objects.

Examples:

def index
  @person = Person.find(params[:person_id])
  @email = @person.emails.find(params[:id])
  @includes = Onsi::Includes.new(params[:include])
  @includes.fetch_person { @person }
  @includes.fetch_messages { @email.messages }
  render_resource(Onsi::Resource.new(@email, params[:version].to_sym, includes: @includes))
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(included) ⇒ Onsi::Includes

Create a new Includes object.

Parameters:

  • included (String, Enumerable<String, Symbol>, nil)

    The keys to be included.



34
35
36
# File 'lib/onsi/includes.rb', line 34

def initialize(included)
  @included = parse_included(included)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/onsi/includes.rb', line 40

def method_missing(name, *args, &block)
  if name =~ FETCH_METHOD_REGEXP
    add_fetch_method(name.to_s.gsub(/\Afetch_/, ''), *args, &block)
  else
    super
  end
end

Instance Attribute Details

#includedArray<Symbol> (readonly)

The includes

Returns:

  • (Array<Symbol>)


25
26
27
# File 'lib/onsi/includes.rb', line 25

def included
  @included
end