manana 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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ env:
6
+ global:
7
+ - "TRAVIS=1"
data/.yardopts ADDED
@@ -0,0 +1,8 @@
1
+ --no-private
2
+ --protected
3
+ --title "Manana Documentation"
4
+ --markup markdown
5
+ --readme README.md
6
+ -
7
+ LICENSE.txt
8
+ CHANGELOG.md
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in manana.gemspec
4
+ gemspec
5
+
6
+ # these aren't strictly needed for development but are nice to have
7
+ unless ENV["TRAVIS"] == "1"
8
+ gem 'yard'
9
+ gem 'redcarpet'
10
+ gem 'simplecov'
11
+ gem 'pry'
12
+ end
13
+
14
+ # for travis.cl
15
+ group :test do
16
+ gem 'rake'
17
+ gem 'mocha'
18
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 coldnebo
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,35 @@
1
+ # Manana
2
+
3
+ *Manana* lets you defer the initialization of any class to when an instance method is called.
4
+
5
+ This can be useful in cases where class initialization may take a long time or fail due to errors (i.e. a network service).
6
+ In these situations, you don't want to tie the initialization of service adapters to the initialization of your application,
7
+ because if the service init fails, then your app fails to init and start (i.e. you want your app to be self-healing and
8
+ retry initialization when the method is called later)... also it can unncessarily increase the startup
9
+ time of your app for testcases, etc.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'manana'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install manana
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ end
7
+
8
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ class Manana
2
+ VERSION = "0.0.1"
3
+ end
data/lib/manana.rb ADDED
@@ -0,0 +1,29 @@
1
+ require "manana/version"
2
+
3
+ class Manana
4
+ attr_reader :deferred_initialization, :instance
5
+
6
+ def self.wrap(&block)
7
+ Manana.new(&block)
8
+ end
9
+
10
+ def method_missing(method, *args, &block)
11
+ instance = get_instance
12
+ instance.send(method, *args, &block);
13
+ end
14
+
15
+ private
16
+
17
+ def initialize(&block)
18
+ @deferred_initialization = block
19
+ end
20
+
21
+ def get_instance
22
+ if @instance.nil?
23
+ @instance = @deferred_initialization.call
24
+ end
25
+ @instance
26
+ end
27
+
28
+
29
+ end
data/manana.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'manana/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "manana"
8
+ spec.version = Manana::VERSION
9
+ spec.authors = ["coldnebo"]
10
+ spec.email = ["larry.kyrala@gmail.com"]
11
+ spec.description = %q{provides a simple way to defer initialization of an object to action on an object}
12
+ spec.summary = %q{I'll get to your initialization tomorrow...}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "minitest"
24
+ end
@@ -0,0 +1,12 @@
1
+ unless ENV["TRAVIS"] == "1"
2
+ require 'simplecov'
3
+ require 'pry'
4
+ SimpleCov.start
5
+ end
6
+
7
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
8
+ require 'manana'
9
+
10
+ require 'minitest/autorun'
11
+ require 'mocha/setup'
12
+
@@ -0,0 +1,74 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestManana < MiniTest::Unit::TestCase
4
+ def test_that_it_has_a_version_number
5
+ refute_nil ::Manana::VERSION
6
+ end
7
+
8
+ # initialize a very generic example object that does some stuff in initialization and has some instance methods you can call.
9
+ def setup
10
+ @klass = Class.new
11
+ @klass.class_eval {
12
+ def initialize
13
+ puts "class initialized!"
14
+ end
15
+
16
+ def do_something
17
+ "I did something!" # simulate an arbitrary method
18
+ end
19
+
20
+ def add_something(x,y)
21
+ x+y # simulate a method with params
22
+ end
23
+
24
+ def raise_something
25
+ raise "kablewey!" # simulate a call that raises an exception
26
+ end
27
+
28
+ def self.do_another_thing
29
+ "I did something else" # simulate a class method call
30
+ end
31
+ }
32
+ end
33
+
34
+ # sanity check
35
+ def test_that_things_work_without_manana
36
+ obj = nil
37
+ out, err = capture_io do
38
+ obj = @klass.new
39
+ end
40
+ assert_match(%r%class initialized!%, out)
41
+ assert_instance_of(String, obj.do_something)
42
+ assert_equal(5, obj.add_something(2,3))
43
+ assert_raises RuntimeError do
44
+ obj.raise_something
45
+ end
46
+ end
47
+
48
+ def test_deferred_init
49
+ handle = nil
50
+ out, err = capture_io do
51
+ # the idea here is that we use the 'Strategy' pattern to store the method of initialization.
52
+ # in this case, it's really simple, but in a network service, it might be a config + some class method calls
53
+ # to fully setup a service instance.
54
+ handle = Manana.wrap {
55
+ obj = @klass.new
56
+ }
57
+ end
58
+ # make sure the init isn't executed until we call...
59
+ refute_match(%r%class initialized!%, out)
60
+
61
+ result = nil
62
+ out, err = capture_io do
63
+ result = handle.do_something
64
+ end
65
+ # now it should have been inited
66
+ assert_match(%r%class initialized!%, out)
67
+ # and the method we called used
68
+ assert_instance_of(String, result)
69
+
70
+
71
+ end
72
+
73
+
74
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: manana
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - coldnebo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: provides a simple way to defer initialization of an object to action
63
+ on an object
64
+ email:
65
+ - larry.kyrala@gmail.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .travis.yml
72
+ - .yardopts
73
+ - Gemfile
74
+ - LICENSE.txt
75
+ - README.md
76
+ - Rakefile
77
+ - lib/manana.rb
78
+ - lib/manana/version.rb
79
+ - manana.gemspec
80
+ - test/minitest_helper.rb
81
+ - test/test_manana.rb
82
+ homepage: ''
83
+ licenses:
84
+ - MIT
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ segments:
96
+ - 0
97
+ hash: -3461867159210393723
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ segments:
105
+ - 0
106
+ hash: -3461867159210393723
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 1.8.25
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: I'll get to your initialization tomorrow...
113
+ test_files:
114
+ - test/minitest_helper.rb
115
+ - test/test_manana.rb
116
+ has_rdoc: