y_support 2.0.2 → 2.0.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: 629249c866bf65956eb005fe95e52760b1a90ca7
4
- data.tar.gz: d1fbe32ecfe7ae9c20d406370aa75a4f84b187c6
3
+ metadata.gz: a6e8e25158487612ee9fd0d9b88dd3cbaa588767
4
+ data.tar.gz: 8e4a78cde0deb07dda57cd9ff93f5f64c4a991be
5
5
  SHA512:
6
- metadata.gz: 47fcc146fb66370b5cfec8e20b7dd14c18641b5b62d35215a5a371258b65d517953db5338b75743d5d15cfcff821e6b51c747c72c250ef61b850882138e4b897
7
- data.tar.gz: 2467010f8dd198422bef47f38de23403d3446327c633fad3e7cbae55acd3576a57babd68b12b95e447b7d1fb4b233bee0623b9f4216c93ef1681c297d0c14839
6
+ metadata.gz: e9c8826eab83bf22364655f6559c5c11114162bd35dee5d01e268f971216d35e4131d5f50100faf01f7644a952a95dcd6d00edd8acb688cd671ec354e3d3d487
7
+ data.tar.gz: 0901936832de50bd38831a31deb565af1eaf8f545dec53de62ba54c8a672dfdd0e37602ed796eb6a1cfc871069c001c3bd545ee7e9f6de875c0350f99c0ee767
@@ -1,5 +1,4 @@
1
- #encoding: utf-8
2
-
1
+ # -*- coding: utf-8 -*-
3
2
  require 'y_support'
4
3
 
5
4
  # Object, whose business is to stay local to methods. Optional signature
@@ -1,26 +1,34 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'y_support'
3
3
 
4
- # A mixin imitating Ruby constant magic, plus automation of :name alias :ɴ
5
- # named argument. This allows to write:
4
+ # This mixin imitates Ruby constant magic and automates the named argument
5
+ # :name (alias :ɴ). One thus can write:
6
6
  #
7
+ # <tt>class Someclass; include NameMagic end</tt>
7
8
  # <tt>SomeName = SomeClass.new</tt>
8
9
  #
9
10
  # and the resulting object will know its #name:
10
11
  #
11
12
  # <tt>SomeName.name = "SomeName"</tt>
12
13
  #
13
- # This is done by searching the whole Ruby namespace for constants to which
14
- # the object is assigned. The search is performed by calling #const_magic.
15
- # This is only done until the name is found - once the object is named, its
16
- # subsequent assignment to constants is without effect.
14
+ # This is done by searching the whole Ruby namespace for constants, to which
15
+ # the object might have been assigned. The search is performed by the method
16
+ # #const_magic defined by this mixin. Once the object is found to be assigned
17
+ # to a constant, and named accordingly, its subsequent assignments to other
18
+ # constants have no additional effect.
17
19
  #
18
- # Alternatively, a named object can be created by using :name alias :ɴ
20
+ # Alternative way to create a named object is by specifying :name (alias :ɴ)
19
21
  # named argument:
20
22
  #
21
- # SomeName.new arg1, arg2, ..., name: "SomeName", named_arg1: val1, ...
23
+ # <tt>SomeClass.new a, b, ..., name: "SomeName", aa: v1, bb: v2 ...</tt>
22
24
  #
23
- # Hook is provided for when the name magic is performed.
25
+ # Lastly, a name can be assigned by #name= accssor, as in
26
+ #
27
+ # <tt>o = SomeClass.new</tt>
28
+ # <tt>o.name = "SomeName"</tt>
29
+ #
30
+ # Hook is provided for when the name magic is performed, as well as when the
31
+ # name is retrieved.
24
32
  #
25
33
  module NameMagic
26
34
  DEBUG = false
@@ -69,13 +77,18 @@ module NameMagic
69
77
  ɴ = self.class.__instances__[ self ]
70
78
  if ɴ then
71
79
  name_get_closure = self.class.instance_variable_get :@name_get_closure
72
- return name_get_closure ? name_get_closure.( ɴ ) : ɴ
73
- else
74
- return nil
75
- end
80
+ name_get_closure ? name_get_closure.( ɴ ) : ɴ
81
+ else nil end
76
82
  end
77
83
  alias ɴ name
78
84
 
85
+ # Retrieves either an instance name (if present), or an object id.
86
+ #
87
+ def name_or_object_id
88
+ name || object_id
89
+ end
90
+ alias ɴ_ name_or_object_id
91
+
79
92
  # Names an instance, cautiously (ie. no overwriting of existing names).
80
93
  #
81
94
  def name=( ɴ )
@@ -158,6 +171,10 @@ module NameMagic
158
171
  #
159
172
  def instance arg
160
173
  const_magic
174
+ # Reject nil argument. (In @instances hash, nameless instances are given
175
+ # name nil, so 'nil' cannot be a real name.)
176
+ fail TypeError, "'nil' is not a valid argument type for " +
177
+ "NameMagic#instance method!" if arg.nil?
161
178
  # if the argument is an actual instance, just return it
162
179
  return arg if __instances__.keys.include? arg
163
180
  # otherwise, treat it as name
@@ -1,3 +1,3 @@
1
1
  module YSupport
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: y_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - boris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-14 00:00:00.000000000 Z
11
+ date: 2013-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport