betterobject 1.1.0 → 1.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.
- checksums.yaml +4 -4
- data/README.md +35 -1
- data/lib/betterobject.rb +1 -10
- data/lib/betterobject/version.rb +1 -1
- data/lib/generators.rb +54 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e64300a8b23a073a27bb1cd2cd3856764339c2b
|
4
|
+
data.tar.gz: 555bf34df4bd8cadaabe5a4ca15e412f8acbfa13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23e5d3d8f0957161b629e489ff6195e0efb48a0c6ac71413eb6f363df0bd3b6b90293488bb512865d6d241f8bd50c0aa39309cf5345e4b8bb566dc6e9ab182d6
|
7
|
+
data.tar.gz: f9e7501bfcba7cfe9470c341e0ee1e10117fa857cf60e0d3f2018309d8cc2923520edd0bb23bb0a23d4cb1e87cb3f2a32695eb51e0408c9b6725749bdebd3765
|
data/README.md
CHANGED
@@ -315,6 +315,7 @@ you must provide code to remove your methods.
|
|
315
315
|
* `:define_presence_of`
|
316
316
|
* `:in?`
|
317
317
|
* `:include_many?`
|
318
|
+
* `:include_any?`
|
318
319
|
* `:to_literal`
|
319
320
|
* `:pluralize`
|
320
321
|
* `:parent`
|
@@ -327,6 +328,8 @@ you must provide code to remove your methods.
|
|
327
328
|
* `:many_at`
|
328
329
|
* `:delete_many_at`
|
329
330
|
* `:tripleize`
|
331
|
+
* `:dup_safe`
|
332
|
+
* `:cvar`
|
330
333
|
|
331
334
|
|
332
335
|
|
@@ -724,16 +727,47 @@ Object.better_install :include_many?
|
|
724
727
|
[1,2,3,[4,5],[6,7],8].include_many? [4,5],[6,7],1 # false ... same as: .include_many? 4,5 ... see note below:
|
725
728
|
[1,2,3,[4,5],[6,7],8].include_many? 1,[4,5],[6,7] # true ... see note below:
|
726
729
|
"This is a test string".include_many? "test", "string" # true
|
727
|
-
```
|
730
|
+
```
|
728
731
|
|
729
732
|
Note that it is best to encapsulate the list inside an array, particularly if your elements are arrays.
|
730
733
|
If the first item in the list is an array, then its contents will be the only thing tested.
|
731
734
|
|
735
|
+
### Generators :include_any?
|
736
|
+
|
737
|
+
This works just like `:include:many?` except instead of all items needing to be included, any item included will return true.
|
738
|
+
|
739
|
+
### Generators :dup_safe
|
740
|
+
|
741
|
+
It is interesting to note that you can't duplicate an Integer instance. Calling `#dup` will raise an exception.
|
742
|
+
In the event that an instance cannot be duplicated, `self` is instead returned.
|
743
|
+
|
744
|
+
### Generators :cvar
|
745
|
+
|
746
|
+
Class variables (not the `@@name` ilk) can be tricky to access from an instance.
|
747
|
+
This method creates and accesses class variables on the class or the instance of that class.
|
748
|
+
See the example below:
|
749
|
+
|
750
|
+
```ruby
|
751
|
+
Object.better_install :cvar
|
752
|
+
|
753
|
+
7.cvar!(:fred,"yaba daba doo!")
|
754
|
+
2.cvar :fred # returns "yaba daba doo!"
|
755
|
+
9.class.cvar :fred # returns "yaba daba doo!"
|
756
|
+
55.class.cvar!(:fred,"Wilma?")
|
757
|
+
100.cvar :fred # returns "Wilma?"
|
758
|
+
```
|
732
759
|
|
733
760
|
## Change Log
|
734
761
|
|
762
|
+
### Version 1.2.0
|
763
|
+
1. Changed `:better_install_as!` to class method
|
764
|
+
2. Added generator `:cvar`
|
765
|
+
3. Added generator `:include_any?`
|
766
|
+
4. Added generator `:dup_safe`
|
767
|
+
|
735
768
|
### Version 1.1.0
|
736
769
|
1. Update documentation
|
770
|
+
2. Added method `:better_install_as!`
|
737
771
|
2. Added generator `:delete_many_at`
|
738
772
|
3. Added generator `:many_at`
|
739
773
|
4. Added generator `:tripleize`
|
data/lib/betterobject.rb
CHANGED
@@ -1,15 +1,6 @@
|
|
1
1
|
require "betterobject/version"
|
2
2
|
require "generators.rb"
|
3
3
|
|
4
|
-
### ::TODO:: :required ... prevent uninstall forever
|
5
|
-
### ::: Array ... needs a delete_many_at(*prm) ... 1,5,7,3 or an array setfu need this!!!
|
6
|
-
### ::: also, a delete_many(*prm) ... deletes a bunch of stuff based on value
|
7
|
-
### ::: Generator clone ??? another way to tag things .... or provide alternate names
|
8
|
-
### ::: Generator drop ??? removes generator completely
|
9
|
-
### ::: drop after permanent install? nah ... not sure if I want drop either
|
10
|
-
### ::: Object.better_install! :generator ... cannot be uninstalled **** I like this!!!
|
11
|
-
|
12
|
-
|
13
4
|
class Object
|
14
5
|
###
|
15
6
|
### The following are standard class methods
|
@@ -245,7 +236,7 @@ class Object
|
|
245
236
|
true
|
246
237
|
end
|
247
238
|
|
248
|
-
def better_install_as!(old_sym, new_sym)
|
239
|
+
def self.better_install_as!(old_sym, new_sym)
|
249
240
|
better_be_object
|
250
241
|
better_be_defined(old_sym)
|
251
242
|
better_be_different(old_sym, new_sym)
|
data/lib/betterobject/version.rb
CHANGED
data/lib/generators.rb
CHANGED
@@ -494,4 +494,58 @@ CODE
|
|
494
494
|
@@better_object_valid_methods[:include_many?] = hash
|
495
495
|
|
496
496
|
|
497
|
+
#
|
498
|
+
# Generator include_any?
|
499
|
+
#
|
500
|
+
hash = {}
|
501
|
+
hash[:type] = :instance
|
502
|
+
hash[:explain] = "calls include? to check for multiple items"
|
503
|
+
hash[:code] = <<'CODE'
|
504
|
+
def BO_METH_NAME(*items)
|
505
|
+
items = items.first if items.first.kind_of? Array
|
506
|
+
items.each do |item|
|
507
|
+
return true if self.include? item
|
508
|
+
end
|
509
|
+
false
|
510
|
+
end
|
511
|
+
CODE
|
512
|
+
@@better_object_valid_methods[:include_any?] = hash
|
513
|
+
|
514
|
+
|
515
|
+
#
|
516
|
+
# Generator cvar
|
517
|
+
#
|
518
|
+
hash = {}
|
519
|
+
hash[:type] = :both
|
520
|
+
hash[:explain] = "cvar reads and writes class variables from instance or class"
|
521
|
+
hash[:code] = <<'CODE'
|
522
|
+
def BO_METH_NAME(sym)
|
523
|
+
self.class.instance_variable_get("@#{sym}".to_sym)
|
524
|
+
end
|
525
|
+
def BO_METH_NAME!(sym,dat)
|
526
|
+
self.class.instance_variable_set("@#{sym}".to_sym,dat)
|
527
|
+
end
|
528
|
+
def self.BO_METH_NAME(sym)
|
529
|
+
instance_variable_get("@#{sym}".to_sym)
|
530
|
+
end
|
531
|
+
def self.BO_METH_NAME!(sym,dat)
|
532
|
+
instance_variable_set("@#{sym}".to_sym,dat)
|
533
|
+
end
|
534
|
+
CODE
|
535
|
+
@@better_object_valid_methods[:cvar] = hash
|
536
|
+
|
537
|
+
|
538
|
+
#
|
539
|
+
# Generator dup_safe
|
540
|
+
#
|
541
|
+
hash = {}
|
542
|
+
hash[:type] = :instance
|
543
|
+
hash[:explain] = "dup if possible else self"
|
544
|
+
hash[:code] = <<'CODE'
|
545
|
+
def BO_METH_NAME
|
546
|
+
dup rescue self
|
547
|
+
end
|
548
|
+
CODE
|
549
|
+
@@better_object_valid_methods[:dup_safe] = hash
|
550
|
+
|
497
551
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: betterobject
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Colvin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|