Sha256: 1118ad1b2234aad89be422921b1321a0dfca2bf14378c2b3ae90cbd405f0d2bb

Contents?: true

Size: 913 Bytes

Versions: 2

Compression:

Stored size: 913 Bytes

Contents

# Provides a module to store global states and a persistence layer.
#
module App
  module_function

  @states = {}

  def states
    @states
  end

  def name
    NSBundle.mainBundle.bundleIdentifier
  end

  # Return application frame
  def frame
    UIScreen.mainScreen.applicationFrame
  end

  # Application Delegate
  def delegate
    UIApplication.sharedApplication.delegate
  end

  # Persistence module built on top of NSUserDefaults
  module Persistence
    def self.app_key
      @app_key ||= App.name
    end

    def self.[]=(key, value)
      defaults = NSUserDefaults.standardUserDefaults
      defaults.setObject(value, forKey: storage_key(key))
      defaults.synchronize
    end

    def self.[](key)
      defaults = NSUserDefaults.standardUserDefaults
      defaults.objectForKey storage_key(key)
    end

    private

    def self.storage_key(key)
      app_key + '_' + key
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bubble-wrap-0.1.1 lib/bubble-wrap/app.rb
bubble-wrap-0.1.0 lib/bubble-wrap/app.rb