valuable 0.9.7 → 0.9.8

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.
Files changed (3) hide show
  1. data/README.markdown +41 -1
  2. data/valuable.version +1 -1
  3. metadata +1 -1
data/README.markdown CHANGED
@@ -24,8 +24,10 @@ Contents
24
24
  - [Aliases](#aliases)
25
25
  - [Formatting Input](#formatting-input)
26
26
  - [Pre-Defined Formatters](#pre-defined-formatters)
27
+ - [Extending Values](#extending-values)
27
28
  - [Collections](#collections)
28
29
  - [Formatting Collections](#formatting-collections)
30
+ - [Extending Collections](#extending-collections)
29
31
  - [Registering Formatters](#registering-formatters)
30
32
  - [More about Attributes](#more-about-attributes)
31
33
  - [Advanced Input Parsing](#advanced-input-parsing)
@@ -102,6 +104,7 @@ like has_value, this creates a getter and setter. The default value is an array.
102
104
  options:
103
105
  + **klass** - apply pre-defined or custom formatters to each element of the array.
104
106
  + **alias** - create additional getters and setters under this name.
107
+ + **extend** - extend the collection with the provided module or modules.
105
108
 
106
109
  class Person
107
110
  has_collection :friends
@@ -362,6 +365,23 @@ see also [Registering Formatters](#registering-formatters)
362
365
  when this is not the correct behavior. )
363
366
  - or any class ( formats as SomeClass.new( ) unless value.is_a?( SomeClass ) )
364
367
 
368
+ Extending Values
369
+ ----------------
370
+
371
+ As with has_value, you can do something like:
372
+
373
+ module PirateTranslator
374
+ def to_pirate
375
+ "#{self} AAARRRRRGgghhhh!"
376
+ end
377
+ end
378
+
379
+ class Envelope < Valuable
380
+ has_value :message, :extend => PirateTranslator
381
+ end
382
+
383
+ >> Envelope.new(:message => 'contrived').message.to_pirate
384
+ => "contrived AAARRRRRGgghhhh!"
365
385
 
366
386
  Collections
367
387
  -----------
@@ -372,7 +392,9 @@ is similar to:
372
392
 
373
393
  has_value :codez, :default => []
374
394
 
375
- except that it reads better, and that the formatter is applied to the collection's members, not (obviously) the collection. See [Formatting Collections](#formatting-collections) for more details.
395
+ except
396
+ * it reads better
397
+ * that the formatter is applied to the collection's members, not (obviously) the collection. See [Formatting Collections](#formatting-collections) for more details.
376
398
 
377
399
  class MailingList < Valuable
378
400
  has_collection :emails
@@ -401,6 +423,24 @@ If a klass is specified, members of the collection will be formatted appropriate
401
423
 
402
424
  see [Advanced Collection Formatting](#advanced-collection-formatting) for more complex examples.
403
425
 
426
+ Extending Collections
427
+ ---------------------
428
+
429
+ As with has_value, you can do something like:
430
+
431
+ module PirateTranslator
432
+ def to_pirate
433
+ "#{self} AAARRRRRGgghhhh!"
434
+ end
435
+ end
436
+
437
+ class Envelope < Valuable
438
+ has_value :message, :extend => PirateTranslator
439
+ end
440
+
441
+ >> Envelope.new(:message => 'contrived').message.to_pirate
442
+ => "contrived AAARRRRRGgghhhh!"
443
+
404
444
  Registering Formatters
405
445
  ----------------------
406
446
 
data/valuable.version CHANGED
@@ -1 +1 @@
1
- 0.9.7
1
+ 0.9.8
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valuable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: