Class: Entitize::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/entitize/repo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Repo

Returns a new instance of Repo.



6
7
8
# File 'lib/entitize/repo.rb', line 6

def initialize(settings = {})
  @token = settings[:token]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/entitize/repo.rb', line 10

def method_missing(query, *args, &block)
  data_source_class = args[0]
  options           = args[1] || {}
  arguments         = options[:args] || []
  class_name_to_use = options[:entity] || data_source_class.to_s

  # TODO: add in all settings as first args -> e.g. pub_key, secret_key
  arguments.unshift(token) unless token.nil?
  data = data_source_class.send(query, *arguments)

  Entitize::Entity.generate(data, class_name_to_use)
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



4
5
6
# File 'lib/entitize/repo.rb', line 4

def token
  @token
end