Skip to content

Commit

Permalink
ProcessDefinition can merge partial files for shared data
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Tilley committed Jan 7, 2011
1 parent 0bfc75b commit aa04dc1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
9 changes: 7 additions & 2 deletions lib/dataloaderb/conf_creator.rb
Expand Up @@ -10,14 +10,19 @@ class ConfCreator
attr_reader :processes

# Create a new instance of a ConfCreator
def initialize(yamls)
def initialize(yamls, opts = {})
@processes = []
@opts = opts
build_process_definitions(yamls)
end

def build_process_definitions(yamls)
yamls.each do |yaml|
proc_def = Dataloaderb::ProcessDefinition.new(yaml)
if @opts[:marge].nil? || @opts[:marge].empty?
proc_def = Dataloaderb::ProcessDefinition.new(yaml)
else
proc_def = Dataloaderb::ProcessDefinition.new(yaml, @opts[:merge])
end
@processes << proc_def
end
end
Expand Down
13 changes: 10 additions & 3 deletions lib/dataloaderb/process_definition.rb
Expand Up @@ -6,11 +6,11 @@ class ProcessDefinition
attr_reader :entries

# Create a new instance of a ConfCreator
def initialize(yaml)
def initialize(yaml, merge = nil)
@id = ''
@description = ''
@entries = {}
load_yaml(yaml)
load_yaml(yaml, merge)
end

def set(key, value)
Expand All @@ -22,8 +22,15 @@ def get(key)
end

# Load a process definition from a Yaml file
def load_yaml(yaml_file)
def load_yaml(yaml_file, merge = nil)
raise ArgumentError, "Cannot find file #{yaml_file}" unless File.exist?(yaml_file)
raise ArgumentError, "Cannot find file #{merge}" unless merge.nil? || File.exist?(merge)
unless merge.nil?
merge_data = YAML.load_file(merge)
merge_data.each do |key, value|
self.set(key, value)
end
end
proc = YAML.load_file(yaml_file)
@id = proc['id']
@description = proc['description']
Expand Down
5 changes: 3 additions & 2 deletions lib/dataloaderb/process_runner.rb
Expand Up @@ -4,8 +4,9 @@ module Dataloaderb
class ProcessRunner
# Create the process runner and specify the path to
# the Apex Data Loader executable (batch) files.
def initialize(bin_path)
def initialize(bin_path, opts = {})
@bin_path = bin_path
@opts = opts
end

# Run one or more processes. Specify the processes to run by passing
Expand All @@ -15,7 +16,7 @@ def run(*yamls)
raise ArgumentError, "You must pass at least one argument to Dataloaderb::ProcessRunner#run"
end

creator = Dataloaderb::ConfCreator.new(yamls)
creator = Dataloaderb::ConfCreator.new(yamls, opts)
end

def execute_process(process_name)
Expand Down
14 changes: 14 additions & 0 deletions spec/dataloaderb/process_definition_spec.rb
Expand Up @@ -26,10 +26,24 @@
}.should raise_error ArgumentError
end

it "should raise an ArgumentError if the merge file doesn't exist" do
lambda {
@conf.load_yaml(FIXTURE_PROCESSES[:full_process_one], "fake_merge.yml")
}.should raise_error ArgumentError
end

it "should set the appropriate values via set()" do
@conf.get('sfdc.timeoutSecs').should == '600'
@conf.get('sfdc.debugMessages').should == 'true'
@conf.get('process.initialLastRunDate').should == '2010-01-01T00:00:00.000-0800'
end
end

it "should correctly merge any partial files" do
@conf = Dataloaderb::ProcessDefinition.new(FIXTURE_PROCESSES[:partial_process_one], FIXTURE_PROCESSES[:partial_shared])
@conf.get('sfdc.timeoutSecs').should == '600'
@conf.get('sfdc.debugMessages').should == 'true'
@conf.get('process.initialLastRunDate').should == '2010-01-01T00:00:00.000-0800'
@conf.get('process.encryptionKeyFile').should == 'C:/salesforce/dataloader/enc_pass.key'
end
end

0 comments on commit aa04dc1

Please sign in to comment.