Class: Blueprint::StructureDesignContext

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

Overview

Design context for a structure (a group of nodes and links)

Instance Method Summary collapse

Methods inherited from DesignContext

#send

Constructor Details

#initialize(api_key, structure_id) ⇒ StructureDesignContext

Returns a new instance of StructureDesignContext.



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/blueprint/api/rails.rb', line 69

def initialize(api_key, structure_id)
  @api_key = api_key
  @structure_id = structure_id
  @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

#begin(name) ⇒ Object



98
99
100
# File 'lib/blueprint/api/rails.rb', line 98

def begin(name)
  ActivityDesignContext.new(@api_key, @structure_id, name)
end

#classifier(from, conditions, to) ⇒ Object

creates a new message classifier



88
89
90
91
92
93
94
95
96
# File 'lib/blueprint/api/rails.rb', line 88

def classifier(from, conditions, to)
  self.send CLASSIFIER_NEW,
            {
                :from => from,
                :conditions => conditions,
                :to => to
            }
  nil
end

creates a design context between source and target



83
84
85
# File 'lib/blueprint/api/rails.rb', line 83

def link(source, target)
  LinkDesignContext.new(@api_key, @structure_id, source, target)
end

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

logs a message between two nodes in the structure



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/blueprint/api/rails.rb', line 103

def log(message = { }, extras = { }, type = nil, source = nil, target = nil)
  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

  # send the message
  self.send MESSAGE, properties, payload

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