lotus-utils 0.3.3 → 0.3.4

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: 629a22895276c357e5ee478c10eb6fd0c2c4ef4a
4
- data.tar.gz: 185f59a1c22e690428f1675aa0ebb2a1553ad4ad
3
+ metadata.gz: 339681343526eb287d81d4f52ca29bda0550d8e7
4
+ data.tar.gz: 3e22d02c21a013f03cb1789e307e59054ba37ff1
5
5
  SHA512:
6
- metadata.gz: a3e7907833d632771a62ccd573d72238ca7f454f28c84f440eb85b6cf6b49bb635214bc22d05431861ff163246ef82fea184c30b52132c54c8323e7d4eac157c
7
- data.tar.gz: 589fd11dc42724192687b86d4848b378d90c7a14516fb69117667a7b021df56facd67f91ebbba7fb53fe492a2e010ee22bf6622910fa0a6bed61f83fb19befb7
6
+ metadata.gz: da44a5d936f554ae76be3c7c8195bd416268c5c0f81898df0c4959cc4aee3ab38180fa995943fac286ff464ebed477fb07307562330b0d086162b22fc4dbb41d
7
+ data.tar.gz: 6e835299ce217838cd487070b1ade2a5b7c8916af0eef233e76716257f99b258360faba93ca4ac8c29c84efc6dbccaf46db99d35b81891e00c76f92b39d62fc5
data/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # Lotus::Utils
2
2
  Ruby core extentions and class utilities for Lotus
3
3
 
4
+ ## v0.3.4 - 2015-01-30
5
+ ### Added
6
+ - [Alfonso Uceda Pompa] Aliased `Lotus::Utils::Attributes#get` with `#[]`
7
+ - [Simone Carletti] Introduced `Lotus::Utils::Callbacks::Chain#prepend` and `#append`
8
+
9
+ ### Deprecated
10
+ - [Luca Guidi] Deprecated `Lotus::Utils::Callbacks::Chain#add` in favor of `#append`
11
+
4
12
  ## v0.3.3 - 2015-01-08
5
13
  ### Fixed
6
14
  - [Luca Guidi] Ensure to return the right offending object if a missing method is called with Utils::String and Hash (eg. `Utils::Hash.new(a: 1).all? {|_, v| v.foo }` blame `v` instead of `Hash`)
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Luca Guidi
1
+ Copyright © 2014-2015 Luca Guidi
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -61,4 +61,4 @@ __Lotus::Utils__ uses [Semantic Versioning 2.0.0](http://semver.org)
61
61
 
62
62
  ## Copyright
63
63
 
64
- Copyright 2014 Luca Guidi – Released under MIT License
64
+ Copyright © 2014-2015 Luca Guidi – Released under MIT License
@@ -48,19 +48,30 @@ module Lotus
48
48
  #
49
49
  # attributes.get(:a) # => 1
50
50
  # attributes.get('a') # => 1
51
+ # attributes[:a] # => 1
52
+ # attributes['a'] # => 1
51
53
  #
52
54
  # attributes.get(:b) # => 2
53
55
  # attributes.get('b') # => 2
56
+ # attributes[:b] # => 2
57
+ # attributes['b'] # => 2
54
58
  #
55
59
  # attributes.get(23) # => "foo"
56
60
  # attributes.get('23') # => "foo"
61
+ # attributes[23] # => "foo"
62
+ # attributes[23] # => "foo"
57
63
  #
58
64
  # attributes.get(:unknown) # => nil
59
65
  # attributes.get('unknown') # => nil
66
+ # attributes[:unknown] # => nil
67
+ # attributes['unknown'] # => nil
60
68
  def get(attribute)
61
69
  @attributes[attribute.to_s]
62
70
  end
63
71
 
72
+ # @since 0.3.4
73
+ alias_method :[], :get
74
+
64
75
  # Set the given value for the given attribute
65
76
  #
66
77
  # @param attribute [#to_s] a String or any object that implements #to_s
@@ -1,3 +1,5 @@
1
+ require 'lotus/utils/deprecation'
2
+
1
3
  module Lotus
2
4
  module Utils
3
5
  # Before and After callbacks
@@ -19,21 +21,71 @@ module Lotus
19
21
  @chain = Array.new
20
22
  end
21
23
 
22
- # Adds the given callbacks to the chain
24
+ # Appends the given callbacks to the end of the chain.
23
25
  #
24
- # @param callbacks [Array] one or multiple callbacks to add
25
- # @param blk [Proc] an optional block to be added
26
+ # @param callbacks [Array] one or multiple callbacks to append
27
+ # @param block [Proc] an optional block to be appended
26
28
  #
27
29
  # @return [void]
28
30
  #
29
31
  # @raise [RuntimeError] if the object was previously frozen
30
32
  #
33
+ # @see #prepend
31
34
  # @see #run
32
35
  # @see Lotus::Utils::Callbacks::Callback
33
36
  # @see Lotus::Utils::Callbacks::MethodCallback
34
37
  # @see Lotus::Utils::Callbacks::Chain#freeze
35
38
  #
39
+ # @since 0.3.4
40
+ #
41
+ # @example
42
+ # require 'lotus/utils/callbacks'
43
+ #
44
+ # chain = Lotus::Utils::Callbacks::Chain.new
45
+ #
46
+ # # Append a Proc to be used as a callback, it will be wrapped by `Callback`
47
+ # # The optional argument(s) correspond to the one passed when invoked the chain with `run`.
48
+ # chain.append { Authenticator.authenticate! }
49
+ # chain.append { |params| ArticleRepository.find(params[:id]) }
50
+ #
51
+ # # Append a Symbol as a reference to a method name that will be used as a callback.
52
+ # # It will wrapped by `MethodCallback`
53
+ # # If the #notificate method accepts some argument(s) they should be passed when `run` is invoked.
54
+ # chain.append :notificate
55
+ def append(*callbacks, &block)
56
+ callables(callbacks, block).each do |c|
57
+ @chain.push(c)
58
+ end
59
+
60
+ @chain.uniq!
61
+ end
62
+
36
63
  # @since 0.1.0
64
+ # @deprecated Use Lotus::Utils::Callbacks::Chain#append as it has the
65
+ # same effect, but it's more consistent with the new API.
66
+ #
67
+ # @see Lotus::Utils::Callbacks::Chain#append
68
+ def add(*callbacks, &blk)
69
+ Utils::Deprecation.new("Lotus::Utils::Callbacks::Chain#add is deprecated, use #append instead.")
70
+ append(*callbacks, &blk)
71
+ end
72
+
73
+ # Prepends the given callbacks to the beginning of the chain.
74
+ #
75
+ # @param callbacks [Array] one or multiple callbacks to add
76
+ # @param block [Proc] an optional block to be added
77
+ #
78
+ # @return [void]
79
+ #
80
+ # @raise [RuntimeError] if the object was previously frozen
81
+ #
82
+ # @see #append
83
+ # @see #run
84
+ # @see Lotus::Utils::Callbacks::Callback
85
+ # @see Lotus::Utils::Callbacks::MethodCallback
86
+ # @see Lotus::Utils::Callbacks::Chain#freeze
87
+ #
88
+ # @since 0.3.4
37
89
  #
38
90
  # @example
39
91
  # require 'lotus/utils/callbacks'
@@ -42,17 +94,16 @@ module Lotus
42
94
  #
43
95
  # # Add a Proc to be used as a callback, it will be wrapped by `Callback`
44
96
  # # The optional argument(s) correspond to the one passed when invoked the chain with `run`.
45
- # chain.add { Authenticator.authenticate! }
46
- # chain.add {|params| ArticleRepository.find(params[:id]) }
97
+ # chain.prepend { Authenticator.authenticate! }
98
+ # chain.prepend { |params| ArticleRepository.find(params[:id]) }
47
99
  #
48
100
  # # Add a Symbol as a reference to a method name that will be used as a callback.
49
101
  # # It will wrapped by `MethodCallback`
50
102
  # # If the #notificate method accepts some argument(s) they should be passed when `run` is invoked.
51
- # chain.add :notificate
52
- def add(*callbacks, &blk)
53
- callbacks.push blk if block_given?
54
- callbacks.each do |c|
55
- @chain.push Factory.fabricate(c)
103
+ # chain.prepend :notificate
104
+ def prepend(*callbacks, &block)
105
+ callables(callbacks, block).each do |c|
106
+ @chain.unshift(c)
56
107
  end
57
108
 
58
109
  @chain.uniq!
@@ -128,6 +179,15 @@ module Lotus
128
179
  super
129
180
  @chain.freeze
130
181
  end
182
+
183
+
184
+ private
185
+
186
+ def callables(callbacks, block)
187
+ callbacks.push(block) if block
188
+ callbacks.map { |c| Factory.fabricate(c) }
189
+ end
190
+
131
191
  end
132
192
 
133
193
  # Callback factory
@@ -3,6 +3,6 @@ module Lotus
3
3
  # Defines the version
4
4
  #
5
5
  # @since 0.1.0
6
- VERSION = '0.3.3'.freeze
6
+ VERSION = '0.3.4'.freeze
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lotus-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-08 00:00:00.000000000 Z
12
+ date: 2015-01-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler