Class: Veneer::Base::ClassWrapper

Inherits:
BasicObject
Defined in:
lib/veneer/base/class_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, opts) ⇒ ClassWrapper

Returns a new instance of ClassWrapper.



5
6
7
# File 'lib/veneer/base/class_wrapper.rb', line 5

def initialize(klass, opts)
  @klass, @opts = klass, opts
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



4
5
6
# File 'lib/veneer/base/class_wrapper.rb', line 4

def klass
  @klass
end

#optsObject (readonly)

Returns the value of attribute opts.



4
5
6
# File 'lib/veneer/base/class_wrapper.rb', line 4

def opts
  @opts
end

Instance Method Details

#all(opts = {}) ⇒ Object



35
36
37
38
# File 'lib/veneer/base/class_wrapper.rb', line 35

def all(opts={})
  conditional = ::Veneer::Conditional.from_hash(opts)
  find_many(conditional).map{|element| ::Kernel.Veneer(element)}
end

#create(opts = {}) ⇒ Object



17
18
19
20
21
# File 'lib/veneer/base/class_wrapper.rb', line 17

def create(opts = {})
  instance = new(opts)
  instance.save
  instance
end

#create!(opts = {}) ⇒ Object



10
11
12
13
14
# File 'lib/veneer/base/class_wrapper.rb', line 10

def create!(opts = {})
  instance = new(opts)
  instance.save!
  instance
end

#find_first(conditional) ⇒ Object

A single object matching the conditional



48
49
50
# File 'lib/veneer/base/class_wrapper.rb', line 48

def find_first(conditional)
  ::Kernel.raise Errors::NotImplemented
end

#find_many(conditional) ⇒ Object

Should return an array or array like structure with elements matching the provided conditional



42
43
44
# File 'lib/veneer/base/class_wrapper.rb', line 42

def find_many(conditional)
  ::Kernel.raise Errors::NotImplemented
end

#first(opts = {}) ⇒ Object



29
30
31
32
# File 'lib/veneer/base/class_wrapper.rb', line 29

def first(opts={})
  conditional = ::Veneer::Conditional.from_hash(opts)
  ::Kernel.Veneer(find_first(conditional))
end

#new(opts = {}) ⇒ Object



24
25
26
# File 'lib/veneer/base/class_wrapper.rb', line 24

def new(opts = {})
  ::Kernel.raise Errors::NotImplemented
end