Class: Keepcon::Context

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Context

Returns a new instance of Context.



6
7
8
9
10
# File 'lib/keepcon/context.rb', line 6

def initialize(params = {})
  @mappings = {}
  map(params[:mappings])
  params.except(:mappings).each { |k, v| send("#{k}=", v) }
end

Instance Attribute Details

#password=(value) ⇒ Object (writeonly)

Sets the attribute password

Parameters:

  • value

    the value to set the attribute password to.



4
5
6
# File 'lib/keepcon/context.rb', line 4

def password=(value)
  @password = value
end

#userObject

Returns the value of attribute user.



3
4
5
# File 'lib/keepcon/context.rb', line 3

def user
  @user
end

Instance Method Details

#attribute_namesObject



21
22
23
# File 'lib/keepcon/context.rb', line 21

def attribute_names
  @mappings.keys
end

#clientObject



25
26
27
28
29
30
# File 'lib/keepcon/context.rb', line 25

def client
  @client ||= Client.new do |config|
    config.user = user
    config.password = @password
  end
end

#map(hash) ⇒ Object



12
13
14
15
# File 'lib/keepcon/context.rb', line 12

def map(hash)
  return unless hash.present?
  hash.each { |k, v| add_mapping(k, v) }
end

#translate(attribute) ⇒ Object



17
18
19
# File 'lib/keepcon/context.rb', line 17

def translate(attribute)
  @mappings[attribute].try(:to)
end