Class: PortalModule::Rake::DtsTasks

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/portal_module/rake/dts_tasks.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task_name = 'dts_task', desc = "Modify a DTS configuration") {|_self| ... } ⇒ DtsTasks

Returns a new instance of DtsTasks.

Yields:

  • (_self)

Yield Parameters:



25
26
27
28
29
30
31
32
33
34
# File 'lib/portal_module/rake/dts_tasks.rb', line 25

def initialize(task_name = 'dts_task', desc = "Modify a DTS configuration")
  @valid_actions = ['upload', 'download']
  @task_name, @desc = task_name, desc

  @stop_on_exception = true

  yield self if block_given?

  define_task
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



21
22
23
# File 'lib/portal_module/rake/dts_tasks.rb', line 21

def action
  @action
end

#envObject

Returns the value of attribute env.



18
19
20
# File 'lib/portal_module/rake/dts_tasks.rb', line 18

def env
  @env
end

#orgObject

Returns the value of attribute org.



19
20
21
# File 'lib/portal_module/rake/dts_tasks.rb', line 19

def org
  @org
end

#pathObject

Returns the value of attribute path.



20
21
22
# File 'lib/portal_module/rake/dts_tasks.rb', line 20

def path
  @path
end

#stop_on_exceptionObject

Returns the value of attribute stop_on_exception.



23
24
25
# File 'lib/portal_module/rake/dts_tasks.rb', line 23

def stop_on_exception
  @stop_on_exception
end

#valid_actionsObject (readonly)

Returns the value of attribute valid_actions.



22
23
24
# File 'lib/portal_module/rake/dts_tasks.rb', line 22

def valid_actions
  @valid_actions
end

Class Method Details

.installObject



147
148
149
# File 'lib/portal_module/rake/dts_tasks.rb', line 147

def install
  new.install
end

Instance Method Details

#assert_env_is_configured(arg) ⇒ Object



111
112
113
114
115
116
117
# File 'lib/portal_module/rake/dts_tasks.rb', line 111

def assert_env_is_configured arg
  unless PortalModule.configuration.credentials.key? arg
    init_msg = "Have you initialized your config file?\n Try: portal_module config init <filedir>"
    env_msg = "Have you configured your environments?\n Try: portal_module config add env <envname> <url>"
    raise "Unknown environment: #{arg}\n#{init_msg}\n\n#{env_msg}"
  end
end

#assert_org_is_configured(arg) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/portal_module/rake/dts_tasks.rb', line 119

def assert_org_is_configured arg
  unless PortalModule.configuration.orgs.key? arg
    init_msg = "Have you initialized your config file?\n Try: portal_module config init <filedir>"
    env_msg = "Have you configured your orgs?\n Try: portal_module config add org <orgname> <orgid>"
    raise "Unknown org: #{arg}\n#{init_msg}\n\n#{env_msg}"
  end
end

#assert_provided(value, msg) ⇒ Object



105
106
107
108
109
# File 'lib/portal_module/rake/dts_tasks.rb', line 105

def assert_provided value, msg
  if value.nil? || value.empty?
    raise msg
  end
end

#commitObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/portal_module/rake/dts_tasks.rb', line 62

def commit
  validate_params

  client = PortalModule::Client.new
  client.env = env

  if self.respond_to? action
    self.send(action, client)
    return
  else
    raise "Unknown action - #{action}"
  end

rescue Exception => e
  raise e if stop_on_exception == true
ensure
  client.quit unless client.nil?
end

#default_paramsObject



89
90
# File 'lib/portal_module/rake/dts_tasks.rb', line 89

def default_params
end

#define_taskObject

:nodoc:



36
37
38
39
40
41
42
# File 'lib/portal_module/rake/dts_tasks.rb', line 36

def define_task #:nodoc:
  desc @desc
  task(@task_name, required_args_for_action) do |t,args|
    set_vars args
    commit  # Call method to perform when invoked.
  end
end

#download(client) ⇒ Object



85
86
87
# File 'lib/portal_module/rake/dts_tasks.rb', line 85

def download client
  client.dts.download org, path
end

#installObject



152
153
154
155
156
157
158
159
160
161
# File 'lib/portal_module/rake/dts_tasks.rb', line 152

def install
  PortalModule.configuration.credentials.keys.each do |e|
    valid_actions.each do |action|
      PortalModule::Rake::DtsTasks.new("pm:#{e}:dts:#{action}", "#{action} a #{e} DTS configuration") do |t|
        t.env = e
        t.action = action
      end
    end
  end
end

#required_args_for_actionObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/portal_module/rake/dts_tasks.rb', line 127

def required_args_for_action
  args = []

  case action
  when 'upload'
    args << :org
    args << :path

  when 'download'
    args << :org
    args << :path

  else
    # Noop
  end

  args
end

#set_vars(args) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/portal_module/rake/dts_tasks.rb', line 44

def set_vars args
  args.each do |arg,val|
    instance_variable_set "@#{arg}", val
  end

  args
end

#upload(client) ⇒ Object



81
82
83
# File 'lib/portal_module/rake/dts_tasks.rb', line 81

def upload client
  client.dts.upload org, path
end

#validate_paramsObject



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/portal_module/rake/dts_tasks.rb', line 92

def validate_params
  assert_provided env, 'Missing "env"'
  assert_provided action, 'Missing "action"'

  default_params

  assert_provided path, 'Missing "path"'
  assert_provided org, 'Missing "org"'

  assert_env_is_configured env
  assert_org_is_configured org
end