mandate 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/README.md +59 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/mandate.rb +10 -0
- data/lib/mandate/call_injector.rb +12 -0
- data/lib/mandate/memoize.rb +30 -0
- data/lib/mandate/version.rb +3 -0
- data/mandate.gemspec +27 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9ab8741425fa1f9095c3eebf35e5a613cfda2838
|
4
|
+
data.tar.gz: ae13f53731aad90ae41f1021cfdabe15b0757a0e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 49e945ea25eb6e058fb1636cc6dabaf83c88cfe25ae5f8ce7bf133e495dfdc428af0162b40af08d25ace04f41cc259b4f1b552f91d013f0a30e36b0ab8fb1519
|
7
|
+
data.tar.gz: 5b8e3f2ba24641cedcc8666d089dd6ff127b65e0f66077862bc3685bb7ed4839cbcca10f4dfd6bbb17e4f2be32a3af12ad260dbfb6ffaad2090a33adb19a0814
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Mandate
|
2
|
+
[![Build Status](https://travis-ci.org/ThalamusAI/mandate.svg?branch=master)](https://travis-ci.org/ThalamusAI/mandate)
|
3
|
+
|
4
|
+
A simple command-pattern helper gem for Ruby.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'mandate'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install mandate
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
class Multiplies
|
26
|
+
include Mandate
|
27
|
+
|
28
|
+
attr_reader :number_1, :number_2
|
29
|
+
def initialize(number_1, number_2)
|
30
|
+
@number_1 = number_1
|
31
|
+
@number_2 = number_2
|
32
|
+
end
|
33
|
+
|
34
|
+
def call
|
35
|
+
do_the_maths
|
36
|
+
end
|
37
|
+
|
38
|
+
# Memoize any method by putting the keyword before it.
|
39
|
+
memoize
|
40
|
+
def do_the_maths
|
41
|
+
sleep(10)
|
42
|
+
number_1 * number_2
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# This calls initializer and then call with the params
|
47
|
+
Multiplies.(20, 3)
|
48
|
+
# => 60
|
49
|
+
```
|
50
|
+
|
51
|
+
## Development
|
52
|
+
|
53
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
54
|
+
|
55
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ThalamusAI/mandate.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mandate"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/mandate.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Mandate
|
2
|
+
module Memoize
|
3
|
+
def memoize
|
4
|
+
@__mandate_memoizing = true
|
5
|
+
end
|
6
|
+
|
7
|
+
def method_added(method_name)
|
8
|
+
super
|
9
|
+
return unless @__mandate_memoizing
|
10
|
+
|
11
|
+
memoizer = Module.new do
|
12
|
+
p method_name
|
13
|
+
define_method method_name do
|
14
|
+
@__mandate_memoized_results ||= {}
|
15
|
+
|
16
|
+
if @__mandate_memoized_results.include?(method_name)
|
17
|
+
@__mandate_memoized_results[method_name]
|
18
|
+
else
|
19
|
+
@__mandate_memoized_results[method_name] = super()
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
prepend memoizer
|
25
|
+
|
26
|
+
@__mandate_memoizing = false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
data/mandate.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "mandate/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mandate"
|
8
|
+
spec.version = Mandate::VERSION
|
9
|
+
spec.authors = ["Jeremy Walker"]
|
10
|
+
spec.email = ["jez.walker@gmail.com"]
|
11
|
+
spec.licenses = ['MIT']
|
12
|
+
|
13
|
+
spec.summary = %q{A simple command-pattern helper gem for Ruby}
|
14
|
+
spec.description = %q{This Ruby Gem adds functionality for the command pattern in Ruby, and for memoization.}
|
15
|
+
spec.homepage = "https://github.com/thalamusai/mandate"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mandate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Walker
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: This Ruby Gem adds functionality for the command pattern in Ruby, and
|
56
|
+
for memoization.
|
57
|
+
email:
|
58
|
+
- jez.walker@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- lib/mandate.rb
|
71
|
+
- lib/mandate/call_injector.rb
|
72
|
+
- lib/mandate/memoize.rb
|
73
|
+
- lib/mandate/version.rb
|
74
|
+
- mandate.gemspec
|
75
|
+
homepage: https://github.com/thalamusai/mandate
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.6.13
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: A simple command-pattern helper gem for Ruby
|
99
|
+
test_files: []
|
100
|
+
has_rdoc:
|