Class: Materialize::Repo

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/materialize/repo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#class_exists?

Constructor Details

#initialize(token = nil) ⇒ Repo

Returns a new instance of Repo.



7
8
9
# File 'lib/materialize/repo.rb', line 7

def initialize(token = nil)
  @token = token
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(query, *args) {|data| ... } ⇒ Object

Yields:

  • (data)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/materialize/repo.rb', line 11

def method_missing(query, *args, &block)
  data_source_class = args[0]
  options           = args[1] || {}
  args_to_pass      = options[:args]

  data, builder_class, entity_class = process(data_source_class, query, args_to_pass)

  yield(data) if block_given?

  options.delete(:args)

  # TODO: add a temporary bypass switch that skips builders
  # TODO: Switch to something like data['m_message'] to avoid collisions

  if options[:skip_builders]
    if data.is_a?(Hash) and !data['message'].nil?
      Response.new data
    elsif data.is_a?(Array)
      entity_class.wrap(data)
    else
      entity_class.new(data)
    end
  else
    if data.is_a?(Hash) and !data['message'].nil?
      Response.new data
    elsif data.is_a?(Array)
      builder_class.build_all(data, self, options)
    else
      builder_class.build(data, self, options)
    end
  end

end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



5
6
7
# File 'lib/materialize/repo.rb', line 5

def token
  @token
end