Sha256: 772638c4a433990280e3b79fa21dc34841bb307904ee79a1008d7f21d8c27ed2

Contents?: true

Size: 1.88 KB

Versions: 8

Compression:

Stored size: 1.88 KB

Contents

class Revision < Fire::SingleNestedModel

  class Root < Fire::Model
    in_collection 'Revision'
    has_path_keys :branch, :user
    set_id_key(:time)

    require Swat::Engine.root.join 'app/models/concerns/root_revision_ext'
    include RootRevisionExt

    def initialize(args)
      super(extend_path_data(args))
    end

    def threads_count
      nested_main.threads_count.to_i
    end

  end

  nested_in Revision::Root, folder: 'main', parent_values: true

  class Thread < Fire::NestedModel
    nested_in Revision::Root, folder: 'threads'
    set_id_key :thread_id
    attr_accessor :tests
  end

  class Status < Fire::SingleNestedModel
    nested_in Revision::Root, folder: 'status'
  end

  def collect_started_thread(rspec_notification, data)
    object = data.merge( total_examples: rspec_notification.count )
    add_to_threads(object)
  end

  def add_to_threads(data)
    root.add_to_threads(data)
  end

  def threads
    load_root.nested_threads || []
  end

  def collect_ended_thread(rspec_notification, data)
    fails = rspec_notification.failure_notifications.map{|fn|fn.example.metadata[:execution_result].exception}
    total_time = rspec_notification.examples.map{|ex| ex.metadata[:execution_result].run_time }.inject(:+)
    rspec_data = {
        total_examples: rspec_notification.examples.count,
        failed_examples: rspec_notification.failed_examples.count,
        pending_examples: rspec_notification.pending_examples.count,
        failure_notifications: fails,
        total_runtime: total_time,
    }
    object = rspec_data.merge(data)
    add_to_threads(object)
  end

  class << self

    def add(params)
      create(params)
    end

  end

  private

  def root
    @root || Root.new(data)
  end

  def load_root
    @root = Root.take(data)
    return root unless @root
    Root.all_path_keys.each do |k|
      @root.send("#{k}=", self.send(k))
    end
    @root
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sw2at-ui-0.0.16 app/models/revision.rb
sw2at-ui-0.0.15 app/models/revision.rb
sw2at-ui-0.0.14 app/models/revision.rb
sw2at-ui-0.0.13 app/models/revision.rb
sw2at-ui-0.0.12 app/models/revision.rb
sw2at-ui-0.0.11 app/models/revision.rb
sw2at-ui-0.0.10 app/models/revision.rb
sw2at-ui-0.0.9 app/models/revision.rb