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 +4 -4
- data/.rubocop.yml +8 -5
- data/bin/bundle +114 -0
- data/chic.gemspec +4 -2
- data/lib/chic/configuration.rb +1 -1
- data/lib/chic/errors.rb +1 -0
- data/lib/chic/formats.rb +20 -6
- data/lib/chic/formatters/nil.rb +1 -1
- data/lib/chic/presents.rb +5 -2
- data/lib/chic/version.rb +1 -1
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd0f4b4ac3b5b6097ea4670bad650de8b39f011c59a73101f3b82552f9f14bac
|
4
|
+
data.tar.gz: c199afc9dd72faa4f8f9fc8a466cb6fce82df91d926053044cfd1b8a95a428c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3d6312d529f55e22af639948e8116ce0940741594a0414a023d67bfc31078b683e24b7cb9945413546cb65f582688a69422b3bb273147a9de81e86a766f42db
|
7
|
+
data.tar.gz: 1e6bf540de26573830f280d8688b6c032595ca7526d9eb0742ae6cd637457ef2a9453628f7c4a48580c91666e55895d08d3a5a65b6420d6fcbabd8198fded850
|
data/.rubocop.yml
CHANGED
data/bin/bundle
ADDED
@@ -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
|
data/chic.gemspec
CHANGED
@@ -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', '~>
|
29
|
-
spec.add_development_dependency 'rubocop', '
|
30
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
31
|
+
spec.add_development_dependency 'rubocop', '~> 0.71'
|
30
32
|
end
|
data/lib/chic/configuration.rb
CHANGED
data/lib/chic/errors.rb
CHANGED
data/lib/chic/formats.rb
CHANGED
@@ -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
|
-
|
91
|
+
case options[:value]
|
92
|
+
when Symbol
|
81
93
|
send(options[:value])
|
82
|
-
|
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
|
|
data/lib/chic/formatters/nil.rb
CHANGED
data/lib/chic/presents.rb
CHANGED
@@ -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
|
-
|
118
|
+
case options[:value]
|
119
|
+
when Symbol
|
119
120
|
send(options[:value])
|
120
|
-
|
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
|
data/lib/chic/version.rb
CHANGED
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.
|
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:
|
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: '
|
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: '
|
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.
|
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.
|
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: '
|
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
|
-
|
122
|
-
|
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: []
|