chainable_methods 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -1
- data/chainable_methods.gemspec +1 -0
- data/lib/chainable_methods.rb +10 -1
- data/lib/chainable_methods/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0d4a0cea382228024a634b6fb49dbc51c532b17
|
4
|
+
data.tar.gz: 32f219904e97cca4b4f07ea1be3915cf4723dec9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 087199d2c14017033ad4bceea79edd564c052dac2535e6764090d6c811c5ae89667d0962e4507ad8d1474e536bd4ab4749bcb3c4dd07f634533cd49cf4dbf9bd
|
7
|
+
data.tar.gz: 25df2f99e191d8fa688175b9742d39b9b723c04193173de47db0ff102b391f4b0d1ff4b7c94f8db6c31ccb1bb76ab44975a340bd20413893d3ca8a83efba063f
|
data/README.md
CHANGED
@@ -119,13 +119,29 @@ v0.1.2
|
|
119
119
|
- introduces a shortcut global method 'CM' to be used like this:
|
120
120
|
|
121
121
|
```
|
122
|
-
CM(['a', 'b', 'c']
|
122
|
+
CM(2, ['a', 'b', 'c'])
|
123
123
|
.[]
|
124
124
|
.upcase
|
125
125
|
.unwrap
|
126
126
|
# => "C"
|
127
127
|
```
|
128
128
|
|
129
|
+
v0.1.3
|
130
|
+
- introduces the #chain method do link blocks of code together, the results are wrapped in the Link object and chained again
|
131
|
+
|
132
|
+
```
|
133
|
+
CM("foo http:///www.google.com bar")
|
134
|
+
.chain { |text| URI.extract(text) }
|
135
|
+
.first
|
136
|
+
.chain { |url| URI.parse(url) }
|
137
|
+
.chain { |uri| open(uri) }
|
138
|
+
.read
|
139
|
+
.chain { |body| Nokogiri::HTML(body) }
|
140
|
+
.css("h1")
|
141
|
+
.first.text.strip
|
142
|
+
.unwrap
|
143
|
+
```
|
144
|
+
|
129
145
|
## License
|
130
146
|
|
131
147
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/chainable_methods.gemspec
CHANGED
data/lib/chainable_methods.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require "chainable_methods/version"
|
2
2
|
|
3
3
|
module ChainableMethods
|
4
|
+
module Nil
|
5
|
+
# TODO placeholder for shortcut initializer. not the best option but works for now
|
6
|
+
end
|
7
|
+
|
4
8
|
def chain_from(initial_state)
|
5
9
|
ChainableMethods::Link.new(initial_state, self)
|
6
10
|
end
|
@@ -17,6 +21,11 @@ module ChainableMethods
|
|
17
21
|
@context = context
|
18
22
|
end
|
19
23
|
|
24
|
+
def chain(&block)
|
25
|
+
new_state = block.call(state)
|
26
|
+
ChainableMethods::Link.new( new_state, context )
|
27
|
+
end
|
28
|
+
|
20
29
|
def method_missing(name, *args, &block)
|
21
30
|
local_response = state.respond_to?(name)
|
22
31
|
context_response = context.respond_to?(name)
|
@@ -37,6 +46,6 @@ module ChainableMethods
|
|
37
46
|
end
|
38
47
|
|
39
48
|
# easier shortcut
|
40
|
-
def CM(
|
49
|
+
def CM(initial_state, context = ChainableMethods::Nil)
|
41
50
|
ChainableMethods.wrap(context, initial_state)
|
42
51
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chainable_methods
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AkitaOnRails
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.6.8
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.6.8
|
55
69
|
description: The idea is to allow for a more functional way of organizing code within
|
56
70
|
a module and being able to chain those methdos together, where the result of the
|
57
71
|
first method serves as the first argument of the next method in the chain.
|