heroics 0.0.18 → 0.0.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 179b0e5aaa24933d18882a76ec0959fa652daaf0
4
- data.tar.gz: cc6aa87e66ff2668dea1564bcc618734f0b4759f
3
+ metadata.gz: 6ad986af06425a0794b57a5ed51f9ff9ff4f3c59
4
+ data.tar.gz: 355d94f757b2820464f5b65ceec411061665e378
5
5
  SHA512:
6
- metadata.gz: e9bc244a410cf64600f6dfe4bf6f7c07e23aed919586383f9a9cc30f8f543beb48c3adee94a535fe6d810fad376677a6269da86512611a2e2c35ea498e208c65
7
- data.tar.gz: 8be7d88e12c9fe28174e4d1ae9854de0f9f04631025155e6243f2ef8a6dc9c07d02b7783ecba849e359414a34431f2d491b2e6ca7fe3219102414b1199f009f4
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
- `config.headers` and `config.cache_path` are optional, but all other config shown above is required.
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, :cache_path, :module_name, :schema, :options
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
@@ -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, and
7
- # dashes and spaces converted to underscores.
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
- name.downcase.gsub(/[- ]/, '_')
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.
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Heroics
3
- VERSION = '0.0.18'
3
+ VERSION = '0.0.19'
4
4
  end
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.18
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-14 00:00:00.000000000 Z
12
+ date: 2017-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler