Class: Calabash::Android::Preferences
- Inherits:
-
Object
- Object
- Calabash::Android::Preferences
- Defined in:
- lib/calabash-android/store/preferences.rb
Overview
Users preferences persisted across runs:
~/.calabash/preferences/preferences.json
Instance Method Summary collapse
-
#initialize ⇒ Preferences
constructor
A new instance of Preferences.
- #inspect ⇒ Object
- #to_s ⇒ Object
-
#usage_tracking ⇒ Object
[email protected] private.
-
#usage_tracking=(value) ⇒ Object
[email protected] private.
-
#user_id ⇒ Object
[email protected] private.
-
#user_id=(value) ⇒ Object
[email protected] private.
Constructor Details
#initialize ⇒ Preferences
Returns a new instance of Preferences.
13 14 15 16 |
# File 'lib/calabash-android/store/preferences.rb', line 13 def initialize dot_dir = Calabash::Android::DotDir.directory @path = File.join(dot_dir, "preferences", "preferences.json") end |
Instance Method Details
#inspect ⇒ Object
23 24 25 |
# File 'lib/calabash-android/store/preferences.rb', line 23 def inspect to_s end |
#to_s ⇒ Object
18 19 20 21 |
# File 'lib/calabash-android/store/preferences.rb', line 18 def to_s $stdout.puts "Preferences:" ap read end |
#usage_tracking ⇒ Object
[email protected] private
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/calabash-android/store/preferences.rb', line 28 def usage_tracking preferences = read unless valid_user_tracking_value?(preferences[:usage_tracking]) log_defaults_reset preferences[:usage_tracking] = defaults[:usage_tracking] write(preferences) end preferences[:usage_tracking] end |
#usage_tracking=(value) ⇒ Object
[email protected] private
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/calabash-android/store/preferences.rb', line 41 def usage_tracking=(value) if !valid_user_tracking_value?(value) raise ArgumentError, "Expected '#{value}' to be one of #{VALID_USAGE_TRACKING_VALUES.join(", ")}" end preferences = read preferences[:usage_tracking] = value write(preferences) end |
#user_id ⇒ Object
[email protected] private
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/calabash-android/store/preferences.rb', line 53 def user_id preferences = read unless valid_user_id?(preferences[:user_id]) preferences[:user_id] = SecureRandom.uuid write(preferences) end preferences[:user_id] end |
#user_id=(value) ⇒ Object
[email protected] private
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/calabash-android/store/preferences.rb', line 65 def user_id=(value) if !valid_user_id?(value) raise ArgumentError, "Expected '#{value}' to not be nil and not an empty string" end preferences = read preferences[:user_id] = value write(preferences) end |