adornable 1.0.2 → 1.0.3

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
  SHA256:
3
- metadata.gz: 962cc3a7645f1a3fb6d729907b0d51d57c5c246d194ce3618516085831625fff
4
- data.tar.gz: cedbf0bed0c105d3ae2336e2da7c872b193c0706c7eef7b4d3f40d1437704d97
3
+ metadata.gz: 39c5f35488e69b6f4de57d24b3a4867552fdb7e72a59a98017cd59af19dbc7f7
4
+ data.tar.gz: 3d9998525bb6393c681cb2688d3ba3d2df321ae5e39f598e9c8ea7a3bed9cd8e
5
5
  SHA512:
6
- metadata.gz: 41e131cde6f78b610f6417b8a7a2710f7be4fc13261db3902b97a4d8781880ea930a665392094868d733bd400bd0d66be1cb187f0c310240958200cb8808597e
7
- data.tar.gz: b93c1072a77b5b1b667fea3493466c6fc5bcf544c4d750c1c8ae36c1f260ee0b4fcfe50c09255ac7c32dda287206b1f32130aede3867d7b2c4dd5296e26953ef
6
+ metadata.gz: 9a26ac80096736eaa6e20d6c63250686491b528e915603723f933879dfda9d10ce0e17e73531e7a4c46b7eb4d47efdbb152f9c0da78fab89850740a11fb6f8d2
7
+ data.tar.gz: 44ea1ed9f80932ea5214e7287bbbc40c5a385c10eb5b9dce52f34dc5e915fff6ff3d5da854084f0a342d6728657420f4ce940d1e27d94c3c3cb629bddbd9f272
data/.rubocop.yml ADDED
@@ -0,0 +1,59 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+ - rubocop-rake
5
+
6
+ # Layout
7
+
8
+ Layout/LineLength:
9
+ Max: 120
10
+ Exclude:
11
+ - 'spec/**/*_spec.rb'
12
+ - 'test/**/*_spec.rb'
13
+
14
+ Layout/EndAlignment:
15
+ EnforcedStyleAlignWith: variable
16
+
17
+ # Metrics
18
+
19
+ Metrics/AbcSize:
20
+ CountRepeatedAttributes: false
21
+ Exclude:
22
+ - 'spec/**/*_spec.rb'
23
+ - 'test/**/*_spec.rb'
24
+
25
+ Metrics/BlockLength:
26
+ Exclude:
27
+ - 'spec/**/*_spec.rb'
28
+ - 'test/**/*_spec.rb'
29
+
30
+ Metrics/ClassLength:
31
+ Exclude:
32
+ - 'spec/**/*_spec.rb'
33
+ - 'test/**/*_spec.rb'
34
+
35
+ # Rspec
36
+
37
+ RSpec/ExampleLength:
38
+ Max: 20
39
+
40
+ RSpec/MessageSpies:
41
+ Enabled: false
42
+
43
+ RSpec/MultipleExpectations:
44
+ Max: 5
45
+
46
+ RSpec/NestedGroups:
47
+ Max: 10
48
+
49
+ # Style
50
+
51
+ Style/DoubleNegation:
52
+ Enabled: false
53
+
54
+ Style/ExpandPathArguments:
55
+ Exclude:
56
+ - 'adornable.gemspec'
57
+
58
+ Style/StringLiterals:
59
+ Enabled: false
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/adornable.gemspec CHANGED
@@ -1,29 +1,35 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  lib = File.expand_path("../lib", __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require "adornable/version"
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "adornable"
8
- spec.version = Adornable::VERSION
9
- spec.authors = ["Keegan Leitz"]
10
- spec.email = ["kjleitz@gmail.com"]
8
+ spec.name = "adornable"
9
+ spec.version = Adornable::VERSION
10
+ spec.authors = ["Keegan Leitz"]
11
+ spec.email = ["kjleitz@gmail.com"]
11
12
 
12
- spec.summary = "Method decorators for Ruby"
13
- spec.description = "Method decorators for Ruby"
14
- spec.homepage = "https://github.com/kjleitz/adornable"
15
- spec.license = "MIT"
13
+ spec.summary = "Method decorators for Ruby"
14
+ spec.description = "Method decorators for Ruby"
15
+ spec.homepage = "https://github.com/kjleitz/adornable"
16
+ spec.license = "MIT"
17
+ spec.required_ruby_version = ">= 2.4.7"
16
18
 
17
19
  # Specify which files should be added to the gem when it is released.
18
20
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
22
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
23
  end
22
- spec.bindir = "exe"
23
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
26
  spec.require_paths = ["lib"]
25
27
 
26
28
  spec.add_development_dependency "bundler", "~> 1.17"
27
29
  spec.add_development_dependency "rake", "~> 10.0"
28
30
  spec.add_development_dependency "rspec", "~> 3.0"
31
+ spec.add_development_dependency "rubocop", "~> 1.10"
32
+ spec.add_development_dependency "rubocop-performance", "~> 1.9"
33
+ spec.add_development_dependency "rubocop-rake", "~> 0.5"
34
+ spec.add_development_dependency "rubocop-rspec", "~> 2.2"
29
35
  end
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require "adornable"
data/lib/adornable.rb CHANGED
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "adornable/version"
2
4
  require "adornable/utils"
3
5
  require "adornable/error"
4
6
  require "adornable/decorators"
5
7
  require "adornable/machinery"
6
8
 
9
+ # Extend the `Adornable` module in your class in order to have access to the
10
+ # `decorate` and `add_decorators_from` macros.
7
11
  module Adornable
8
12
  def adornable_machinery
9
13
  @adornable_machinery ||= Adornable::Machinery.new
@@ -27,9 +31,10 @@ module Adornable
27
31
 
28
32
  def method_added(method_name)
29
33
  machinery = adornable_machinery # for local variable
30
- return unless machinery.has_accumulated_decorators?
34
+ return unless machinery.accumulated_decorators?
35
+
31
36
  machinery.apply_accumulated_decorators_to_instance_method!(method_name)
32
- original_method = self.instance_method(method_name)
37
+ original_method = instance_method(method_name)
33
38
  define_method(method_name) do |*args|
34
39
  bound_method = original_method.bind(self)
35
40
  machinery.run_decorated_instance_method(bound_method, *args)
@@ -39,9 +44,10 @@ module Adornable
39
44
 
40
45
  def singleton_method_added(method_name)
41
46
  machinery = adornable_machinery # for local variable
42
- return unless machinery.has_accumulated_decorators?
47
+ return unless machinery.accumulated_decorators?
48
+
43
49
  machinery.apply_accumulated_decorators_to_class_method!(method_name)
44
- original_method = self.method(method_name)
50
+ original_method = method(method_name)
45
51
  define_singleton_method(method_name) do |*args|
46
52
  machinery.run_decorated_class_method(original_method, *args)
47
53
  end
@@ -1,4 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Adornable
4
+ # `Adornable::Decorators` is used as the default namespace for decorator
5
+ # methods when a decorator method that is neither explicitly sourced (via the
6
+ # `decorate from: <receiver>` option) nor implicitly sourced (via the
7
+ # `add_decorators_from <receiver>` macro).
2
8
  class Decorators
3
9
  def self.log(method_receiver, method_name, arguments)
4
10
  receiver_name, name_delimiter = if method_receiver.is_a?(Class)
@@ -12,7 +18,7 @@ module Adornable
12
18
  yield
13
19
  end
14
20
 
15
- def self.memoize(method_receiver, method_name, arguments)
21
+ def self.memoize(method_receiver, method_name, _arguments)
16
22
  memo_var_name = :"@adornable_memoized_#{method_receiver.object_id}_#{method_name}"
17
23
  existing = instance_variable_get(memo_var_name)
18
24
  value = existing.nil? ? yield : existing
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Adornable
2
4
  module Error
3
5
  class Base < ::StandardError
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'adornable/utils'
2
4
  require 'adornable/error'
3
5
 
4
6
  module Adornable
5
- class Machinery
7
+ class Machinery # :nodoc:
6
8
  def register_decorator_receiver!(receiver)
7
9
  registered_decorator_receivers.unshift(receiver)
8
10
  end
@@ -16,7 +18,7 @@ module Adornable
16
18
  accumulated_decorators << decorator
17
19
  end
18
20
 
19
- def has_accumulated_decorators?
21
+ def accumulated_decorators?
20
22
  Adornable::Utils.present?(accumulated_decorators)
21
23
  end
22
24
 
@@ -82,6 +84,7 @@ module Adornable
82
84
 
83
85
  def run_decorators(decorators, bound_method, *args)
84
86
  return bound_method.call(*args) if Adornable::Utils.blank?(decorators)
87
+
85
88
  decorator, *remaining_decorators = decorators
86
89
  name = decorator[:name]
87
90
  receiver = decorator[:receiver]
@@ -97,16 +100,19 @@ module Adornable
97
100
  end
98
101
  end
99
102
 
103
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity, Layout/LineLength
100
104
  def validate_decorator!(decorator_name, decorator_receiver, bound_method = nil)
101
105
  return if decorator_receiver.respond_to?(decorator_name)
102
106
 
103
107
  location_hint = if bound_method
104
108
  method_receiver = bound_method.receiver
109
+
105
110
  method_full_name = method_receiver.is_a?(Class) ? "#{method_receiver}::#{method.name}" : "#{method_receiver.class}##{method.name}"
111
+
106
112
  method_location = bound_method.source_location
107
113
  "Cannot decorate `#{method_full_name}` (defined at `#{method_location.first}:#{method_location.second})."
108
114
  end
109
-
115
+
110
116
  base_message = "Decorator method `#{decorator_name.inspect}` cannot be found on `#{decorator_receiver.inspect}`."
111
117
 
112
118
  definition_hint = if decorator_receiver.is_a?(Class) && decorator_receiver.instance_methods.include?(decorator_name)
@@ -120,5 +126,6 @@ module Adornable
120
126
  message = [location_hint, base_message, definition_hint].compact.join(" ")
121
127
  raise Adornable::Error::InvalidDecoratorArguments, message
122
128
  end
129
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity, Layout/LineLength
123
130
  end
124
131
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Adornable
2
- class Utils
4
+ class Utils # :nodoc:
3
5
  class << self
4
6
  def blank?(value)
5
7
  value.nil? || (value.respond_to?(:empty?) && value.empty?)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Adornable
2
- VERSION = "1.0.2"
4
+ VERSION = "1.0.3"
3
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adornable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keegan Leitz
@@ -52,6 +52,62 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-performance
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.5'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.5'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.2'
55
111
  description: Method decorators for Ruby
56
112
  email:
57
113
  - kjleitz@gmail.com
@@ -61,6 +117,7 @@ extra_rdoc_files: []
61
117
  files:
62
118
  - ".gitignore"
63
119
  - ".rspec"
120
+ - ".rubocop.yml"
64
121
  - ".travis.yml"
65
122
  - Gemfile
66
123
  - Gemfile.lock
@@ -88,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
145
  requirements:
89
146
  - - ">="
90
147
  - !ruby/object:Gem::Version
91
- version: '0'
148
+ version: 2.4.7
92
149
  required_rubygems_version: !ruby/object:Gem::Requirement
93
150
  requirements:
94
151
  - - ">="