chic 0.1.0 → 0.2.0

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: a6ee27baaf52ccaffd000c9ffc37ba80e929ab93386c2f1dc2fb3d419d9cd86e
4
- data.tar.gz: aebe4ade08bfff97f1fa3f4a96334dc4cb5cb9efdcbc108d6b00e1f81e781f1c
3
+ metadata.gz: fd0f4b4ac3b5b6097ea4670bad650de8b39f011c59a73101f3b82552f9f14bac
4
+ data.tar.gz: c199afc9dd72faa4f8f9fc8a466cb6fce82df91d926053044cfd1b8a95a428c1
5
5
  SHA512:
6
- metadata.gz: 200473240b8f99cbef6229c0181a7e820df796b744f199f0b25bcb22656109c0338b14c63385f8fe6c6eaa06027bc97a33edd8e0635f995eb974d1635f449b48
7
- data.tar.gz: 1b0dc1cc823cfd555e19f4c6aea0306a852fcef8ff9f66bb1c3f1c7189a6003368fb7f5497a825311c24dc65d8551e3779cd53f0c1da2f4192d8ac6f358f6115
6
+ metadata.gz: d3d6312d529f55e22af639948e8116ce0940741594a0414a023d67bfc31078b683e24b7cb9945413546cb65f582688a69422b3bb273147a9de81e86a766f42db
7
+ data.tar.gz: 1e6bf540de26573830f280d8688b6c032595ca7526d9eb0742ae6cd637457ef2a9453628f7c4a48580c91666e55895d08d3a5a65b6420d6fcbabd8198fded850
@@ -1,8 +1,11 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.5
2
+ NewCops: enable
3
+ TargetRubyVersion: 2.7
4
+ Exclude:
5
+ - 'bin/**/*'
3
6
 
4
- Documentation:
5
- Enabled: false
6
-
7
- Metrics/LineLength:
7
+ Layout/LineLength:
8
8
  Max: 120
9
+
10
+ Style/Documentation:
11
+ Enabled: false
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'bundle' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "rubygems"
12
+
13
+ m = Module.new do
14
+ module_function
15
+
16
+ def invoked_as_script?
17
+ File.expand_path($0) == File.expand_path(__FILE__)
18
+ end
19
+
20
+ def env_var_version
21
+ ENV["BUNDLER_VERSION"]
22
+ end
23
+
24
+ def cli_arg_version
25
+ return unless invoked_as_script? # don't want to hijack other binstubs
26
+ return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27
+ bundler_version = nil
28
+ update_index = nil
29
+ ARGV.each_with_index do |a, i|
30
+ if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31
+ bundler_version = a
32
+ end
33
+ next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34
+ bundler_version = $1
35
+ update_index = i
36
+ end
37
+ bundler_version
38
+ end
39
+
40
+ def gemfile
41
+ gemfile = ENV["BUNDLE_GEMFILE"]
42
+ return gemfile if gemfile && !gemfile.empty?
43
+
44
+ File.expand_path("../../Gemfile", __FILE__)
45
+ end
46
+
47
+ def lockfile
48
+ lockfile =
49
+ case File.basename(gemfile)
50
+ when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51
+ else "#{gemfile}.lock"
52
+ end
53
+ File.expand_path(lockfile)
54
+ end
55
+
56
+ def lockfile_version
57
+ return unless File.file?(lockfile)
58
+ lockfile_contents = File.read(lockfile)
59
+ return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60
+ Regexp.last_match(1)
61
+ end
62
+
63
+ def bundler_version
64
+ @bundler_version ||=
65
+ env_var_version || cli_arg_version ||
66
+ lockfile_version
67
+ end
68
+
69
+ def bundler_requirement
70
+ return "#{Gem::Requirement.default}.a" unless bundler_version
71
+
72
+ bundler_gem_version = Gem::Version.new(bundler_version)
73
+
74
+ requirement = bundler_gem_version.approximate_recommendation
75
+
76
+ return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
77
+
78
+ requirement += ".a" if bundler_gem_version.prerelease?
79
+
80
+ requirement
81
+ end
82
+
83
+ def load_bundler!
84
+ ENV["BUNDLE_GEMFILE"] ||= gemfile
85
+
86
+ activate_bundler
87
+ end
88
+
89
+ def activate_bundler
90
+ gem_error = activation_error_handling do
91
+ gem "bundler", bundler_requirement
92
+ end
93
+ return if gem_error.nil?
94
+ require_error = activation_error_handling do
95
+ require "bundler/version"
96
+ end
97
+ return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
98
+ warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
99
+ exit 42
100
+ end
101
+
102
+ def activation_error_handling
103
+ yield
104
+ nil
105
+ rescue StandardError, LoadError => e
106
+ e
107
+ end
108
+ end
109
+
110
+ m.load_bundler!
111
+
112
+ if m.invoked_as_script?
113
+ load Gem.bin_path("bundler", "bundle")
114
+ end
@@ -23,8 +23,10 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ['lib']
25
25
 
26
+ spec.required_ruby_version = '>= 2.7'
27
+
26
28
  spec.add_development_dependency 'bundler', '~> 2.0'
27
29
  spec.add_development_dependency 'minitest', '~> 5.0'
28
- spec.add_development_dependency 'rake', '~> 10.0'
29
- spec.add_development_dependency 'rubocop', '>= 0.49.0'
30
+ spec.add_development_dependency 'rake', '~> 13.0'
31
+ spec.add_development_dependency 'rubocop', '~> 0.71'
30
32
  end
@@ -19,7 +19,7 @@ module Chic
19
19
  end
20
20
 
21
21
  def logger
22
- @logger ||= Logger.new(STDOUT)
22
+ @logger ||= Logger.new($stdout)
23
23
  end
24
24
  end
25
25
  end
@@ -3,4 +3,5 @@
3
3
  module Chic
4
4
  class PresentsOptionsNotValid < StandardError; end
5
5
  class FormatsOptionsNotValid < StandardError; end
6
+ class ConfigFormatterNotValid < StandardError; end
6
7
  end
@@ -41,7 +41,6 @@ module Chic
41
41
  end
42
42
 
43
43
  # rubocop: disable Metrics/AbcSize
44
- # rubocop: disable Metrics/CyclomaticComplexity
45
44
  def _validate_formats_options_with!(attributes, options)
46
45
  _raise_formats_options_not_valid '`with` must be a symbol or a class', attributes \
47
46
  if options.key?(:with) && !options[:with].is_a?(Symbol) && !options[:with].is_a?(Class)
@@ -49,9 +48,8 @@ module Chic
49
48
  _raise_formats_options_not_valid "`with` formatter :#{options[:with]} doesn't exist", attributes \
50
49
  if options.key?(:with) && options[:with].is_a?(Symbol) && !Chic.configuration.formatters.key?(options[:with])
51
50
  end
52
- # rubocop: enable Metrics/AbcSize
53
- # rubocop: enable Metrics/CyclomaticComplexity
54
51
 
52
+ # rubocop: enable Metrics/AbcSize
55
53
  def _validate_formats_options_value!(attributes, options)
56
54
  _raise_formats_options_not_valid '`value` must be a symbol or a lambda', attributes \
57
55
  if options.key?(:value) && !options[:value].is_a?(Symbol) && !options[:value].is_a?(Proc)
@@ -70,17 +68,33 @@ module Chic
70
68
 
71
69
  private
72
70
 
71
+ # rubocop: disable Metrics/MethodLength
73
72
  def _formatters
74
- Chic.configuration.formatters
73
+ @_formatters ||= Chic.configuration.formatters.reduce({}) do |result, (key, klass)|
74
+ formatter = case klass
75
+ when Class
76
+ klass
77
+ when String
78
+ klass.constantize
79
+ else
80
+ raise ConfigFormatterNotValid, "Configured formatter for #{key} must be a class or class-string"
81
+ end
82
+
83
+ result.merge(key => formatter)
84
+ end
75
85
  end
86
+ # rubocop: enable Metrics/MethodLength
76
87
 
77
88
  def _formats_options_value(attribute, options)
78
89
  return object&.public_send(attribute) unless options.is_a?(Hash) && options.key?(:value)
79
90
 
80
- if options[:value].is_a?(Symbol)
91
+ case options[:value]
92
+ when Symbol
81
93
  send(options[:value])
82
- elsif options[:value].is_a?(Proc)
94
+ when Proc
83
95
  instance_exec(&options[:value])
96
+ else
97
+ raise FormatsOptionsNotValid, "Options value for #{attribute} must be a symbol or a Proc"
84
98
  end
85
99
  end
86
100
 
@@ -17,7 +17,7 @@ module Chic
17
17
  private
18
18
 
19
19
  def value
20
- object&.to_s
20
+ object.to_s
21
21
  end
22
22
  end
23
23
  end
@@ -115,10 +115,13 @@ module Chic
115
115
  def _presents_options_value(attribute, options)
116
116
  return object&.public_send(attribute) unless options.is_a?(Hash) && options.key?(:value)
117
117
 
118
- if options[:value].is_a?(Symbol)
118
+ case options[:value]
119
+ when Symbol
119
120
  send(options[:value])
120
- elsif options[:value].is_a?(Proc)
121
+ when Proc
121
122
  instance_exec(&options[:value])
123
+ else
124
+ raise PresentsOptionsNotValid, "Options value for #{attribute} must be a symbol or a Proc"
122
125
  end
123
126
  end
124
127
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Chic
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lawrance Shepstone
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-16 00:00:00.000000000 Z
11
+ date: 2020-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,29 +44,29 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.49.0
61
+ version: '0.71'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.49.0
69
- description:
68
+ version: '0.71'
69
+ description:
70
70
  email:
71
71
  - lawrance@collabcollective.com
72
72
  executables: []
@@ -81,6 +81,7 @@ files:
81
81
  - LICENSE.txt
82
82
  - README.md
83
83
  - Rakefile
84
+ - bin/bundle
84
85
  - bin/console
85
86
  - bin/setup
86
87
  - chic.gemspec
@@ -103,7 +104,7 @@ homepage: https://github.com/collcoll/chic
103
104
  licenses:
104
105
  - MIT
105
106
  metadata: {}
106
- post_install_message:
107
+ post_install_message:
107
108
  rdoc_options: []
108
109
  require_paths:
109
110
  - lib
@@ -111,16 +112,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
112
  requirements:
112
113
  - - ">="
113
114
  - !ruby/object:Gem::Version
114
- version: '0'
115
+ version: '2.7'
115
116
  required_rubygems_version: !ruby/object:Gem::Requirement
116
117
  requirements:
117
118
  - - ">="
118
119
  - !ruby/object:Gem::Version
119
120
  version: '0'
120
121
  requirements: []
121
- rubyforge_project:
122
- rubygems_version: 2.7.6
123
- signing_key:
122
+ rubygems_version: 3.1.4
123
+ signing_key:
124
124
  specification_version: 4
125
125
  summary: Opinionated presentation layer comprised of presenters and formatters.
126
126
  test_files: []