Class: CrossOrigen::DesignSync

Inherits:
Object
  • Object
show all
Defined in:
lib/cross_origen/design_sync.rb

Overview

Driver for talking to DesignSync

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner) ⇒ DesignSync

Returns a new instance of DesignSync.



9
10
11
# File 'lib/cross_origen/design_sync.rb', line 9

def initialize(owner)
  @owner = owner
end

Instance Attribute Details

#ownerObject (readonly)

Returns the object that included the CrossOrigen module



7
8
9
# File 'lib/cross_origen/design_sync.rb', line 7

def owner
  @owner
end

Instance Method Details

#driverObject



13
14
15
# File 'lib/cross_origen/design_sync.rb', line 13

def driver
  @driver ||= Origen::Utility::DesignSync.new
end

#fetch(options = {}) ⇒ Object

This will be called if the user has supplied a :vault in the rs_import options. The corresponding version of the file will be returned from the cache if it already exists locally, otherwise it will be imported.

This method returns a full path to the local cache copy of the file.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cross_origen/design_sync.rb', line 30

def fetch(options = {})
  unless options[:version]
    puts 'You must supply a :version number (or tag) when importing data from Design Sync'
    exit 1
  end
  v = options[:vault]
  f = v.split('/').last
  vault = v.sub(/\/#{f}$/, '')
  # Consider that similarly named files could exist in different vaults, so attach
  # a representation of the vault to the filename
  vault_hash = Digest::SHA1.hexdigest(vault)
  dir = "#{import_dir}/#{vault_hash}-#{f}"
  file = "#{dir}/#{options[:version]}"
  if f =~ /.*\.(.*)/
    file += ".#{Regexp.last_match[1]}"
  end
  if !File.exist?(file) || options[:force]
    FileUtils.mkdir_p(dir) unless File.exist?(dir)
    driver.import(f, vault, options[:version], dir)
    FileUtils.mv("#{dir}/#{f}", file)
  end
  file
end

#import_dirObject

Returns a full path to the Design Sync import (cache) directory



18
19
20
21
22
23
# File 'lib/cross_origen/design_sync.rb', line 18

def import_dir
  return @import_dir if @import_dir
  @import_dir = "#{Origen.app.workspace_manager.imports_directory}/design_sync"
  FileUtils.mkdir_p(@import_dir) unless File.exist?(@import_dir)
  @import_dir
end