chainable_methods 0.1.3 → 0.2.0

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.
@@ -1,42 +1,52 @@
1
1
  require "chainable_methods/version"
2
2
 
3
- module ChainableMethods
4
- module Nil
5
- # TODO placeholder for shortcut initializer. not the best option but works for now
6
- end
3
+ # easier shortcut
4
+ def CM(initial_state, context = ChainableMethods::Nil)
5
+ ChainableMethods::Link.new(initial_state, context)
6
+ end
7
7
 
8
- def chain_from(initial_state)
9
- ChainableMethods::Link.new(initial_state, self)
8
+ module ChainableMethods
9
+ # TODO placeholder context to always delegate method missing to the state object
10
+ module Nil; end
11
+
12
+ def self.included(base)
13
+ base.extend(self)
14
+ begin
15
+ # this way the module doesn't have to declare all methods as class methods
16
+ base.extend(base) if base.kind_of?(Module)
17
+ rescue TypeError
18
+ # wrong argument type Class (expected Module)
19
+ end
10
20
  end
11
21
 
12
- def self.wrap(context, initial_state)
22
+ def chain_from(initial_state, context = self)
13
23
  ChainableMethods::Link.new(initial_state, context)
14
24
  end
15
25
 
16
26
  class Link
17
- attr_reader :state, :context
18
-
19
27
  def initialize(object, context)
20
28
  @state = object
21
29
  @context = context
22
30
  end
23
31
 
24
32
  def chain(&block)
25
- new_state = block.call(state)
26
- ChainableMethods::Link.new( new_state, context )
33
+ new_state = block.call(@state)
34
+ ChainableMethods::Link.new( new_state, @context )
27
35
  end
28
36
 
29
- def method_missing(name, *args, &block)
30
- local_response = state.respond_to?(name)
31
- context_response = context.respond_to?(name)
37
+ def method_missing(method_name, *args, &block)
38
+ local_response = @state.respond_to?(method_name)
39
+ context_response = @context.respond_to?(method_name)
32
40
 
33
41
  # if the state itself has the means to respond, delegate to it
34
42
  # but if the context has the behavior, it has priority over the delegation
35
- if local_response && !context_response
36
- ChainableMethods::Link.new( state.send(name, *args, &block), context)
37
- else
38
- ChainableMethods::Link.new( context.send(name, *([state] + args), &block), context )
39
- end
43
+ new_state = if local_response && !context_response
44
+ @state.send(method_name, *args, &block)
45
+ else
46
+ @context.send(method_name, *args.unshift(@state), &block)
47
+ end
48
+
49
+ ChainableMethods::Link.new( new_state, @context )
40
50
  end
41
51
 
42
52
  def unwrap
@@ -44,8 +54,3 @@ module ChainableMethods
44
54
  end
45
55
  end
46
56
  end
47
-
48
- # easier shortcut
49
- def CM(initial_state, context = ChainableMethods::Nil)
50
- ChainableMethods.wrap(context, initial_state)
51
- end
@@ -1,3 +1,3 @@
1
1
  module ChainableMethods
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
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.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AkitaOnRails
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-17 00:00:00.000000000 Z
11
+ date: 2016-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,11 +52,28 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.10.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.10.3
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: nokogiri
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.6'
76
+ - - ">="
60
77
  - !ruby/object:Gem::Version
61
78
  version: 1.6.8
62
79
  type: :development
@@ -64,8 +81,51 @@ dependencies:
64
81
  version_requirements: !ruby/object:Gem::Requirement
65
82
  requirements:
66
83
  - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '1.6'
86
+ - - ">="
67
87
  - !ruby/object:Gem::Version
68
88
  version: 1.6.8
89
+ - !ruby/object:Gem::Dependency
90
+ name: vcr
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.0'
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 3.0.3
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '3.0'
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 3.0.3
109
+ - !ruby/object:Gem::Dependency
110
+ name: webmock
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '2.1'
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: 2.1.0
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '2.1'
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 2.1.0
69
129
  description: The idea is to allow for a more functional way of organizing code within
70
130
  a module and being able to chain those methdos together, where the result of the
71
131
  first method serves as the first argument of the next method in the chain.
@@ -85,6 +145,7 @@ files:
85
145
  - bin/console
86
146
  - bin/setup
87
147
  - chainable_methods.gemspec
148
+ - fixtures/vcr_cassettes/github-test.yml
88
149
  - lib/chainable_methods.rb
89
150
  - lib/chainable_methods/version.rb
90
151
  homepage: http://www.codeminer42.com
@@ -110,6 +171,6 @@ rubyforge_project:
110
171
  rubygems_version: 2.5.1
111
172
  signing_key:
112
173
  specification_version: 4
113
- summary: Just a simple experiment to allow for a behavior similar to Elixir's Pipe
114
- Operator but within Ruby's semantics.
174
+ summary: Just a simple experiment to allow for a behavior similar to [Elixir|Haskell|F#]'s
175
+ Pipe Operator but within Ruby's semantics.
115
176
  test_files: []