Class: Keepcon::Context
- Inherits:
-
Object
- Object
- Keepcon::Context
- Defined in:
- lib/keepcon/context.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
writeonly
Sets the attribute password.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #attribute_names ⇒ Object
- #client ⇒ Object
-
#initialize(params = {}) ⇒ Context
constructor
A new instance of Context.
- #map(hash) ⇒ Object
- #translate(attribute) ⇒ Object
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
4 5 6 |
# File 'lib/keepcon/context.rb', line 4 def password=(value) @password = value end |
#user ⇒ Object
Returns the value of attribute user.
3 4 5 |
# File 'lib/keepcon/context.rb', line 3 def user @user end |
Instance Method Details
#attribute_names ⇒ Object
21 22 23 |
# File 'lib/keepcon/context.rb', line 21 def attribute_names @mappings.keys end |
#client ⇒ Object
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 |