heroics 0.0.18 → 0.0.19
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 +8 -1
- data/lib/heroics/configuration.rb +17 -1
- data/lib/heroics/naming.rb +12 -3
- data/lib/heroics/version.rb +1 -1
- 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: 6ad986af06425a0794b57a5ed51f9ff9ff4f3c59
|
4
|
+
data.tar.gz: 355d94f757b2820464f5b65ceec411061665e378
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4ae1365bdacbde7816d0cb5091c0c25c4ca803da9709a55b77f5313b54e18c59cc0b8b619e6fc17832dcd473ffe729a906b71f94d2bfd62159cb41c5c1fe69d
|
7
|
+
data.tar.gz: 82b7611b2e33cca630ab2d2b39d996cc4a8c942e0195a0cf850258028e848b740c3eb98a4020dcec35248a556c870e27cbe817227eace57bde65a047b1b0f4ba
|
data/README.md
CHANGED
@@ -40,7 +40,14 @@ end
|
|
40
40
|
|
41
41
|
#### Optional configuration
|
42
42
|
|
43
|
-
`
|
43
|
+
`base_url`, `module_name`, and `schema_filepath` are required for a proper configuration.
|
44
|
+
|
45
|
+
The following keys are optional:
|
46
|
+
|
47
|
+
* `headers`
|
48
|
+
* `cache_path`
|
49
|
+
* `ruby_name_replacements` a hash of replacement patterns for converting endpoint paths to Ruby method names, such as:
|
50
|
+
> { /[\s-]+/ => '_' }
|
44
51
|
|
45
52
|
For further details on config file usage, see the `example/` directory in this repo.
|
46
53
|
|
@@ -3,17 +3,28 @@
|
|
3
3
|
module Heroics
|
4
4
|
# Attempts to load configuration, provides defaults, and provide helpers to access that data
|
5
5
|
class Configuration
|
6
|
-
attr_reader :base_url,
|
6
|
+
attr_reader :base_url,
|
7
|
+
:cache_path,
|
8
|
+
:module_name,
|
9
|
+
:schema,
|
10
|
+
:ruby_name_replacement_patterns,
|
11
|
+
:options
|
7
12
|
|
8
13
|
def self.defaults
|
9
14
|
@defaults ||= Configuration.new
|
10
15
|
end
|
11
16
|
|
17
|
+
def self.restore_defaults
|
18
|
+
@defaults = Configuration.new
|
19
|
+
end
|
20
|
+
|
12
21
|
def initialize
|
13
22
|
@options = {}
|
14
23
|
@options[:cache] = 'Moneta.new(:Memory)'
|
15
24
|
@options[:default_headers] = {}
|
16
25
|
|
26
|
+
@ruby_name_replacement_patterns = { /[\s-]+/ => '_' }
|
27
|
+
|
17
28
|
yield self if block_given?
|
18
29
|
end
|
19
30
|
|
@@ -41,5 +52,10 @@ module Heroics
|
|
41
52
|
raise "Must provide a hash of headers" unless headers.is_a?(Hash)
|
42
53
|
@options[:default_headers] = headers
|
43
54
|
end
|
55
|
+
|
56
|
+
def ruby_name_replacement_patterns=(patterns)
|
57
|
+
raise "Must provide a hash of replacements" unless patterns.is_a?(Hash)
|
58
|
+
@ruby_name_replacement_patterns = patterns
|
59
|
+
end
|
44
60
|
end
|
45
61
|
end
|
data/lib/heroics/naming.rb
CHANGED
@@ -3,10 +3,19 @@ module Heroics
|
|
3
3
|
# Process a name to make it suitable for use as a Ruby method name.
|
4
4
|
#
|
5
5
|
# @param name [String] The name to process.
|
6
|
-
# @return [String] The new name with capitals converted to lowercase,
|
7
|
-
#
|
6
|
+
# @return [String] The new name with capitals converted to lowercase,
|
7
|
+
# and characters replaced or removed based on the
|
8
|
+
# Configuration.ruby_names_replacement_patterns rules
|
9
|
+
# @raise [SchemaError] Raised if the name contains invalid characters.
|
8
10
|
def self.ruby_name(name)
|
9
|
-
|
11
|
+
patterns = Heroics::Configuration.defaults.ruby_name_replacement_patterns
|
12
|
+
|
13
|
+
ruby_name = patterns.reduce(name.downcase) do |memo, (regex, replacement)|
|
14
|
+
memo.gsub(regex, replacement)
|
15
|
+
end
|
16
|
+
|
17
|
+
raise SchemaError.new("Name '#{name}' converts to invalid Ruby name '#{ruby_name}'.") if ruby_name =~ /\W/
|
18
|
+
ruby_name
|
10
19
|
end
|
11
20
|
|
12
21
|
# Process a name to make it suitable for use as a pretty command name.
|
data/lib/heroics/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heroics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- geemus
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-02-
|
12
|
+
date: 2017-02-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|