Skip to content

Commit

Permalink
Less is more 🎸
Browse files Browse the repository at this point in the history
  • Loading branch information
ElMassimo committed Apr 3, 2017
1 parent c049d3f commit d06256d
Show file tree
Hide file tree
Showing 35 changed files with 157 additions and 2,363 deletions.
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
*.bundle
*.so
*.o
*.a
mkmf.log
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--format=progress
1 change: 0 additions & 1 deletion .ruby-gemset

This file was deleted.

2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.0.0
ruby-2.3.0
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: ruby
rvm:
- 2.3.0
- 2.1.1
- 2.0.0
1 change: 0 additions & 1 deletion .yardoc/checksums

This file was deleted.

Binary file removed .yardoc/object_types
Binary file not shown.
Binary file removed .yardoc/objects/root.dat
Binary file not shown.
Binary file removed .yardoc/proxy_types
Binary file not shown.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Pakiderm 2.0.0 (2017-04-02) ##

* Use a lighter memoization stragegy based on `instance_variable_defined?`.
* Remove support for `assignable`; not that useful in practice.
16 changes: 3 additions & 13 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
source 'https://rubygems.org'
source "https://rubygems.org"

gemspec
gem 'coveralls', require: false
gem 'rake'
gem 'bundler'

group :test do
gem 'rspec-given'
end

group :doc do
gem 'yard'
gem 'yard-tomdoc'
end
gem "rake"
gem "coveralls", require: false
81 changes: 39 additions & 42 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,61 +1,58 @@
PATH
remote: .
specs:
pakiderm (1.0.0)
pakiderm (2.0.0)

GEM
remote: https://rubygems.org/
specs:
coveralls (0.7.0)
multi_json (~> 1.3)
rest-client
simplecov (>= 0.7)
term-ansicolor
thor
diff-lcs (1.2.5)
docile (1.1.3)
given_core (3.5.4)
coveralls (0.8.20)
json (>= 1.8, < 3)
simplecov (~> 0.14.1)
term-ansicolor (~> 1.3)
thor (~> 0.19.4)
tins (~> 1.6)
diff-lcs (1.3)
docile (1.1.5)
given_core (3.8.0)
sorcerer (>= 0.3.7)
mime-types (2.2)
multi_json (1.9.2)
rake (10.2.2)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.8)
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
rspec-given (3.5.4)
given_core (= 3.5.4)
rspec (>= 2.12)
rspec-mocks (2.14.6)
simplecov (0.8.2)
json (2.0.3)
rake (12.0.0)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-given (3.8.0)
given_core (= 3.8.0)
rspec (>= 2.14.0)
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
simplecov (0.14.1)
docile (~> 1.1.0)
multi_json
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
sorcerer (1.0.2)
term-ansicolor (1.3.0)
term-ansicolor (1.5.0)
tins (~> 1.0)
thor (0.19.1)
tins (1.1.0)
tomparse (0.4.2)
yard (0.8.7.4)
yard-tomdoc (0.7.1)
tomparse (>= 0.4.0)
yard
thor (0.19.4)
tins (1.13.2)

PLATFORMS
ruby

DEPENDENCIES
bundler
coveralls
pakiderm!
rake
rspec-given
yard
yard-tomdoc
rspec-given (~> 3.0)

BUNDLED WITH
1.14.6
32 changes: 10 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@ Pakiderm

[![Gem Version](https://badge.fury.io/rb/pakiderm.svg)](http://badge.fury.io/rb/pakiderm)
[![Build Status](https://travis-ci.org/ElMassimo/pakiderm.svg)](https://travis-ci.org/ElMassimo/pakiderm)
[![Coverage Status](https://coveralls.io/repos/ElMassimo/pakiderm/badge.png)](https://coveralls.io/r/ElMassimo/pakiderm)
[![Coverage Status](https://coveralls.io/repos/github/ElMassimo/pakiderm/badge.svg?branch=master)](https://coveralls.io/github/ElMassimo/pakiderm?branch=master)
[![Inline docs](http://inch-ci.org/github/ElMassimo/pakiderm.svg)](http://inch-ci.org/github/ElMassimo/pakiderm)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ElMassimo/queryable/blob/master/LICENSE.txt)

Allows you to memoize simple methods and works only on ruby 2.0 or greater.
Allows you to unobtrusively memoize simple methods.

## Usage
```ruby
class Counter
extend Pakiderm

memoize \
def increment
@sum = 1 + @sum.to_i
end

memoize :increment, assignable: true
end
```
Your method will only be called the first time, the result will be stored and returned on subsequent invocations.
Expand All @@ -31,28 +30,17 @@ counter.increment
counter.increment
=> 1
counter.increment = 5
=> 5
counter.increment
=> 5
```
As you can see, you can also pass the `assignable` option, so that the memoized methods also provide an assignment operator to override the memoized value :smiley:.
You can also pass a list of methods that should be memoized:
```ruby
memoize :complex_calculation, :api_response, :db_query
```

## Background
Pakiderm uses `Module#prepend` to add the memoized method before yours in the method lookup path of your class. Your method is called by using 'super', because the class is an ancestor to the prepended module.

### Corolary
If you override a memoized method in a derived class, you alter the method chain, so the derived method won't be memoized unless you invoke memoize in the derived class as well.


## RDocs

You can view the **Pakiderm** documentation in RDoc format here:

http://rubydoc.info/github/ElMassimo/pakiderm/master/frames
Pakiderm adds a method by using `Module#prepend` in order to"intercept" calls to the original method and provide memoization.

### Caveat
If you override the method in a subclass, Pakiderm's method won't be able to intercept calls to the subclass' method.

License
--------
Expand Down
9 changes: 4 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'rspec/core/rake_task'
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = ['--format progress']
end
RSpec::Core::RakeTask.new

task :default => :spec
task default: :spec
Loading

0 comments on commit d06256d

Please sign in to comment.