Skip to content

Commit fd95af1

Browse files
authored
Merge pull request #1 from splitwise/jess/update-readme
Update readme and rubocop
2 parents ca4dddc + 1f6ccbb commit fd95af1

9 files changed

Lines changed: 23 additions & 23 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@
1111

1212
#RSpec
1313
spec/examples.txt
14+
15+
#Rubymine
16+
.idea

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ By [Splitwise](https://www.splitwise.com)
55
Cacheable is a gem which intends to add method caching in an [aspect-oriented programming (AOP)](https://en.wikipedia.org/wiki/Aspect-oriented_programming) fashion in Ruby. Its core goals are:
66

77
* ease of use (method annotation)
8-
* flexibility (simple adaptablability for any cache backend)
8+
* flexibility (simple adaptability for any cache backend)
99
* portability (plain Ruby for use with any framework)
1010

11-
While Rails is not a requirement, Cacheable was built inside a mature Rails app and later extracted. This first release will seemlyless work in Rails and only includes an adapter for an in-memory cache backed by a simple Hash. This may be enough for you needs but it is more likely that additional cache adapters will need to be written.
11+
While Rails is not a requirement, Cacheable was built inside a mature Rails app and later extracted. This first release will seamlessly work in Rails and only includes an adapter for an in-memory cache backed by a simple Hash. This may be enough for your needs but it is more likely that additional cache adapters will need to be written.
1212

1313
See more about [Cache Adapters](cache-adapters.md).
1414

@@ -32,7 +32,7 @@ Cacheable.cache_adapter = :memory
3232

3333
### Simple Implementation Example
3434

35-
Cacheable is designed to work seemlessly with your already existings codebase. Consider the following contrived class:
35+
Cacheable is designed to work seamlessly with your already existing codebase. Consider the following contrived class:
3636

3737
```ruby
3838
class SimpleExample
@@ -62,7 +62,7 @@ class SimpleExample
6262
end
6363
```
6464

65-
**Thats it!** There's some complex Ruby magic going on under the hood but to the end user you can simply call `expensive_calculation` and the result will be retreived from the cache, if available, or generated and placed into the cache. To confirm it is working, fire up an IRB console try the following:
65+
**That's it!** There's some complex Ruby magic going on under the hood but to the end user you can simply call `expensive_calculation` and the result will be retrieved from the cache, if available, or generated and placed into the cache. To confirm it is working, fire up an IRB console try the following:
6666

6767
```irb
6868
> s = SimpleExample.new
@@ -81,7 +81,7 @@ Cacheable also adds two useful methods to your class.
8181

8282
#### Skip the Cache via `#{method}_without_cache`
8383

84-
The cache can intentionally be skipped by appending `_without_cache` to the method name. This invocation with neither check the cache nor populate it as if you called the original method and never used Cacheable.
84+
The cache can intentionally be skipped by appending `_without_cache` to the method name. This invocation will neither check the cache nor populate it. It is as if you called the original method and never used Cacheable.
8585

8686
```irb
8787
> s = SimpleExample.new
@@ -95,7 +95,7 @@ beginning expensive method
9595

9696
#### Remove the Value via `clear_#{method}_cache`
9797

98-
The cache can be cleared at any time by calling `clear_#{your_method_name}_cache`.
98+
The cached value can be cleared at any time by calling `clear_#{your_method_name}_cache`.
9999

100100
```irb
101101
> s = SimpleExample.new
@@ -151,7 +151,7 @@ So if we called `CustomKeyExample.new.my_method(123)` we would get the cache key
151151

152152
`"my_method called on #<CustomKeyExample:0x0…0> with Integer::123"`.
153153

154-
### Conditional Cacheing
154+
### Conditional Caching
155155

156156
You can control if a method should be cached by supplying a proc to the `unless:` option which will get the same arguments as `key_format:`. Alternatively this method can be defined on the class and a symbol of the name of the method can be passed. **Note**: When using a symbol, the first argument will not be passed but will be available in the method as `self`. The following example will not cache the value if the first argument to the method is `false`.
157157

@@ -189,7 +189,7 @@ cacheable :these, :methods, :share, :options, key_format: key_proc, unless: unle
189189
cacheable :this_method_has_its_own_options, unless: unless_proc2
190190
```
191191

192-
### Class Method Cacheing
192+
### Class Method Caching
193193

194194
You can cache class methods just as easily as a Ruby class is just an instance of `Class`. You simply need to `include Cacheable` within the `class << self` block. Methods can be defined in this block or outside using the `def self.` syntax.
195195

cache-adapters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A cache adapter is an object that Cacheable can use as an interface to your system's cache. Cacheable will work out of the box using the object returned by `Rails.cache` as a cache adapter.
44

5-
The other adapter provided with the library is the [Memory Adapter](lib/cacheable/cache_adapters/memory_adapter.rb). Is a simple memoizing cache used in testing. It is little more than an object that conforms to the protocol and is backed by a Ruby Hash. When writting a new cache adapter it can be used as a template.
5+
The other adapter provided with the library is the [Memory Adapter](lib/cacheable/cache_adapters/memory_adapter.rb). Is a simple memoizing cache used in testing. It is little more than an object that conforms to the protocol and is backed by a Ruby Hash. When writing a new cache adapter it can be used as a template.
66

77
### Protocol
88

@@ -16,7 +16,7 @@ There are only two methods the cache adapter protocol requires.
1616

1717
#### `delete(key)`
1818

19-
`delete` takes a key and removes it's associated value in the cache. While not currently dependend on by Cacheable, it appears the standard is to return `true` if the value was present and removed and `false` if not present to begin with.
19+
`delete` takes a key and removes it's associated value in the cache. While not currently depended on by Cacheable, it appears the standard is to return `true` if the value was present and removed and `false` if not present to begin with.
2020

2121
#### Additional useful methods
2222

cacheable.gemspec

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
# -*- encoding: utf-8 -*-
21
# frozen_string_literal: true
32

4-
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
3+
$LOAD_PATH.push File.expand_path('lib', __dir__)
54
require 'cacheable/version'
65

76
Gem::Specification.new do |s|
87
s.name = 'cacheable'
98
s.version = Cacheable::VERSION
109
s.date = '2018-07-31'
1110
s.summary = 'Add caching to any Ruby method in a aspect orientated programming approach.'
12-
s.description = 'Add caching simply without modifying your existing code. Inlcudes configurable options for simple cache invalidation. See README on github for more information.'
11+
s.description = 'Add caching simply without modifying your existing code. '\
12+
'Includes configurable options for simple cache invalidation. '\
13+
'See README on github for more information.'
1314
s.authors = ['Jess Hottenstein', 'Ryan Laughlin', 'Aaron Rosenberg']
1415
s.email = 'support@splitwise.com'
1516
s.files = Dir['lib/**/*', 'README.md', 'cache-adapters.md']
1617
s.homepage = 'https://github.com/splitwise/cacheable'
1718
s.licenses = 'MIT'
18-
s.required_ruby_version = '>= 2.0.0'
19+
s.required_ruby_version = '>= 2.3.0'
1920
end

lib/cacheable/cache_adapter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ def cache_adapter
1515
end
1616

1717
def cache_adapter=(name_or_adapter)
18-
@_cache_adapter = interprete_adapter(name_or_adapter)
18+
@_cache_adapter = interpret_adapter(name_or_adapter)
1919
end
2020

2121
private
2222

23-
def interprete_adapter(name_or_adapter)
23+
def interpret_adapter(name_or_adapter)
2424
return name_or_adapter if cache_adapter?(name_or_adapter)
2525

2626
unless [Symbol, String].include?(name_or_adapter.class)

lib/cacheable/method_generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
23
require 'English'
34

45
module Cacheable

spec/cacheable/cache_adapter_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'spec_helper'
2-
31
RSpec.describe Cacheable::CacheAdapter do
42
subject(:adapter_object) { Class.new { extend(Cacheable::CacheAdapter) } }
53

spec/cacheable/cache_adapters/memory_adapter_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
require 'spec_helper'
21
require 'cacheable/cache_adapters/memory_adapter'
32

43
RSpec.describe Cacheable::CacheAdapters::MemoryAdapter do

spec/cacheable/cacheable_spec.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'spec_helper'
2-
31
RSpec.describe Cacheable do
42
subject(:cacheable_object) { cacheable_class.new }
53

@@ -231,8 +229,8 @@ class RealClassName
231229
end
232230
end
233231

234-
describe 'syntatic sugar' do
235-
it 'allows cachable to be used before the method is defined' do
232+
describe 'syntactic sugar' do
233+
it 'allows cacheable to be used before the method is defined' do
236234
cacheable_called_before_definition = :cacheable_called_before_definition
237235
inner_method = cacheable_method_inner
238236
cacheable_class.class_eval do

0 commit comments

Comments
 (0)