Module: Fabricas
- Defined in:
- lib/fabricas.rb
Overview
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Defined Under Namespace
Classes: CleanRoom
Constant Summary collapse
- VERSION =
"1.1.3"
Class Method Summary collapse
- .build(klass, values = {}) ⇒ Object
- .define(&block) ⇒ Object
- .factory(klass, args = {}, &block) ⇒ Object
Class Method Details
.build(klass, values = {}) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/fabricas.rb', line 37 def self.build(klass, values = {}) _i = const_get(@factories[klass].class_name.capitalize).new attributes = @factories[klass].attributes.merge(values) attributes.each do |name, value| _i.send("#{name}=", value.is_a?(Proc) ? _i.instance_eval(&value) : value) end _i end |
.define(&block) ⇒ Object
24 25 26 |
# File 'lib/fabricas.rb', line 24 def self.define(&block) module_eval(&block) end |
.factory(klass, args = {}, &block) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/fabricas.rb', line 28 def self.factory(klass, args = {}, &block) _p = args.fetch(:parent, nil) if block_given? _f = @factories[klass] = CleanRoom.new(args.fetch(:class_name, nil) || (_p.class_name if _p) || klass) _f.attributes = _p.attributes.clone if _p _f.instance_eval(&block) end end |