Class: PortalModule::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



130
131
132
# File 'lib/portal_module.rb', line 130

def initialize
  reset
end

Instance Attribute Details

#base_urlsObject

Returns the value of attribute base_urls.



119
120
121
# File 'lib/portal_module.rb', line 119

def base_urls
  @base_urls
end

#browser_timeoutObject

Browser timeout in seconds. Default: 360 (6 mins).



123
124
125
# File 'lib/portal_module.rb', line 123

def browser_timeout
  @browser_timeout
end

#credentialsObject

Returns the value of attribute credentials.



118
119
120
# File 'lib/portal_module.rb', line 118

def credentials
  @credentials
end

#default_environmentObject

Returns the value of attribute default_environment.



117
118
119
# File 'lib/portal_module.rb', line 117

def default_environment
  @default_environment
end

#download_dirObject

Returns the value of attribute download_dir.



126
127
128
# File 'lib/portal_module.rb', line 126

def download_dir
  @download_dir
end

#download_timeoutObject

Returns the value of attribute download_timeout.



127
128
129
# File 'lib/portal_module.rb', line 127

def download_timeout
  @download_timeout
end

#orgsObject

Returns the value of attribute orgs.



125
126
127
# File 'lib/portal_module.rb', line 125

def orgs
  @orgs
end

#page_urlsObject

Returns the value of attribute page_urls.



120
121
122
# File 'lib/portal_module.rb', line 120

def page_urls
  @page_urls
end

Instance Method Details

#base_urlObject



190
191
192
# File 'lib/portal_module.rb', line 190

def base_url
  @base_urls[current_env]
end

#current_envObject

Return the current environment. Will return the default environment if current environment is not set.



177
178
179
180
# File 'lib/portal_module.rb', line 177

def current_env
  return @default_environment if @current_env.nil?
  @current_env
end

#current_env=(env) ⇒ Object

Set the current environment.



162
163
164
165
166
167
168
169
170
# File 'lib/portal_module.rb', line 162

def current_env=(env)
  env = env.to_sym

  fail "Cannot set current_env to un-configured environment: #{env}" unless @base_urls.key? env

  # This value is NOT included when dumping to YAML.
  # See Configurtion#encode_with
  @current_env = env.to_sym
end

#encode_with(coder) ⇒ Object

Control which instance vars are emitted when dumped to YAML.



208
209
210
211
212
213
214
215
216
# File 'lib/portal_module.rb', line 208

def encode_with(coder)
  vars = instance_variables.map { |x| x.to_s }
  vars = vars - ["@current_env"]

  vars.each do |var|
    var_val = eval(var)
    coder[var.gsub('@', '')] = var_val
  end
end

#resetObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/portal_module.rb', line 134

def reset
  @default_environment = :dev
  @current_env = nil

  @credentials = {}
  #@credentials = { dev: [ ENV['DEV_USER'], ENV['DEV_PASSWORD'] ],
  #               }

  @base_urls   = {}
  #@base_urls   = { dev: "http://example.com/Portal",
  #               }

  @page_urls   = { 'DataTransformationPage' => "/Admin/DataTransformation.aspx",
                   'PrequalSetupPage'       => "/Admin/PrequalSetup.aspx",
                }

  @browser_timeout = 360

  @orgs = {}

  @download_dir = ''
  @download_timeout = 360
end

#url(page_class) ⇒ Object



194
195
196
197
198
# File 'lib/portal_module.rb', line 194

def url page_class
  suffix = @page_urls[page_class.to_s.split('::').last]
  raise "Unkown page [#{page_class.to_s}]" if suffix.nil?
  base_url + suffix
end

#user_credentialsObject



200
201
202
# File 'lib/portal_module.rb', line 200

def user_credentials
  @credentials[current_env]
end