enum_args 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0acfec4f4348a5b9566c217395fd29a0add7e24
4
- data.tar.gz: 26cb7afa178ce703ffebb394f29621ae52237021
3
+ metadata.gz: 68df5fb718558589a21017b5855a79dbf5ac7a7d
4
+ data.tar.gz: eca79a772cb5d8e2acd15e3043d10bb3329ac371
5
5
  SHA512:
6
- metadata.gz: 4d2c196467fc821139d64dcb2a9936d3fcd1b036e6e875c16f8bed0db5f76959dab910c63b123a762bd8cef55d5248673d12b87930ed325d89c139d9bdc37cef
7
- data.tar.gz: ee3b7bc71bf6a64e12d7c7491c48878fe4ec5fa9d25774ac95acc2797c11463c6377a1990f6ca8f820a280c0e9d42904ccd83de3d1f259c37cf49d89c0fb4937
6
+ metadata.gz: ed587f106c77f0c9d4d1c05ded01163f8ab4f460d970c3cf2e32d112d1d78d0fddb8909b504927ca1e9f74be09316efeb55cb0b7fd856a413f3f66b02b577cf5
7
+ data.tar.gz: f2169665ffff932f9b15d0361b394f8298208568feb35fb0b6d97b4dc1670ebeaedfe3216b539ab1d6c299be0518ac2759c73b97be6adc9324895914b1dd84fc
data/LICENSE.txt CHANGED
@@ -1,6 +1,7 @@
1
1
  The MIT License (MIT)
2
2
 
3
3
  Copyright (c) 2015 Alejandro Martinez Ruiz <alex at flawedcode . org>
4
+ Copyright (c) 2015 3scale, Inc.
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,24 +1,51 @@
1
- [![Gem Version](https://badge.fury.io/rb/enum_args.svg)](http://badge.fury.io/rb/enum_args) [![Build Status](https://travis-ci.org/unleashed/enum_args.svg?branch=master)](https://travis-ci.org/unleashed/enum_args) [![Code Climate](https://codeclimate.com/github/unleashed/enum_args/badges/gpa.svg)](https://codeclimate.com/github/unleashed/enum_args) [![Test Coverage](https://codeclimate.com/github/unleashed/enum_args/badges/coverage.svg)](https://codeclimate.com/github/unleashed/enum_args)
1
+ [![Gem Version](https://badge.fury.io/rb/enum_args.svg)](http://badge.fury.io/rb/enum_args) [![Build Status](https://travis-ci.org/unleashed/enum_args.svg?branch=master)](https://travis-ci.org/unleashed/enum_args) [![Code Climate](https://codeclimate.com/github/unleashed/enum_args/badges/gpa.svg)](https://codeclimate.com/github/unleashed/enum_args) [![Test Coverage](https://codeclimate.com/github/unleashed/enum_args/badges/coverage.svg)](https://codeclimate.com/github/unleashed/enum_args) [![Dependencies](https://img.shields.io/gemnasium/unleashed/enum_args.svg?style=flat)](https://gemnasium.com/unleashed/enum_args) [![License](http://img.shields.io/:license-MIT-blue.svg?style=flat)](LICENSE.txt)
2
2
 
3
3
  # EnumArgs
4
4
 
5
- EnumArgs is a simple gem that enables your enumerators to receive parameters
6
- from any of the methods provided by Enumerable in a uniform fashion, so that you
5
+ EnumArgs is a gem that enables your enumerators to receive parameters from any
6
+ of of the methods provided by Enumerable in a uniform fashion, so that you
7
7
  could, ie. `ai_team.select(max_cpu: 80) { |troop| troop.can_hit?(enemy) }.each
8
8
  { ... }`.
9
9
 
10
- See Usage for some examples.
10
+ ## Basic Usage
11
+
12
+ You just need to include EnumArgs to your class and call `enum_args_for`.
13
+
14
+ ```ruby
15
+ class MyEnum
16
+ include EnumArgs
17
+
18
+ enum_args_for :my_iterator, 3, 'fixed', 'params', using: { dynamic: :params }
19
+
20
+ def my_iterator(how_many, string1, string2, dynamic:)
21
+ # do something with all params, including dynamic ones
22
+ # which are always keyword parameters
23
+ yield element1
24
+ yield element2
25
+ # [...]
26
+ end
27
+ end
28
+ ```
29
+
30
+ **N.B**: You *should avoid* using `each` as the method name for your iterator. Doing
31
+ so will prevent your iterator from consistently getting the correct parameters.
32
+
33
+ See Usage for additional information.
11
34
 
12
35
  ### Namespace pollution
13
36
 
14
- A common issue with this sort of gems is namespace pollution. EnumArgs is wise
15
- enough to pollute your namespace with the bare minimum needed.
37
+ A common issue with this sort of gems is namespace pollution. EnumArgs works
38
+ hard to use just the bare minimum needed methods.
16
39
 
17
- All of this is done by adding, apart from the Enumerable instance methods, _one_
40
+ EnumArgs adds all the Enumerable instance methods and a corresponding `each`
41
+ method, which is what we need for a collection, and other than that, just _one_
18
42
  single accessor (instance) method to your class and _one_ single instance variable
19
- with configurable name (default is `enum_args`). A few _class_ methods are added
20
- to hold default values for your enumerator, all of them prefixed with
21
- `enum_args_`.
43
+ with configurable name (default is `enum_args`). You can specify what that name
44
+ should look like by specifying the `with_enum_args_as: :method_name` option to
45
+ `enum_args_for`.
46
+
47
+ A few _class_ methods are added as well to hold default values for your
48
+ enumerator, all of them prefixed with `enum_args_`.
22
49
 
23
50
  ## Installation
24
51
 
@@ -193,4 +220,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/unleas
193
220
  ## License
194
221
 
195
222
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
196
-
223
+ See [LICENSE.txt](LICENSE.txt) for details.
@@ -12,13 +12,13 @@ module EnumArgs
12
12
  @args
13
13
  end
14
14
 
15
- # :nocov:
16
- def using=(using)
17
- @using = using
18
- self.args = args
19
- @using
20
- end
21
- # :nocov:
15
+ # Currently unused setter
16
+ #
17
+ # def using=(using)
18
+ # @using = using
19
+ # self.args = args
20
+ # @using
21
+ # end
22
22
 
23
23
  def initialize(object, method_name, *fixed_args, using: {})
24
24
  @object = object
@@ -40,7 +40,9 @@ module EnumArgs
40
40
  def rewind
41
41
  self.fiber = Fiber.new do
42
42
  object.send method_name, *args do |*yielded_values|
43
+ # :nocov:
43
44
  Fiber.yield(*yielded_values)
45
+ # :nocov:
44
46
  end
45
47
  raise StopIteration
46
48
  end
@@ -1,7 +1,7 @@
1
1
  module EnumArgs
2
2
  class Proxy
3
- ProxiedEnumerable.on_enumerable_methods self do |*args, &blk|
4
- enum_delegate __method__, *args, &blk
3
+ ProxiedEnumerable.on_enumerable_methods self do |*args, **options, &blk|
4
+ enum_delegate __method__, args, options, blk
5
5
  end
6
6
 
7
7
  def self.attr_writer_resetting_enum(*writers)
@@ -30,7 +30,7 @@ module EnumArgs
30
30
 
31
31
  attr_writer :enum
32
32
 
33
- def enum_delegate(m, *m_args, **options, &blk)
33
+ def enum_delegate(m, m_args, options, blk)
34
34
  # remove specific 'using' options from method call
35
35
  iterator_params = extract_iterator_params_from options
36
36
 
@@ -58,7 +58,7 @@ module EnumArgs
58
58
  end
59
59
 
60
60
  def build_enum(merge = {})
61
- Enumerator.new(object, method_name, *args, using: self.using.merge(merge))
61
+ Enumerator.new(object, method_name, *args, using: self.using.merge(merge))
62
62
  end
63
63
  end
64
64
  end
@@ -1,3 +1,3 @@
1
1
  module EnumArgs
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enum_args
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alejandro Martinez Ruiz