sleeping_king_studios-tools 0.7.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +54 -3
- data/CODE_OF_CONDUCT.md +132 -0
- data/DEVELOPMENT.md +7 -16
- data/LICENSE +1 -1
- data/README.md +71 -145
- data/lib/sleeping_king_studios/tools.rb +12 -6
- data/lib/sleeping_king_studios/tools/array_tools.rb +86 -58
- data/lib/sleeping_king_studios/tools/base.rb +20 -0
- data/lib/sleeping_king_studios/tools/core_tools.rb +78 -19
- data/lib/sleeping_king_studios/tools/hash_tools.rb +69 -42
- data/lib/sleeping_king_studios/tools/integer_tools.rb +97 -55
- data/lib/sleeping_king_studios/tools/object_tools.rb +75 -52
- data/lib/sleeping_king_studios/tools/string_tools.rb +69 -96
- data/lib/sleeping_king_studios/tools/toolbelt.rb +44 -23
- data/lib/sleeping_king_studios/tools/toolbox.rb +2 -2
- data/lib/sleeping_king_studios/tools/toolbox/constant_map.rb +75 -74
- data/lib/sleeping_king_studios/tools/toolbox/inflector.rb +124 -0
- data/lib/sleeping_king_studios/tools/toolbox/inflector/rules.rb +173 -0
- data/lib/sleeping_king_studios/tools/toolbox/mixin.rb +11 -11
- data/lib/sleeping_king_studios/tools/toolbox/semantic_version.rb +15 -14
- data/lib/sleeping_king_studios/tools/version.rb +14 -10
- metadata +106 -35
- data/lib/sleeping_king_studios/tools/all.rb +0 -5
- data/lib/sleeping_king_studios/tools/enumerable_tools.rb +0 -8
- data/lib/sleeping_king_studios/tools/semantic_version.rb +0 -15
- data/lib/sleeping_king_studios/tools/string_tools/plural_inflector.rb +0 -185
- data/lib/sleeping_king_studios/tools/toolbox/configuration.rb +0 -207
- data/lib/sleeping_king_studios/tools/toolbox/delegator.rb +0 -175
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 00a0525024c0fc1f2999486b96860169b8d8d09921d5fc289c53f2ee7960a796
|
4
|
+
data.tar.gz: '0788cece6dd1fa8ea4eb88f2bdd047f1f4804fbf610b4c4312badd1dcf7e8800'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a54d291f7f55d911b732c2be690f51e8d33931ee353ba3504ccf68c726a2398a46dd059ae3eeb9d1253619f6e704ab557af75cc4a3900c326451afb696afbcb6
|
7
|
+
data.tar.gz: 784980ce5bdb0e5266e14ac5c2e6c3747aaca88ba085a7ee1983bfdb4b625a483c8e266f688e41e6d7c4e624796661253d64d93232975c84fceb64a2d7ad3c51
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,59 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
|
3
|
+
### 1.0.2
|
4
|
+
|
5
|
+
Updated gem metadata.
|
6
|
+
|
7
|
+
### 1.0.1
|
8
|
+
|
9
|
+
Added a missing `require 'set'` to Toolbox::Inflector::Rules.
|
10
|
+
|
11
|
+
### 1.0.0
|
12
|
+
|
13
|
+
Removed all deprecated code from pre-1.0 releases.
|
14
|
+
|
15
|
+
#### Toolbox
|
16
|
+
|
17
|
+
Added some Hash-like methods to ConstantMap - `#each_key`, `#each_value`,
|
18
|
+
`#keys`, `#to_h`, and `#values`.
|
19
|
+
|
20
|
+
### 0.8.0
|
21
|
+
|
22
|
+
Last minor release before 1.0.0.
|
23
|
+
|
24
|
+
This release adds a number of deprecations. All deprecated code will be removed
|
25
|
+
in version 1.0.0. Update dependent code accordingly.
|
26
|
+
|
27
|
+
- Removed deprecated SleepingKingStudios::Tools::SemanticVersion. This
|
28
|
+
functionality is still available as
|
29
|
+
SleepingKingStudios::Tools::Toolbox::SemanticVersion.
|
30
|
+
|
31
|
+
#### Tools
|
32
|
+
|
33
|
+
- Refactored all Tools modules to classes.
|
34
|
+
- Removed StringTools::PluralInflector. It's functionality is now handled by
|
35
|
+
Toolbox::Inflector.
|
36
|
+
- Added support for deprecation strategy to CoreTools#deprecate.
|
37
|
+
|
38
|
+
#### Toolbelt
|
39
|
+
|
40
|
+
- Refactored Toolbelt to reference Tools instances rather than classes.
|
41
|
+
- Defined new abbreviated helpers #ary, #hsh, #int, #obj, #str.
|
42
|
+
- Defined new helpers #array_tools, #core_tools, #hash_tools, #integer_tools,
|
43
|
+
#object_tools, #string_tools.
|
44
|
+
- Deprecated old abbreviated helpers #array, #core, #hash, #integer, #object,
|
45
|
+
#string.
|
46
|
+
|
47
|
+
#### Toolbox
|
48
|
+
|
49
|
+
- Deprecate Toolbox::Configuration. Use a struct instead.
|
50
|
+
- Deprecate Toolbox::Delegator. Use the stdlib Forwardable module instead.
|
51
|
+
- Implement Toolbox::Inflector, which serves as a delegate for StringTools.
|
52
|
+
|
53
|
+
### 0.7.1
|
54
|
+
|
55
|
+
- Implement CoreTools#empty_binding.
|
56
|
+
- Implement HashTools#generate_binding.
|
4
57
|
|
5
58
|
### 0.7.0
|
6
59
|
|
@@ -20,8 +73,6 @@
|
|
20
73
|
- IntegerTools#pluralize now accepts 2..3 arguments, and will automatically generate the plural string using StringTools#pluralize if an explicit plural is not given.
|
21
74
|
- SleepingKingStudios::Tools::Toolbelt is now autoloaded from SleepingKingStudios::Tools.
|
22
75
|
|
23
|
-
## Previous Releases
|
24
|
-
|
25
76
|
### 0.6.0
|
26
77
|
|
27
78
|
- Implement HashTools#convert_keys_to_strings and #convert_keys_to_symbols.
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity
|
10
|
+
and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the
|
26
|
+
overall community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or
|
31
|
+
advances of any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email
|
35
|
+
address, without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official e-mail address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
merlin@sleepingkingstudios.com.
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series
|
86
|
+
of actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or
|
93
|
+
permanent ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within
|
113
|
+
the community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.0, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available
|
126
|
+
at [https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/DEVELOPMENT.md
CHANGED
@@ -1,26 +1,17 @@
|
|
1
1
|
# Development Notes
|
2
2
|
|
3
|
-
## 0.7.0
|
4
|
-
|
5
3
|
## Future Tasks
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
### Features
|
10
|
-
|
11
|
-
- HashTools::slice, ::bisect_keys
|
12
|
-
- ObjectTools::apply_with_arity
|
13
|
-
- ObjectTools::method_arity
|
14
|
-
- Delegator#delegate, :prefix => prefix_name
|
15
|
-
|
16
|
-
#### Tools
|
5
|
+
### Tools
|
17
6
|
|
7
|
+
- HashTools#bisect_keys
|
8
|
+
- HashTools#slice
|
9
|
+
- ObjectTools#apply_with_arity
|
10
|
+
- ObjectTools#method_arity
|
18
11
|
- ObjectTools#pretty - returns user-friendly string representation. :multiline option? Delegates to specific toolset implementations.
|
19
12
|
- RegexpTools#matching_string - generates a string that matches the regular expression. Does not support advanced Regexp features.
|
20
13
|
- RegexpTools#nonmatching_strings - generates a set of strings that do not match the regular expression.
|
21
|
-
- Identity Methods
|
22
|
-
- RegexpTools#regexp? - true if object is regular expression, otherwise false.
|
23
14
|
|
24
|
-
|
15
|
+
#### Identity Methods
|
25
16
|
|
26
|
-
-
|
17
|
+
- RegexpTools#regexp? - true if object is regular expression, otherwise false.
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -2,13 +2,27 @@
|
|
2
2
|
|
3
3
|
A library of utility services and concerns to expand the functionality of core classes without polluting the global namespace.
|
4
4
|
|
5
|
-
##
|
5
|
+
## About
|
6
6
|
|
7
|
-
|
7
|
+
SleepingKingStudios::Tools is tested against MRI Ruby 2.5 through 3.0.
|
8
8
|
|
9
|
-
###
|
9
|
+
### Documentation
|
10
10
|
|
11
|
-
|
11
|
+
Method and class documentation is available courtesy of RubyDoc.
|
12
|
+
|
13
|
+
Documentation is generated using [YARD](https://yardoc.org/), and can be generated locally using the `yard` gem.
|
14
|
+
|
15
|
+
### License
|
16
|
+
|
17
|
+
SleepingKingStudios::Tools is released under the [MIT License](https://opensource.org/licenses/MIT).
|
18
|
+
|
19
|
+
### Contribute
|
20
|
+
|
21
|
+
The canonical repository for this gem is on [GitHub](https://github.com/sleepingkingstudios/sleeping_king_studios-tasks). Community contributions are welcome - please feel free to fork or submit issues, bug reports or pull requests.
|
22
|
+
|
23
|
+
### Code of Conduct
|
24
|
+
|
25
|
+
Please note that the `SleepingKingStudios::Tools` project is released with a [Contributor Code of Conduct](https://github.com/sleepingkingstudios/sleeping_king_studios-tools/blob/master/CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms.
|
12
26
|
|
13
27
|
## Tools
|
14
28
|
|
@@ -187,6 +201,14 @@ Prints a deprecation warning.
|
|
187
201
|
ObjectTools#old_method was deprecated in version 0.1.0.
|
188
202
|
called from /path/to/file.rb:4: in something_or_other
|
189
203
|
|
204
|
+
#### `#empty_binding`
|
205
|
+
|
206
|
+
Generates an empty Binding object. Note that this binding object still has
|
207
|
+
access to Object methods and constants - it is **not** eval-safe.
|
208
|
+
|
209
|
+
CoreTools.empty_binding
|
210
|
+
#=> Binding
|
211
|
+
|
190
212
|
#### `#require_each`
|
191
213
|
|
192
214
|
Takes a file pattern or a list of file names and requires each file.
|
@@ -262,6 +284,22 @@ Freezes the hash and performs a deep freeze on each hash key and value.
|
|
262
284
|
hsh[:one].frozen?
|
263
285
|
#=> true
|
264
286
|
|
287
|
+
#### `#generate_binding`
|
288
|
+
|
289
|
+
Generates a Binding object, with the hash converted to local variables in the
|
290
|
+
binding.
|
291
|
+
|
292
|
+
hsh = { :one => 'one', :two => 'two', :three => 'three' }
|
293
|
+
binding = HashTools.generate_binding(hsh)
|
294
|
+
#=> Binding
|
295
|
+
|
296
|
+
binding.local_variable_defined?(:one)
|
297
|
+
#=> true
|
298
|
+
binding.local_variable_get(:one)
|
299
|
+
#=> 'one'
|
300
|
+
binding.eval('one')
|
301
|
+
#=> 'one'
|
302
|
+
|
265
303
|
#### `#hash?`
|
266
304
|
|
267
305
|
Returns true if the object is or appears to be a Hash.
|
@@ -394,19 +432,19 @@ Creates a deep copy of the object. If the object is an Array, returns a new Arra
|
|
394
432
|
:name => 'Welcome to the Jungle',
|
395
433
|
:artist => "Guns N' Roses",
|
396
434
|
:album => 'Appetite for Destruction'
|
397
|
-
},
|
435
|
+
},
|
398
436
|
{
|
399
437
|
:name => 'Hells Bells',
|
400
438
|
:artist => 'AC/DC',
|
401
439
|
:album => 'Back in Black'
|
402
|
-
},
|
440
|
+
},
|
403
441
|
{
|
404
442
|
:name => "Knockin' on Heaven's Door",
|
405
443
|
:artist => 'Bob Dylan',
|
406
444
|
:album => 'Pat Garrett & Billy The Kid'
|
407
|
-
}
|
408
|
-
]
|
409
|
-
}
|
445
|
+
}
|
446
|
+
]
|
447
|
+
}
|
410
448
|
|
411
449
|
copy = ObjectTools.deep_dup data
|
412
450
|
|
@@ -428,19 +466,19 @@ Performs a deep freeze of the object. If the object is an Array, freezes the arr
|
|
428
466
|
:name => 'Welcome to the Jungle',
|
429
467
|
:artist => "Guns N' Roses",
|
430
468
|
:album => 'Appetite for Destruction'
|
431
|
-
},
|
469
|
+
},
|
432
470
|
{
|
433
471
|
:name => 'Hells Bells',
|
434
472
|
:artist => 'AC/DC',
|
435
473
|
:album => 'Back in Black'
|
436
|
-
},
|
474
|
+
},
|
437
475
|
{
|
438
476
|
:name => "Knockin' on Heaven's Door",
|
439
477
|
:artist => 'Bob Dylan',
|
440
478
|
:album => 'Pat Garrett & Billy The Kid'
|
441
|
-
}
|
442
|
-
]
|
443
|
-
}
|
479
|
+
}
|
480
|
+
]
|
481
|
+
}
|
444
482
|
ObjectTools.deep_freeze(data)
|
445
483
|
|
446
484
|
data.frozen?
|
@@ -553,7 +591,7 @@ Adds the specified number of spaces to the start of each line of the string. Def
|
|
553
591
|
"The Fellowship of the Ring",
|
554
592
|
"The Two Towers",
|
555
593
|
"The Return of the King"
|
556
|
-
]
|
594
|
+
]
|
557
595
|
string = titles.join "\n"
|
558
596
|
StringTools.indent(string, 4)
|
559
597
|
#=> " The Fellowship of the Ring\n"\
|
@@ -572,7 +610,7 @@ Yields each line of the string to the provided block and combines the results in
|
|
572
610
|
"The Fellowship of the Ring",
|
573
611
|
"The Two Towers",
|
574
612
|
"The Return of the King"
|
575
|
-
]
|
613
|
+
]
|
576
614
|
string = titles.join "\n"
|
577
615
|
StringTools.map_lines(string) { |line, index| "#{index}. #{line}" }
|
578
616
|
#=> "0. The Fellowship of the Ring\n"\
|
@@ -667,73 +705,6 @@ Converts a mixed-case string expression to a lowercase, underscore separated str
|
|
667
705
|
|
668
706
|
Common objects or patterns that are useful across projects but are larger than or do not fit the functional paradigm of the tools.* pattern.
|
669
707
|
|
670
|
-
### Configuration
|
671
|
-
|
672
|
-
require 'sleeping_king_studios/tools/toolbox/configuration'
|
673
|
-
|
674
|
-
Provides a simple DSL for defining configuration objects, which can be populated via hashes or data objects (such as a Rails configuration object).
|
675
|
-
|
676
|
-
class MyGemConfig < SleepingKingStudios::Tools::Toolbox::Configuration
|
677
|
-
option :template_dir
|
678
|
-
|
679
|
-
namespace :serialization do
|
680
|
-
option :format, :default => :json, :enum => [:json, :xml, :yaml]
|
681
|
-
end # namespace
|
682
|
-
end # class
|
683
|
-
|
684
|
-
# Initialize with a hash.
|
685
|
-
hsh = YAML.load(File.read 'path/to/config.yml')
|
686
|
-
config = MyGemConfig.new(hsh)
|
687
|
-
|
688
|
-
# Initialize with a data object.
|
689
|
-
klass = Struct.new(:template_dir)
|
690
|
-
data = klass.new('path/to/templates')
|
691
|
-
config = MyGemConfig.new(data)
|
692
|
-
|
693
|
-
# Retrieve data by calling methods or using hash syntax. All of the
|
694
|
-
# following will return the configured value:
|
695
|
-
config.serialization.format
|
696
|
-
config[:serialization][:format]
|
697
|
-
config['serialization']['format']
|
698
|
-
config.dig(:serialization, :format)
|
699
|
-
config.fetch(:serialization', {}).fetch(:format, :json)
|
700
|
-
|
701
|
-
#### `::namespace`
|
702
|
-
|
703
|
-
Defines an inner namespace for the configuration, which will itself be an instance of Configuration. Can be nested to any depth:
|
704
|
-
|
705
|
-
class MyGemConfig < SleepingKingStudios::Tools::Toolbox::Configuration
|
706
|
-
namespace :weapons do
|
707
|
-
namespace :swords do
|
708
|
-
namespace :upgrades do
|
709
|
-
option :hilts
|
710
|
-
|
711
|
-
option :tangs
|
712
|
-
end # namespace
|
713
|
-
end # namespace
|
714
|
-
end # namespace
|
715
|
-
end # class
|
716
|
-
|
717
|
-
config.weapons.swords.upgrades
|
718
|
-
#=> a Configuration instance, with options #hilts and #tangs.
|
719
|
-
|
720
|
-
#### `::option`
|
721
|
-
|
722
|
-
Defines an option, which creates an accessor and mutator method for the property. Can configure a :default (can be a value, a Proc, or the name of a
|
723
|
-
method) and/or allowable values via the :enum option.
|
724
|
-
|
725
|
-
class MyGemConfig < SleepingKingStudios::Tools::Toolbox::Configuration
|
726
|
-
option :max_level, :default => 20
|
727
|
-
|
728
|
-
option :class, :enum => %(warrior ranger elementalist monk)
|
729
|
-
end # class
|
730
|
-
|
731
|
-
config.max_level
|
732
|
-
# Returns 20 if no configured value is set.
|
733
|
-
|
734
|
-
config.class = 'necromancer'
|
735
|
-
# Raises an error.
|
736
|
-
|
737
708
|
### ConstantMap
|
738
709
|
|
739
710
|
require 'sleeping_king_studios/tools/toolbox/constant_map'
|
@@ -741,10 +712,12 @@ method) and/or allowable values via the :enum option.
|
|
741
712
|
Provides an enumerable interface for defining a group of constants.
|
742
713
|
|
743
714
|
UserRoles = ConstantMap.new(
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
715
|
+
{
|
716
|
+
GUEST: 'guest',
|
717
|
+
USER: 'user',
|
718
|
+
ADMIN: 'admin'
|
719
|
+
}'
|
720
|
+
)
|
748
721
|
|
749
722
|
UserRoles::GUEST
|
750
723
|
#=> 'guest'
|
@@ -755,74 +728,27 @@ Provides an enumerable interface for defining a group of constants.
|
|
755
728
|
UserRoles.all
|
756
729
|
#=> { :GUEST => 'guest', :USER => 'user', :ADMIN => 'admin' }
|
757
730
|
|
758
|
-
|
759
|
-
|
760
|
-
require 'sleeping_king_studios/tools/toolbox/delegator'
|
731
|
+
ConstantMap includes `Enumerable`, with `#each` yielding the name and value of each defined constant. It also defines the following additional methods:
|
761
732
|
|
762
|
-
|
763
|
-
|
764
|
-
class MyClass
|
765
|
-
extend SleepingKingStudios::Tools::Toolbox::Delegator
|
766
|
-
|
767
|
-
delegate :my_method, :to => MyService
|
768
|
-
end # class
|
733
|
+
#### `#each_key`
|
769
734
|
|
770
|
-
|
735
|
+
Yields each defined constant name, similar to `Hash#each_key`.
|
771
736
|
|
772
|
-
|
737
|
+
#### `#each_value`
|
773
738
|
|
774
|
-
|
775
|
-
class MyModule
|
776
|
-
extend SleepingKingStudios::Tools::Toolbox::Delegator
|
739
|
+
Yields each defined constant value, similar to `Hash#each_value`.
|
777
740
|
|
778
|
-
|
779
|
-
end class
|
741
|
+
#### `#keys`
|
780
742
|
|
781
|
-
|
782
|
-
class MyModule
|
783
|
-
extend SleepingKingStudios::Tools::Toolbox::Delegator
|
743
|
+
Returns an array containing the names of the defined constants, similar to `Hash#keys`.
|
784
744
|
|
785
|
-
|
786
|
-
MyService.new
|
787
|
-
end method my_service
|
745
|
+
#### `#to_h`
|
788
746
|
|
789
|
-
|
790
|
-
end class
|
791
|
-
|
792
|
-
# Delegate to an instance variable
|
793
|
-
class MyModule
|
794
|
-
extend SleepingKingStudios::Tools::Toolbox::Delegator
|
795
|
-
|
796
|
-
def initialize
|
797
|
-
@my_service = MyService.new
|
798
|
-
end constructor
|
799
|
-
|
800
|
-
delegate :my_method, :to => :@my_service
|
801
|
-
end class
|
802
|
-
|
803
|
-
Expects one or more method names and a delegation target, which can be an object literal, or the name of an method or instance variable as a String or Symbol. Defines a wrapper method to delegate implementation of the specified method or methods to an object, to the object at the another specified method, or to the object at the specified instance variable.
|
804
|
-
|
805
|
-
#### `::wrap_delegate`
|
806
|
-
|
807
|
-
Wraps a delegate object by automatically delegating each method that is defined on the delegate class from the instance to the delegate. The delegate can be specified with an object literal or with the name of an instance method or instance variable.
|
808
|
-
|
809
|
-
Only methods that are defined at the time #wrap_delegate is called will be delegated, so make sure to call #wrap_delegate after loading any gems or libraries that extend your delegate class, such as ActiveSupport.
|
810
|
-
|
811
|
-
# Create a class that wraps a Hash
|
812
|
-
class Errors
|
813
|
-
extend SleepingKingStudios::Tools::Toolbox::Delegator
|
814
|
-
|
815
|
-
wrap_delegate Hash.new { |hsh, key| hsh[key] = Errors.new }, :klass => Hash
|
816
|
-
|
817
|
-
def messages
|
818
|
-
@messages ||= []
|
819
|
-
end # method messages
|
820
|
-
end # class
|
747
|
+
Also `#all`. Returns a Hash representation of the constants.
|
821
748
|
|
822
|
-
|
823
|
-
errors[:post].messages << "title can't be blank"
|
749
|
+
#### `#values`
|
824
750
|
|
825
|
-
|
751
|
+
Returns an array containing the values of the defined constants, similar to `Hash#values`.
|
826
752
|
|
827
753
|
### Mixin
|
828
754
|
|