Module: Cero::Repo::ClassMethods

Defined in:
lib/cero/repo.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



67
68
69
70
71
72
73
74
# File 'lib/cero/repo.rb', line 67

def method_missing(name, *args, &block)
  if target.respond_to?(name)
    args = args.unshift(collection)
    target.__send__(name, *args, &block)
  else
    super(name, *args, &block)
  end
end

Instance Method Details

#adapter(options = {}) ⇒ Object



33
34
35
# File 'lib/cero/repo.rb', line 33

def adapter(options = {})
  @adapter = Adapter.new(options)
end

#collectionObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cero/repo.rb', line 45

def collection
  @collection ||= begin
    klass_name = extract_default_class_name
    collection_name = if klass_name.index('::')
      parts = klass_name.split('::')
      parts.join.underscore.pluralize
    else
      klass_name.downcase.pluralize
    end
  end
end

#collection=(collection_name) ⇒ Object



41
42
43
# File 'lib/cero/repo.rb', line 41

def collection=(collection_name)
  @collection = collection_name.to_s
end

#entity_classObject



61
62
63
64
65
# File 'lib/cero/repo.rb', line 61

def entity_class
  @entity_class ||= begin
    klass_name = extract_default_class_name.constantize
  end
end

#entity_class=(klass_name) ⇒ Object



57
58
59
# File 'lib/cero/repo.rb', line 57

def entity_class=(klass_name)
  @entity_class = klass_name.to_s.classify.constantize
end

#get_adapterObject



37
38
39
# File 'lib/cero/repo.rb', line 37

def get_adapter
  @adapter ||= Repo.adapter
end

#targetObject



76
77
78
79
80
81
# File 'lib/cero/repo.rb', line 76

def target
  @target ||= begin
    t = get_adapter.resolve_for(collection)
    t.proxy
  end
end