drawers 1.0.1 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6501ca69ca387b5fcdadca2cefc421dd6ce4218b
4
- data.tar.gz: eb848da7400a579adee113d08ce014d653e8c28b
3
+ metadata.gz: f4c6856bb136262cc033ca63ed44d3c77ceb1523
4
+ data.tar.gz: d25727def6ac5c084d714dafc5c78d1eef7819b6
5
5
  SHA512:
6
- metadata.gz: 634e42977c1b7ebb23b47a092f594e89880622b8e8112e5ef3fa35384d916b9ce990c15c71301c4b94ab047dae29495238ae1f37c13ad413d057a941ea051441
7
- data.tar.gz: 93a4fe1015c817bf47d4759c8f2dfdd119d84353091de35e288d5aa4d263666ce6e0bb782da7563f56db8f577d40503b2b5ebbeca720559e4784c1361b3c53e1
6
+ metadata.gz: 6a0a280c14732e505235250320d07a7e75a061e832c1a5542d346bf2f78e1cb68dea462fbcf564b26a03a64540963a22aa85c752a838a949ec376a7c8e1924b3
7
+ data.tar.gz: 11a1aab740992b64b313c6d4b875907da3a4d7bd2e3f5a798ab56f7a13d6f9dca6b4eb9c2130bb91b29b3f605e784aed27cb436704fcb90cf2a99b24f7720926
data/README.md CHANGED
@@ -3,8 +3,8 @@ Group related classes together. No more silos.
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/drawers.svg)](https://badge.fury.io/rb/drawers)
5
5
  [![Build Status](https://travis-ci.org/NullVoxPopuli/drawers.svg?branch=master)](https://travis-ci.org/NullVoxPopuli/drawers)
6
- [![Code Climate](https://codeclimate.com/repos/57dddb2c50dac40e6900197c/badges/73a0a0761e417c655b68/gpa.svg)](https://codeclimate.com/repos/57dddb2c50dac40e6900197c/feed)
7
- [![Test Coverage](https://codeclimate.com/repos/57dddb2c50dac40e6900197c/badges/73a0a0761e417c655b68/coverage.svg)](https://codeclimate.com/repos/57dddb2c50dac40e6900197c/coverage)
6
+ [![Code Climate](https://codeclimate.com/github/NullVoxPopuli/drawers/badges/gpa.svg)](https://codeclimate.com/github/NullVoxPopuli/drawers)
7
+ [![Test Coverage](https://codeclimate.com/github/NullVoxPopuli/drawers/badges/coverage.svg)](https://codeclimate.com/github/NullVoxPopuli/drawers/coverage)
8
8
  [![Dependency Status](https://gemnasium.com/badges/github.com/NullVoxPopuli/drawers.svg)](https://gemnasium.com/github.com/NullVoxPopuli/drawers)
9
9
 
10
10
 
@@ -103,6 +103,8 @@ ActiveModelSerializers.config.serializer_lookup_chain.unshift(
103
103
  ```
104
104
  Note: as of 2016-11-04, only [this branch of AMS](https://github.com/rails-api/active_model_serializers/pull/1757) supports a confnigurable lookup chain
105
105
 
106
+ Note: as of 2016-11-16, the `master` (>= v0.10.3) branch of AMS supports configurable lookup chain.
107
+
106
108
  ## Migrating
107
109
 
108
110
  Each part of your app can be migrated gradually (either manually or automatically).
@@ -3,6 +3,17 @@
3
3
  require 'active_support'
4
4
 
5
5
  module Drawers
6
+ DEFAULT_RESOURCE_SUFFIXES = %w(
7
+ Controller
8
+ Forms
9
+ Serializer
10
+ Operations
11
+ Presenters
12
+ Policy
13
+ Policies
14
+ Services
15
+ ).freeze
16
+
6
17
  require 'drawers/active_support/dependency_extensions'
7
18
  require 'drawers/action_view/path_extensions'
8
19
  require 'drawers/action_view/resource_resolver'
@@ -10,6 +21,14 @@ module Drawers
10
21
 
11
22
  module_function
12
23
 
24
+ def resource_suffixes
25
+ @resource_suffixes || DEFAULT_RESOURCE_SUFFIXES
26
+ end
27
+
28
+ def resource_suffixes=(suffixes)
29
+ @resource_suffixes = suffixes.freeze
30
+ end
31
+
13
32
  def directory=(dir)
14
33
  @directory = dir
15
34
  end
@@ -18,11 +37,21 @@ module Drawers
18
37
  @directory || ''
19
38
  end
20
39
 
40
+ # @api private
41
+ # Join all the suffix names together with an "OR" operator
42
+ def resource_suffixes_regex
43
+ /(#{resource_suffixes.join('|')})/
44
+ end
45
+
46
+ # @api private
47
+ # split on any of the resource suffixes OR the ruby namespace seperator
48
+ def qualified_name_split
49
+ /::|#{resource_suffixes_regex}/
50
+ end
51
+
21
52
  require 'drawers/railtie'
53
+
22
54
  ActiveSupport::Dependencies.extend Drawers::DependencyExtensions
23
55
  ActionController::Base.extend Drawers::PathExtensions
24
-
25
- if Rails.version > '5'
26
- ActionController::API.extend Drawers::PathExtensions
27
- end
56
+ ActionController::API.extend Drawers::PathExtensions if Rails.version > '5'
28
57
  end
@@ -1,25 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  module Drawers
3
3
  module DependencyExtensions
4
- RESOURCE_SUFFIX_NAMES = %w(
5
- Controller
6
- Forms
7
- Serializer
8
- Operations
9
- Presenters
10
- Policy
11
- Policies
12
- Services
13
- ).freeze
14
-
15
4
  ERROR_CIRCULAR_DEPENDENCY = 'Circular dependency detected while autoloading constant'
16
5
 
17
- # Join all the suffix names together with an "OR" operator
18
- RESOURCE_SUFFIXES = /(#{RESOURCE_SUFFIX_NAMES.join('|')})/
19
-
20
- # split on any of the resource suffixes OR the ruby namespace seperator
21
- QUALIFIED_NAME_SPLIT = /::|#{RESOURCE_SUFFIXES}/
22
-
23
6
  def load_from_path(file_path, qualified_name, from_mod, const_name)
24
7
  expanded = File.expand_path(file_path)
25
8
  expanded.sub!(/\.rb\z/, '')
@@ -1,9 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Drawers
3
3
  class ResourceParts
4
- RESOURCE_SUFFIX_NAMES = Drawers::DependencyExtensions::RESOURCE_SUFFIX_NAMES
5
- QUALIFIED_NAME_SPLIT = Drawers::DependencyExtensions::QUALIFIED_NAME_SPLIT
6
-
7
4
  attr_reader :namespace, :resource_name,
8
5
  :resource_type, :named_resource_type,
9
6
  :class_path
@@ -80,7 +77,9 @@ module Drawers
80
77
  # Api::V2::PostOperations::Update
81
78
  # => Api, V2, Post, Operations, Update
82
79
  def qualified_parts
83
- @qualified_parts ||= @qualified_name.split(QUALIFIED_NAME_SPLIT).reject(&:blank?)
80
+ @qualified_parts ||= @qualified_name
81
+ .split(Drawers.qualified_name_split)
82
+ .reject(&:blank?)
84
83
  end
85
84
 
86
85
  # based on the position of of the resource type name,
@@ -91,7 +90,7 @@ module Drawers
91
90
  # Given: Api, V2, Post, Operations, Update
92
91
  # ^ index_of_resource_type (3)
93
92
  def index_of_resource_type
94
- @index_of_resource_type ||= qualified_parts.index { |x| RESOURCE_SUFFIX_NAMES.include?(x) }
93
+ @index_of_resource_type ||= qualified_parts.index { |x| Drawers.resource_suffixes.include?(x) }
95
94
  end
96
95
  end
97
96
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Drawers
3
- VERSION = '1.0.1'
3
+ VERSION = '1.1.0'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drawers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - L. Preston Sego III
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-22 00:00:00.000000000 Z
11
+ date: 2017-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -172,8 +172,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
172
  version: '0'
173
173
  requirements: []
174
174
  rubyforge_project:
175
- rubygems_version: 2.5.2
175
+ rubygems_version: 2.6.8
176
176
  signing_key:
177
177
  specification_version: 4
178
- summary: Drawers-1.0.1
178
+ summary: Drawers-1.1.0
179
179
  test_files: []