tuto_man 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c8eaa86ecdcfb035bcf325f07a4f20405308354f
4
+ data.tar.gz: d61c82f31db71aa241329150f70f89a662a8ce73
5
+ SHA512:
6
+ metadata.gz: 5dc38275fbecdb7b7a20be27556e44bc80ae192e21df0336b3c492678bc8afa3a21fe319fbad876abe293a2b5bd45b0e3a9bf962cbf8576f2579e15faaa60ad8
7
+ data.tar.gz: 9b0d34c5da0e061dae34729bdff96841c5e8aa80e3ad656434ba50d83a3bc7ea6f97a3375167217e8bb8cb2c897e0e0fe1891536adb92d14e47f7fc5ba537b09
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tuto_man.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tuto_man (0.0.1)
5
+ activesupport
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (4.1.0)
11
+ i18n (~> 0.6, >= 0.6.9)
12
+ json (~> 1.7, >= 1.7.7)
13
+ minitest (~> 5.1)
14
+ thread_safe (~> 0.1)
15
+ tzinfo (~> 1.1)
16
+ diff-lcs (1.2.5)
17
+ i18n (0.6.9)
18
+ json (1.8.1)
19
+ minitest (5.3.2)
20
+ rake (10.2.2)
21
+ rspec (2.14.1)
22
+ rspec-core (~> 2.14.0)
23
+ rspec-expectations (~> 2.14.0)
24
+ rspec-mocks (~> 2.14.0)
25
+ rspec-core (2.14.8)
26
+ rspec-expectations (2.14.5)
27
+ diff-lcs (>= 1.1.3, < 2.0)
28
+ rspec-mocks (2.14.6)
29
+ thread_safe (0.3.3)
30
+ tzinfo (1.1.0)
31
+ thread_safe (~> 0.1)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler (~> 1.5)
38
+ rake
39
+ rspec
40
+ tuto_man!
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 KRAY Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # TutoMan
2
+
3
+ TutoMan manages diplays of tutorial views or reminders in a rails application.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'tuto_man'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install tuto_man
18
+
19
+ ## Usage
20
+
21
+ ### Configuration
22
+
23
+ Set display timing for each tutorial or reminders.
24
+
25
+ ```ruby
26
+ # config/initializers/tuto_man.rb
27
+ TutoMan :my_tuto, interval: 7 * 24 * 60 * 60 # once shown suppress for 1 week
28
+ ```
29
+
30
+ ### Control
31
+
32
+ ```ruby
33
+ # tell if a tuto is displaying
34
+ tuto(:my_tuto).on?
35
+
36
+ # mark as shown
37
+ tuto(:my_tuto).shown
38
+
39
+ # turn off forever
40
+ tuto(:my_tuto).off
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( http://github.com/<my-github-username>/tuto_man/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/tuto_man.rb ADDED
@@ -0,0 +1,82 @@
1
+ require "tuto_man/version"
2
+ require "active_support/core_ext"
3
+
4
+ module TutoManager
5
+ mattr_reader :tutos
6
+ @@tutos = {}
7
+
8
+ module Register
9
+ def TutoMan(id, options = {})
10
+ TutoManager.tutos[id] = options
11
+ end
12
+ end
13
+
14
+ module Helpers
15
+ class Tuto
16
+ def initialize(id, session)
17
+ @id = id
18
+ @session = session
19
+ end
20
+
21
+ def off
22
+ @session[:"_#{@id}_disabled"] = true
23
+ end
24
+
25
+ def on?
26
+ enabled? && (options[:days_after] ? day_after? : elapsed?)
27
+ end
28
+
29
+ def shown
30
+ now = Time.now
31
+ if options[:days_after]
32
+ @session[:"_next_#{@id}_at"] = (now.mday < options[:days_after] ? now : now.next_month).change(day: options[:days_after]).to_s
33
+ else
34
+ @session[:"_#{@id}_shown_at"] = now.to_s
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def day_after?
41
+ now = Time.now
42
+ @session[:"_next_#{@id}_at"] ||= (now.mday < options[:days_after] ? now.change(day: options[:days_after]) : now).to_s
43
+ now >= @session[:"_next_#{@id}_at"]
44
+ end
45
+
46
+ def elapsed?
47
+ shown_at.nil? || Time.parse(shown_at) + interval < Time.now
48
+ end
49
+
50
+ def enabled?
51
+ !@session[:"_#{@id}_disabled"]
52
+ end
53
+
54
+ def interval
55
+ options[:interval] ||= 24 * 60 * 60
56
+ end
57
+
58
+ def options
59
+ TutoManager.tutos[@id]
60
+ end
61
+
62
+ def shown_at
63
+ @session[:"_#{@id}_shown_at"]
64
+ end
65
+ end
66
+
67
+ def tuto(id)
68
+ Tuto.new(id, session)
69
+ end
70
+ end
71
+ end
72
+
73
+ Object.class_eval do
74
+ include TutoManager::Register
75
+ end
76
+
77
+ if defined?(ActionController)
78
+ ActionController::Base.class_eval do
79
+ include TutoManager::Helpers
80
+ helper_method :tuto
81
+ end
82
+ end
@@ -0,0 +1,3 @@
1
+ module TutoMan
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,94 @@
1
+ require 'tuto_man'
2
+
3
+ describe TutoManager::Helpers do
4
+ before do
5
+ @controller_class = Class.new
6
+ @controller = @controller_class.new
7
+ @controller_class.send(:include, TutoManager::Helpers)
8
+ @controller.stub(:session).and_return(session)
9
+ end
10
+
11
+ describe "Interval mode" do
12
+ before { TutoMan :foo }
13
+
14
+ describe "#on?" do
15
+ subject { @controller.tuto(:foo).on? }
16
+
17
+ context "first time" do
18
+ let(:session){ {} }
19
+ it { should be_true }
20
+ end
21
+
22
+ context "recently shown" do
23
+ let(:session){ {} }
24
+ before { @controller.tuto(:foo).shown }
25
+ it { should be_false }
26
+ end
27
+
28
+ context "shown long time ago" do
29
+ let(:session){ {foo_shown_at: 2.days.ago.to_s} }
30
+ it { should be_true }
31
+
32
+ context "turned off" do
33
+ before { @controller.tuto(:foo).off }
34
+ it { should be_false }
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ describe "After day of month mode" do
41
+ before { TutoMan :bar, days_after: 20 }
42
+
43
+ describe "#on?" do
44
+ subject { @controller.tuto(:bar).on? }
45
+
46
+ context "on Jan 15" do
47
+ before { Time.stub(now: Time.new(2013, 1, 15)) }
48
+
49
+ context "first time" do
50
+ let(:session){ {} }
51
+ it { should be_false }
52
+ end
53
+
54
+ context "second time" do
55
+ let(:session){ {_next_bar_at: '2013-01-20 00:00:00 +0900'} }
56
+ it { should be_false }
57
+ end
58
+ end
59
+
60
+ context "on Jan 25" do
61
+ before { Time.stub(now: Time.new(2013, 1, 25)) }
62
+
63
+ context "first time" do
64
+ let(:session){ {} }
65
+ it { should be_true }
66
+ end
67
+
68
+ context "second time" do
69
+ let(:session){ {_next_bar_at: '2013-02-20 00:00:00 +0900'} }
70
+ it { should be_false }
71
+ end
72
+ end
73
+ end
74
+
75
+ describe "#shown" do
76
+ let(:session){ {} }
77
+ before do
78
+ Time.stub(now: Time.new(2013, 1, mday))
79
+ @controller.tuto(:bar).shown
80
+ end
81
+ subject { session[:_next_bar_at] }
82
+
83
+ context "on Jan 15" do
84
+ let(:mday){ 15 }
85
+ it { should eq '2013-01-20 00:00:00 +0900' }
86
+ end
87
+
88
+ context "on Jan 25" do
89
+ let(:mday){ 25 }
90
+ it { should eq '2013-02-20 00:00:00 +0900' }
91
+ end
92
+ end
93
+ end
94
+ end
data/tuto_man.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tuto_man/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tuto_man"
8
+ spec.version = TutoMan::VERSION
9
+ spec.authors = ["Hiroki Yoshioka"]
10
+ spec.email = ["irohiroki@gmail.com"]
11
+ spec.summary = %q{A tutorial view or reminder manager for rails applications.}
12
+ spec.description = %q{TutoMan manages diplays of tutorial views or reminders in a rails application.}
13
+ spec.homepage = "https://github.com/krayinc/tuto_man"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activesupport"
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tuto_man
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hiroki Yoshioka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: TutoMan manages diplays of tutorial views or reminders in a rails application.
70
+ email:
71
+ - irohiroki@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/tuto_man.rb
83
+ - lib/tuto_man/version.rb
84
+ - spec/tuto_man_spec.rb
85
+ - tuto_man.gemspec
86
+ homepage: https://github.com/krayinc/tuto_man
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.0
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: A tutorial view or reminder manager for rails applications.
110
+ test_files:
111
+ - spec/tuto_man_spec.rb