chainable_methods 0.1.2 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3ba65326dbdf9e52dc0cc60ac86f30a8463e11e
4
- data.tar.gz: 676a58f53f7c3304d9ec84e449259d3251c3cacb
3
+ metadata.gz: b0d4a0cea382228024a634b6fb49dbc51c532b17
4
+ data.tar.gz: 32f219904e97cca4b4f07ea1be3915cf4723dec9
5
5
  SHA512:
6
- metadata.gz: 39617913f8991b301f54cc1fb79ebd1dcab4ffab9898bfc80fe920d0a5776e9124ba0c42efd5c95a760b3c8202f99ac0d89a296ca300afd5e94e5cfaef324cd9
7
- data.tar.gz: 3114b059d897afb0b82f4aa9f2b60fdc5f0de3685bff2b7d1a141c9e6029ce2afa058dcc8044f375ba548dfb477755d5af4cbb0d47506d7cbac4883a251a116a
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'], 2)
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).
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.11"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "minitest", "~> 5.0"
25
+ spec.add_development_dependency "nokogiri", "~> 1.6.8"
25
26
  end
@@ -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(context, initial_state)
49
+ def CM(initial_state, context = ChainableMethods::Nil)
41
50
  ChainableMethods.wrap(context, initial_state)
42
51
  end
@@ -1,3 +1,3 @@
1
1
  module ChainableMethods
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  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.2
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-02-23 00:00:00.000000000 Z
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.