Class: Blueprint::LinkDesignContext

Inherits:
DesignContext show all
Defined in:
lib/blueprint/api/rails.rb

Instance Method Summary collapse

Methods inherited from DesignContext

#check_rules, #determine_remote_repository, #send

Constructor Details

#initialize(api_key, structure_id, source, target) ⇒ LinkDesignContext

Returns a new instance of LinkDesignContext.



502
503
504
505
506
507
508
509
510
511
512
513
514
# File 'lib/blueprint/api/rails.rb', line 502

def initialize(api_key, structure_id, source, target)
  @api_key = api_key
  @structure_id = structure_id
  @source = source
  @target = target
  @branch = `git rev-parse --abbrev-ref HEAD 2>&1`.strip! || 'master'

  # initialise faraday
  @conn = Faraday.new(:url => BLUEPRINT_SERVER) do |faraday|
    # faraday.response :logger                  # log requests to STDOUT
    faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
  end
end

Instance Method Details

#allow(concept) ⇒ Object



516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'lib/blueprint/api/rails.rb', line 516

def allow(concept)
  unless RULES.has_key?(:links)
    RULES[:links] = [ ]
  end

  # look for an existing rule
  existing_rule = RULES[:links].find { |l| l[:source] == @source && l[:target] == @target }

  if existing_rule.nil?
    existing_rule = {
        :source => @source,
        :target => @target,
        :allowed => concept,
    }

    RULES[:links] << existing_rule
  else
    existing_rule[:allowed] = concept
  end
end

#log(type = nil, message = { }, extras = { }) ⇒ Object

logs a message between two nodes in the structure



538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
# File 'lib/blueprint/api/rails.rb', line 538

def log(type = nil, message = { }, extras = { })
  # always check the logged message for architectural rules violations
  check_rules(@source, @target, type)

  properties = Hash.new.tap do |h|
    h[:source] = @source unless @source.blank?
    h[:target] = @target unless @target.blank?
  end

  payload = Hash.new.tap do |h|
    h[:type] = type unless type.blank?
    h[:payload] = {
        :message => message,
        :extras => extras
    }
  end

  self.send MESSAGE, properties, payload

  # return nil so that no further calls can be made to the fluent API
  nil
end