Sha256: 925b3b45fc091dc77e959949332c09c5dd8643148780133fbcc8008b06b0385a

Contents?: true

Size: 882 Bytes

Versions: 15

Compression:

Stored size: 882 Bytes

Contents

module MockleyCrew
  class Data
    attr_accessor :builders

    def initialize params = []
      raise Errors::InvalidDataError unless params.is_a? Array

      params.each do |p|
        raise Errors::InvalidDataError unless p.is_a? Hash
        
        builders.push FactoryBuilder.new(p)
      end
    end

    def builders
      @builders ||= []
    end

    def save
      success = true
      ActiveRecord::Base.transaction do
        @builders.each do |b|
          unless b.save
            success = false
          end
        end
        raise ActiveRecord::Rollback unless success
      end
      return success
    end

    def as_json
      @builders.map do |b|
        h = {
          "factory" => b.factory,
          "options" => b.options
        }
        unless b.errors.blank?
          h["errors"] = b.errors
        end
        h
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
mockley_crew-1.3.9 lib/mockley_crew/data.rb
mockley_crew-1.3.8 lib/mockley_crew/data.rb
mockley_crew-1.3.7 lib/mockley_crew/data.rb
mockley_crew-1.2.2 lib/mockley_crew/data.rb
mockley_crew-1.1.9 lib/mockley_crew/data.rb
mockley_crew-1.1.8 lib/mockley_crew/data.rb
mockley_crew-1.1.7 lib/mockley_crew/data.rb
mockley_crew-1.1.6 lib/mockley_crew/data.rb
mockley_crew-1.1.5 lib/mockley_crew/data.rb
mockley_crew-1.1.4 lib/mockley_crew/data.rb
mockley_crew-1.1.3 lib/mockley_crew/data.rb
mockley_crew-1.1.2 lib/mockley_crew/data.rb
mockley_crew-1.1.1 lib/mockley_crew/data.rb
mockley_crew-1.1.0 lib/mockley_crew/data.rb
mockley_crew-1.0.0 lib/mockley_crew/data.rb