blueprint-api-rails 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/blueprint/api/rails.rb +84 -29
 - data/lib/blueprint/api/rails/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 8a9fe12b5d07a6b092fd9ac10f9556116e51fa27
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8d2d6f67c7b40f676cc344427a14f588db42ecdd
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 76515fe219c732211854347e732d3dd5bd96b59dfd4527f894b0e218c560953f218d32d439cde34150aae35c1d92c129d57211c60252154743c9bc4f68752342
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: da3b116b3d680f9538e794d2531d1ddccc19b9457d2615183c0b314e1d363251b4b0e73d8dbd3d381940c079a8e42655fbc4cf9b862d0476691276be07c6b99b
         
     | 
    
        data/lib/blueprint/api/rails.rb
    CHANGED
    
    | 
         @@ -9,7 +9,6 @@ module Blueprint 
     | 
|
| 
       9 
9 
     | 
    
         
             
              # TODO deprecate all of the branch stuff
         
     | 
| 
       10 
10 
     | 
    
         
             
              # TODO limit messages that are lists to a maximum of 10 elements
         
     | 
| 
       11 
11 
     | 
    
         
             
              # TODO add support for getting the current user (so we can analysis log messages per user)
         
     | 
| 
       12 
     | 
    
         
            -
              # TODO only log messages to the Blueprint server if there is an API key (if there isn't we can still check rules locally)
         
     | 
| 
       13 
12 
     | 
    
         | 
| 
       14 
13 
     | 
    
         
             
              STRUCTURE_NEW = 'start'
         
     | 
| 
       15 
14 
     | 
    
         | 
| 
         @@ -48,26 +47,30 @@ module Blueprint 
     | 
|
| 
       48 
47 
     | 
    
         
             
                # utility method for sending JSON payloads to the Anaxim servers - should never be called directly
         
     | 
| 
       49 
48 
     | 
    
         
             
                def send(event_type, properties = { }, message = { })
         
     | 
| 
       50 
49 
     | 
    
         | 
| 
       51 
     | 
    
         
            -
                  #  
     | 
| 
       52 
     | 
    
         
            -
                   
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
      
 50 
     | 
    
         
            +
                  # only send messages if we have an API key (even without one this gem can apply architectural verification rules)
         
     | 
| 
      
 51 
     | 
    
         
            +
                  unless @api_key.nil?
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                    # construct the base payload
         
     | 
| 
      
 54 
     | 
    
         
            +
                    payload = {
         
     | 
| 
      
 55 
     | 
    
         
            +
                        :header => {
         
     | 
| 
      
 56 
     | 
    
         
            +
                            :structure_id => @structure_id,
         
     | 
| 
      
 57 
     | 
    
         
            +
                            :properties => properties,
         
     | 
| 
      
 58 
     | 
    
         
            +
                            :branch => {
         
     | 
| 
      
 59 
     | 
    
         
            +
                                :name => @branch || 'master'
         
     | 
| 
      
 60 
     | 
    
         
            +
                            },
         
     | 
| 
      
 61 
     | 
    
         
            +
                            :eventType => event_type
         
     | 
| 
      
 62 
     | 
    
         
            +
                        }
         
     | 
| 
      
 63 
     | 
    
         
            +
                    }
         
     | 
| 
       62 
64 
     | 
    
         | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
      
 65 
     | 
    
         
            +
                    # merge (append) the properties hash onto the payload (properties vary per event type)
         
     | 
| 
      
 66 
     | 
    
         
            +
                    payload.merge! message
         
     | 
| 
       65 
67 
     | 
    
         | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
      
 68 
     | 
    
         
            +
                    @conn.post do |req|
         
     | 
| 
      
 69 
     | 
    
         
            +
                      req.url BLUEPRINT_URL_CONTEXT
         
     | 
| 
      
 70 
     | 
    
         
            +
                      req.headers['Content-Type'] = 'application/json'
         
     | 
| 
      
 71 
     | 
    
         
            +
                      req.headers['X-Api-Key'] = @api_key
         
     | 
| 
      
 72 
     | 
    
         
            +
                      req.body = payload.to_json
         
     | 
| 
      
 73 
     | 
    
         
            +
                    end
         
     | 
| 
       71 
74 
     | 
    
         
             
                  end
         
     | 
| 
       72 
75 
     | 
    
         | 
| 
       73 
76 
     | 
    
         
             
                  self
         
     | 
| 
         @@ -93,23 +96,43 @@ module Blueprint 
     | 
|
| 
       93 
96 
     | 
    
         
             
                  # the list of violations for this action
         
     | 
| 
       94 
97 
     | 
    
         
             
                  violations = [ ]
         
     | 
| 
       95 
98 
     | 
    
         | 
| 
      
 99 
     | 
    
         
            +
                  # if all parameters are present then we can check for link rules
         
     | 
| 
      
 100 
     | 
    
         
            +
                  if source.present? && target.present? && type.present?
         
     | 
| 
      
 101 
     | 
    
         
            +
                    # check to see if there is a link rule for this source / target pair
         
     | 
| 
      
 102 
     | 
    
         
            +
                    if RULES.has_key?(:links)
         
     | 
| 
      
 103 
     | 
    
         
            +
                      link_rule = RULES[:links].find { |l| l[:source] == source && l[:target] == target }
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
                      unless link_rule.nil?
         
     | 
| 
      
 106 
     | 
    
         
            +
                        # there is a link rule - check that the type is allowed over the link
         
     | 
| 
      
 107 
     | 
    
         
            +
                        unless link_rule[:allowed] == type
         
     | 
| 
      
 108 
     | 
    
         
            +
                          violations << "The type #{type} is not allowed over the link #{source} -> #{target}."
         
     | 
| 
      
 109 
     | 
    
         
            +
                        end
         
     | 
| 
      
 110 
     | 
    
         
            +
                      end
         
     | 
| 
      
 111 
     | 
    
         
            +
                    end
         
     | 
| 
      
 112 
     | 
    
         
            +
                  end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
       96 
114 
     | 
    
         
             
                  unless type.nil?
         
     | 
| 
       97 
     | 
    
         
            -
                    # is the type  
     | 
| 
      
 115 
     | 
    
         
            +
                    # is the type allowed?
         
     | 
| 
      
 116 
     | 
    
         
            +
                    if RULES.has_key?(:allowed)
         
     | 
| 
      
 117 
     | 
    
         
            +
                      unless RULES[:allowed].map { |t| t[:name] }.include?(type)
         
     | 
| 
      
 118 
     | 
    
         
            +
                        violations << "The type #{type} is not registered as being allowed."
         
     | 
| 
      
 119 
     | 
    
         
            +
                      end
         
     | 
| 
      
 120 
     | 
    
         
            +
                    end
         
     | 
| 
       98 
121 
     | 
    
         | 
| 
      
 122 
     | 
    
         
            +
                    # is the type restricted to a certain structural element?
         
     | 
| 
       99 
123 
     | 
    
         
             
                    unless RULES[type].nil?   # are there any rules for this type?
         
     | 
| 
       100 
124 
     | 
    
         | 
| 
       101 
125 
     | 
    
         
             
                      if RULES[type].has_key?(:only)    # do the rules for this type include an 'only' restriction?
         
     | 
| 
       102 
126 
     | 
    
         
             
                        allowed_element = RULES[type][:only]
         
     | 
| 
       103 
127 
     | 
    
         | 
| 
       104 
128 
     | 
    
         
             
                        unless allowed_element.eql?(source)
         
     | 
| 
       105 
     | 
    
         
            -
                          violations << "The type #{type} is allowed only within #{allowed_element} and it was used  
     | 
| 
      
 129 
     | 
    
         
            +
                          violations << "The type #{type} is allowed only within #{allowed_element} and it was used within #{source}."
         
     | 
| 
       106 
130 
     | 
    
         
             
                        end
         
     | 
| 
       107 
131 
     | 
    
         
             
                      end
         
     | 
| 
       108 
132 
     | 
    
         
             
                    end
         
     | 
| 
       109 
133 
     | 
    
         
             
                  end
         
     | 
| 
       110 
134 
     | 
    
         | 
| 
       111 
135 
     | 
    
         
             
                  # output architectural violations
         
     | 
| 
       112 
     | 
    
         
            -
                  # TODO make this output more obvious (and configurable?)
         
     | 
| 
       113 
136 
     | 
    
         
             
                  unless violations.empty?
         
     | 
| 
       114 
137 
     | 
    
         
             
                    p '### Architectural violations found ###'
         
     | 
| 
       115 
138 
     | 
    
         
             
                    violations.each { |v|
         
     | 
| 
         @@ -139,8 +162,6 @@ module Blueprint 
     | 
|
| 
       139 
162 
     | 
    
         
             
                end
         
     | 
| 
       140 
163 
     | 
    
         | 
| 
       141 
164 
     | 
    
         
             
                # performs an extract (that is, scans the code base for architectural elements)
         
     | 
| 
       142 
     | 
    
         
            -
                # TODO this scan can be arbitrarily complex - we could scan for anything
         
     | 
| 
       143 
     | 
    
         
            -
                # TODO add support of passing in custom scanners
         
     | 
| 
       144 
165 
     | 
    
         
             
                def scan(repository_type)
         
     | 
| 
       145 
166 
     | 
    
         
             
                  repo_url = nil
         
     | 
| 
       146 
167 
     | 
    
         | 
| 
         @@ -175,7 +196,6 @@ module Blueprint 
     | 
|
| 
       175 
196 
     | 
    
         
             
                  end
         
     | 
| 
       176 
197 
     | 
    
         | 
| 
       177 
198 
     | 
    
         
             
                  # now scan for models
         
     | 
| 
       178 
     | 
    
         
            -
                  # TODO support code URLs for models too
         
     | 
| 
       179 
199 
     | 
    
         
             
                  models = Dir[Rails.root.join('app/models/*.rb')].map { |path|
         
     | 
| 
       180 
200 
     | 
    
         
             
                    path.match(/(\w+).rb/); $1.titleize
         
     | 
| 
       181 
201 
     | 
    
         
             
                  }.compact
         
     | 
| 
         @@ -189,10 +209,12 @@ module Blueprint 
     | 
|
| 
       189 
209 
     | 
    
         
             
                  p 'Scan complete'
         
     | 
| 
       190 
210 
     | 
    
         
             
                end
         
     | 
| 
       191 
211 
     | 
    
         | 
| 
      
 212 
     | 
    
         
            +
                # creates a design context for a structural element
         
     | 
| 
       192 
213 
     | 
    
         
             
                def element(name, code_url = nil)
         
     | 
| 
       193 
214 
     | 
    
         
             
                  StructuralElementDesignContext.new(@api_key, @structure_id, name, code_url)
         
     | 
| 
       194 
215 
     | 
    
         
             
                end
         
     | 
| 
       195 
216 
     | 
    
         | 
| 
      
 217 
     | 
    
         
            +
                # creates a design context for a concept
         
     | 
| 
       196 
218 
     | 
    
         
             
                def concept(name)
         
     | 
| 
       197 
219 
     | 
    
         
             
                  ConceptDesignContext.new(@api_key, @structure_id, name)
         
     | 
| 
       198 
220 
     | 
    
         
             
                end
         
     | 
| 
         @@ -218,7 +240,7 @@ module Blueprint 
     | 
|
| 
       218 
240 
     | 
    
         
             
                end
         
     | 
| 
       219 
241 
     | 
    
         | 
| 
       220 
242 
     | 
    
         
             
                # logs a message between two nodes in the structure
         
     | 
| 
       221 
     | 
    
         
            -
                def log( 
     | 
| 
      
 243 
     | 
    
         
            +
                def log(source = nil, target = nil, type = nil, message = { }, extras = { })
         
     | 
| 
       222 
244 
     | 
    
         
             
                  # always check the logged message for architectural rules violations
         
     | 
| 
       223 
245 
     | 
    
         
             
                  check_rules(source, target, type)
         
     | 
| 
       224 
246 
     | 
    
         | 
| 
         @@ -373,7 +395,19 @@ module Blueprint 
     | 
|
| 
       373 
395 
     | 
    
         
             
                  self
         
     | 
| 
       374 
396 
     | 
    
         
             
                end
         
     | 
| 
       375 
397 
     | 
    
         | 
| 
       376 
     | 
    
         
            -
                # verification 
     | 
| 
      
 398 
     | 
    
         
            +
                # methods to support AVL (architectural verification)
         
     | 
| 
      
 399 
     | 
    
         
            +
             
     | 
| 
      
 400 
     | 
    
         
            +
                # marks a conceptual type as allowed within the archiecture
         
     | 
| 
      
 401 
     | 
    
         
            +
                def allow
         
     | 
| 
      
 402 
     | 
    
         
            +
                  unless RULES.has_key?(:allowed)
         
     | 
| 
      
 403 
     | 
    
         
            +
                    RULES[:allowed] = [ ]
         
     | 
| 
      
 404 
     | 
    
         
            +
                  end
         
     | 
| 
      
 405 
     | 
    
         
            +
             
     | 
| 
      
 406 
     | 
    
         
            +
                  # add the type to the allowed list
         
     | 
| 
      
 407 
     | 
    
         
            +
                  RULES[:allowed] << { :name => @name }
         
     | 
| 
      
 408 
     | 
    
         
            +
                end
         
     | 
| 
      
 409 
     | 
    
         
            +
             
     | 
| 
      
 410 
     | 
    
         
            +
                # marks a conceptual type as allowed within (and only within) a structural elements
         
     | 
| 
       377 
411 
     | 
    
         
             
                def only(element)
         
     | 
| 
       378 
412 
     | 
    
         
             
                  unless RULES.has_key?(@name)
         
     | 
| 
       379 
413 
     | 
    
         
             
                    RULES[@name] = { }
         
     | 
| 
         @@ -433,7 +467,7 @@ module Blueprint 
     | 
|
| 
       433 
467 
     | 
    
         
             
                  end
         
     | 
| 
       434 
468 
     | 
    
         | 
| 
       435 
469 
     | 
    
         | 
| 
       436 
     | 
    
         
            -
                  def log( 
     | 
| 
      
 470 
     | 
    
         
            +
                  def log(source = nil, target = nil, type = nil, message = { }, extras = { })
         
     | 
| 
       437 
471 
     | 
    
         
             
                    # always check the logged message for architectural rules violations
         
     | 
| 
       438 
472 
     | 
    
         
             
                    check_rules(source, target, type)
         
     | 
| 
       439 
473 
     | 
    
         | 
| 
         @@ -479,8 +513,29 @@ module Blueprint 
     | 
|
| 
       479 
513 
     | 
    
         
             
                  end
         
     | 
| 
       480 
514 
     | 
    
         
             
                end
         
     | 
| 
       481 
515 
     | 
    
         | 
| 
      
 516 
     | 
    
         
            +
                def allow(concept)
         
     | 
| 
      
 517 
     | 
    
         
            +
                  unless RULES.has_key?(:links)
         
     | 
| 
      
 518 
     | 
    
         
            +
                    RULES[:links] = [ ]
         
     | 
| 
      
 519 
     | 
    
         
            +
                  end
         
     | 
| 
      
 520 
     | 
    
         
            +
             
     | 
| 
      
 521 
     | 
    
         
            +
                  # look for an existing rule
         
     | 
| 
      
 522 
     | 
    
         
            +
                  existing_rule = RULES[:links].find { |l| l[:source] == @source && l[:target] == @target }
         
     | 
| 
      
 523 
     | 
    
         
            +
             
     | 
| 
      
 524 
     | 
    
         
            +
                  if existing_rule.nil?
         
     | 
| 
      
 525 
     | 
    
         
            +
                    existing_rule = {
         
     | 
| 
      
 526 
     | 
    
         
            +
                        :source => @source,
         
     | 
| 
      
 527 
     | 
    
         
            +
                        :target => @target,
         
     | 
| 
      
 528 
     | 
    
         
            +
                        :allowed => concept,
         
     | 
| 
      
 529 
     | 
    
         
            +
                    }
         
     | 
| 
      
 530 
     | 
    
         
            +
             
     | 
| 
      
 531 
     | 
    
         
            +
                    RULES[:links] << existing_rule
         
     | 
| 
      
 532 
     | 
    
         
            +
                  else
         
     | 
| 
      
 533 
     | 
    
         
            +
                    existing_rule[:allowed] = concept
         
     | 
| 
      
 534 
     | 
    
         
            +
                  end
         
     | 
| 
      
 535 
     | 
    
         
            +
                end
         
     | 
| 
      
 536 
     | 
    
         
            +
             
     | 
| 
       482 
537 
     | 
    
         
             
                # logs a message between two nodes in the structure
         
     | 
| 
       483 
     | 
    
         
            -
                def log(message = { }, extras = { } 
     | 
| 
      
 538 
     | 
    
         
            +
                def log(type = nil, message = { }, extras = { })
         
     | 
| 
       484 
539 
     | 
    
         
             
                  # always check the logged message for architectural rules violations
         
     | 
| 
       485 
540 
     | 
    
         
             
                  check_rules(@source, @target, type)
         
     | 
| 
       486 
541 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: blueprint-api-rails
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.7
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - benjii
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2016-07- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2016-07-24 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     |