motion-launchpad 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9d8475a91ccb4f9f7145fbe256abe129be4875fb
4
+ data.tar.gz: c3e2299b74b69312bfc1b00545dfde659c032dca
5
+ SHA512:
6
+ metadata.gz: 4ac55aa3d16ce738f3aa5d2e92bdc3dde59fd3ad913b57049e874303427fdd3dde50d4e6caf7de30e3cbeff91824c73987d608b96a005aaa1ec867724dc2d8af
7
+ data.tar.gz: f732c2cf51d486640bcea82f1c9e3fa5ccf4ef75c82d10c7fff5320a6a5ee385a0e7948de8b2e88cd263985b7ffcd749dae86f5916136aaf15958ab2c86d18b5
@@ -0,0 +1,51 @@
1
+ # motion-launchpad
2
+ Provides a simple DSL to easily schedule events, on the 1st, 3rd, 500th, or every launch. This gem requires [RubyMotion](http://www.rubymotion.com).
3
+
4
+ ## Installation
5
+
6
+ Add the following to your project's Gemfile to work with bundler:
7
+
8
+ ```ruby
9
+ gem 'motion-launchpad'
10
+ ```
11
+
12
+ Install with bundler:
13
+
14
+ ```shell
15
+ bundle install
16
+ ```
17
+
18
+ ## Using
19
+
20
+ After installation, you can use the gem in your project like so:
21
+
22
+ ```ruby
23
+ class AppDelegate
24
+ def application(app, didFinishLaunchingWithOptions: options)
25
+
26
+ setup_schedule
27
+ Motion::Launchpad.run!
28
+ end
29
+
30
+ private
31
+
32
+ def setup_schedule
33
+ Motion::Launchpad.configure do |config|
34
+ config.on :every do
35
+ # maybe track app launch with analytics?
36
+ end
37
+
38
+ config.on 1 do
39
+ # first launch, maybe show user a tutorial?
40
+ end
41
+ end
42
+ end
43
+
44
+ # You can call `configure` multiple times
45
+ Motion::Launchpad.configure do |config|
46
+ config.on 5 do
47
+ # ask user to rate your app? Hate doing that, but best I could come up with
48
+ end
49
+ end
50
+ end
51
+ ```
@@ -0,0 +1,9 @@
1
+ unless defined?(Motion::Project::Config)
2
+ raise "This file must be required within a RubyMotion project Rakefile."
3
+ end
4
+
5
+ lib_dir_path = File.dirname(File.expand_path(__FILE__))
6
+ Motion::Project::App.setup do |app|
7
+ gem_files = Dir.glob(File.join(lib_dir_path, "motion/**/*.rb"))
8
+ app.files.unshift(gem_files).flatten!
9
+ end
@@ -0,0 +1,20 @@
1
+ module Motion
2
+ module Launchpad
3
+
4
+ class << self
5
+ attr_accessor :instance
6
+ end
7
+
8
+ def configure(*args, &block)
9
+ self.instance = Schedule.new(*args) if instance.nil?
10
+ instance.configure(&block) if block_given?
11
+ instance
12
+ end
13
+
14
+ def run!
15
+ instance.run!
16
+ end
17
+
18
+ module_function :configure, :run!
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ module Motion
2
+ module Launchpad
3
+ class Event
4
+ attr_reader :count, :callback
5
+
6
+ def initialize(count, callback)
7
+ @count, @callback = count, callback
8
+ end
9
+
10
+ def call
11
+ callback.call
12
+ end
13
+
14
+ def applicable?(launch)
15
+ every? || launch == count
16
+ end
17
+
18
+ def every?
19
+ count == :every
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,44 @@
1
+ module Motion
2
+ module Launchpad
3
+ class Schedule
4
+ attr_accessor :preferences_key
5
+
6
+ def initialize(options={}, &block)
7
+ self.preferences_key = options.fetch(:preferences_key, :launch_count)
8
+ @events = []
9
+
10
+ handle_launch
11
+ end
12
+
13
+ def configure
14
+ yield(self) if block_given?
15
+ end
16
+
17
+ def on(count, &block)
18
+ @events << Event.new(count, block)
19
+ end
20
+
21
+ def run!
22
+ events.each { |e| e.call }
23
+ end
24
+
25
+ def events
26
+ @events.select { |e| e.applicable?(launch_count) }
27
+ end
28
+
29
+ private
30
+
31
+ def launch_count
32
+ NSUserDefaults.standardUserDefaults[preferences_key]
33
+ end
34
+
35
+ def handle_launch
36
+ if NSUserDefaults.standardUserDefaults[preferences_key].nil?
37
+ NSUserDefaults.standardUserDefaults[preferences_key] = 1
38
+ else
39
+ NSUserDefaults.standardUserDefaults[preferences_key] = NSUserDefaults.standardUserDefaults[preferences_key] + 1
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ module Motion
2
+ module Launchpad
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ describe Motion::Launchpad do
2
+
3
+ it "should return an instance" do
4
+ Motion::Launchpad.configure.should.be.instance_of Motion::Launchpad::Schedule
5
+ end
6
+
7
+ it "should return the same instance twice" do
8
+ instance = Motion::Launchpad.configure
9
+ instance.should.be.equal Motion::Launchpad.configure
10
+ end
11
+
12
+ it "delegates #run! to an instance" do
13
+ @runner = nil
14
+
15
+ Motion::Launchpad.configure do |config|
16
+ config.on(:every) { @runner = true }
17
+ end
18
+
19
+ Motion::Launchpad.run!
20
+ @runner.should.be.true
21
+ end
22
+ end
@@ -0,0 +1,39 @@
1
+ describe Motion::Launchpad::Event do
2
+
3
+ def event(count, callback=nil)
4
+ Motion::Launchpad::Event.new count, callback
5
+ end
6
+
7
+ describe '#every?' do
8
+ it "returns false if not a symbol matching :every" do
9
+ event(1).should.not.be.every
10
+ end
11
+
12
+ it "returns true if given :every" do
13
+ event(:every).should.be.every
14
+ end
15
+ end
16
+
17
+ describe '#applicable?' do
18
+ it "returns always returns true if #every? is true" do
19
+ event(:every).should.be.applicable(1)
20
+ event(:every).should.be.applicable(5)
21
+ end
22
+
23
+ it "returns false if count does not match" do
24
+ event(1).should.not.be.applicable(5)
25
+ end
26
+
27
+ it "returns true if count matches" do
28
+ event(1).should.be.applicable(1)
29
+ end
30
+ end
31
+
32
+ describe '#call' do
33
+ it "executes the given block" do
34
+ e = event :every, ->{ true }
35
+ e.call.should.be.true
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,65 @@
1
+ describe Motion::Launchpad::Schedule do
2
+
3
+ before do
4
+ NSUserDefaults.standardUserDefaults[:launch_count] = nil
5
+ end
6
+
7
+ describe '#configure' do
8
+ it "runs the block" do
9
+ instance = Motion::Launchpad::Schedule.new
10
+ instance.configure { true }.should.be.true
11
+ end
12
+ end
13
+
14
+ it "defaults the preferences key to :launch_count" do
15
+ instance = Motion::Launchpad::Schedule.new
16
+ instance.preferences_key.should.be.equal :launch_count
17
+ end
18
+
19
+ it "allows you to customize the preferences key" do
20
+ instance = Motion::Launchpad::Schedule.new preferences_key: :my_counter
21
+ instance.preferences_key.should.be.equal :my_counter
22
+ end
23
+
24
+ it "initializes NSUserDefaults store on #new" do
25
+ instance = Motion::Launchpad::Schedule.new
26
+ NSUserDefaults.standardUserDefaults[:launch_count].should.be.equal 1
27
+ end
28
+
29
+ it "adds a new event when call #on inside the configure block" do
30
+ instance = Motion::Launchpad::Schedule.new
31
+ instance.configure do |config|
32
+ config.on(:every) { true }
33
+ end
34
+
35
+ instance.events.should.not.be.empty
36
+ e = instance.events.first
37
+ e.count.should.be.equal :every
38
+ end
39
+
40
+ it "calling #configure multiple times continues to add events" do
41
+ instance = Motion::Launchpad::Schedule.new
42
+ instance.configure do |config|
43
+ config.on(:every) { true }
44
+ end
45
+
46
+ instance.configure do |config|
47
+ config.on(1) { true }
48
+ end
49
+
50
+ instance.events.count.should.be.equal 2
51
+ end
52
+
53
+ it "executes the events when calling #run!" do
54
+ instance = Motion::Launchpad::Schedule.new
55
+ instance.configure do |config|
56
+ config.on(:every) { NSUserDefaults.standardUserDefaults[:my_testing_key] = "test" }
57
+ end
58
+
59
+ NSUserDefaults.standardUserDefaults[:my_testing_key].should.be.nil
60
+
61
+ instance.run!
62
+
63
+ NSUserDefaults.standardUserDefaults[:my_testing_key].should.be.equal "test"
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-launchpad
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matt Brewer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: DSL to schedule events on app launch and keeps track of app launch for
28
+ you.
29
+ email:
30
+ - matt.brewer@me.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - README.md
36
+ - lib/motion-launchpad.rb
37
+ - lib/motion/launchpad.rb
38
+ - lib/motion/launchpad/event.rb
39
+ - lib/motion/launchpad/schedule.rb
40
+ - lib/motion/launchpad/version.rb
41
+ - spec/configuration_spec.rb
42
+ - spec/event_spec.rb
43
+ - spec/schedule_spec.rb
44
+ homepage: https://github.com/macfanatic/motion-launchpad
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project: "[none]"
64
+ rubygems_version: 2.2.2
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Provides an easy DSL for scheduling events on app launch
68
+ test_files:
69
+ - spec/configuration_spec.rb
70
+ - spec/event_spec.rb
71
+ - spec/schedule_spec.rb