Class: Veneer::Base::ClassWrapper
- Inherits:
- BasicObject
- Defined in:
- lib/veneer/base/class_wrapper.rb
Direct Known Subclasses
ActiveRecord::Base::VeneerInterface::ClassWrapper, DataMapper::Resource::VeneerInterface::ClassWrapper, MongoMapper::Document::VeneerInterface::ClassWrapper
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #all(opts = {}) ⇒ Object
- #create(opts = {}) ⇒ Object
- #create!(opts = {}) ⇒ Object
-
#find_first(conditional) ⇒ Object
A single object matching the conditional.
-
#find_many(conditional) ⇒ Object
Should return an array or array like structure with elements matching the provided conditional.
- #first(opts = {}) ⇒ Object
-
#initialize(klass, opts) ⇒ ClassWrapper
constructor
A new instance of ClassWrapper.
- #new(opts = {}) ⇒ Object
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
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
4 5 6 |
# File 'lib/veneer/base/class_wrapper.rb', line 4 def klass @klass end |
#opts ⇒ Object (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 |