exposant 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +73 -0
- data/.rubocop_todo.yml +0 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +58 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +16 -0
- data/exposant.gemspec +40 -0
- data/lib/exposant/collection_exhibitor.rb +21 -0
- data/lib/exposant/concerns/exhibitor.rb +24 -0
- data/lib/exposant/concerns/presentable.rb +56 -0
- data/lib/exposant/model_exhibitor.rb +34 -0
- data/lib/exposant/version.rb +5 -0
- data/lib/exposant.rb +16 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a32157d1c5d5bc482d278ea27afc87bea199f1a70459f5158e17a4cb27a35c2b
|
4
|
+
data.tar.gz: 4a31ae775b219ded8bce8961ee321ab57334af8603412997b6622a5e9e918868
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b30952a3a17b5f5bd718d2a1e54f7fb7e186a60cd2a2a0cf667e8f9716eb42fc70d0b80cf1303544c96ee2a39893336bfe4d3ce29e21f70c73f390781a983524
|
7
|
+
data.tar.gz: e0ae7a0c8501b34037038621b79ab9bb78b596c6c3216974bf74970b3f3f8ee0bf328b18e703926bf451dd5dd87797ee3099178ace2d29d2cfb0033560f793b6
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
NewCops: enable
|
5
|
+
|
6
|
+
Layout/LineLength:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Layout/SpaceAroundMethodCallOperator:
|
10
|
+
Enabled: true
|
11
|
+
|
12
|
+
Lint/RaiseException:
|
13
|
+
Enabled: true
|
14
|
+
|
15
|
+
Lint/StructNewOverride:
|
16
|
+
Enabled: true
|
17
|
+
|
18
|
+
Lint/EmptyClass:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Metrics/AbcSize:
|
22
|
+
Max: 50
|
23
|
+
|
24
|
+
Metrics/CyclomaticComplexity:
|
25
|
+
Max: 15
|
26
|
+
|
27
|
+
Metrics/ClassLength:
|
28
|
+
Max: 200
|
29
|
+
|
30
|
+
Metrics/MethodLength:
|
31
|
+
Max: 30
|
32
|
+
|
33
|
+
Metrics/PerceivedComplexity:
|
34
|
+
Max: 15
|
35
|
+
|
36
|
+
Style/ClassVars:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
Style/Documentation:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
Style/ExponentialNotation:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
Style/FetchEnvVar:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
Style/FrozenStringLiteralComment:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
Style/HashEachMethods:
|
52
|
+
Enabled: false
|
53
|
+
|
54
|
+
Style/HashSyntax:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
Style/HashTransformKeys:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
Style/HashTransformValues:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
Style/NumericLiterals:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
Style/NumericPredicate:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
Style/OpenStructUse:
|
70
|
+
Enabled: false
|
71
|
+
|
72
|
+
Style/SymbolArray:
|
73
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
File without changes
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
exposant (0.1.0)
|
5
|
+
activemodel (~> 7.0)
|
6
|
+
activesupport (~> 7.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (7.0.4)
|
12
|
+
activesupport (= 7.0.4)
|
13
|
+
activesupport (7.0.4)
|
14
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
|
+
i18n (>= 1.6, < 2)
|
16
|
+
minitest (>= 5.1)
|
17
|
+
tzinfo (~> 2.0)
|
18
|
+
ast (2.4.2)
|
19
|
+
concurrent-ruby (1.1.10)
|
20
|
+
i18n (1.12.0)
|
21
|
+
concurrent-ruby (~> 1.0)
|
22
|
+
json (2.6.1)
|
23
|
+
minitest (5.16.3)
|
24
|
+
parallel (1.22.1)
|
25
|
+
parser (3.1.2.1)
|
26
|
+
ast (~> 2.4.1)
|
27
|
+
rainbow (3.1.1)
|
28
|
+
rake (13.0.6)
|
29
|
+
regexp_parser (2.5.0)
|
30
|
+
rexml (3.2.5)
|
31
|
+
rubocop (1.36.0)
|
32
|
+
json (~> 2.3)
|
33
|
+
parallel (~> 1.10)
|
34
|
+
parser (>= 3.1.2.1)
|
35
|
+
rainbow (>= 2.2.2, < 4.0)
|
36
|
+
regexp_parser (>= 1.8, < 3.0)
|
37
|
+
rexml (>= 3.2.5, < 4.0)
|
38
|
+
rubocop-ast (>= 1.20.1, < 2.0)
|
39
|
+
ruby-progressbar (~> 1.7)
|
40
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
41
|
+
rubocop-ast (1.21.0)
|
42
|
+
parser (>= 3.1.1.0)
|
43
|
+
ruby-progressbar (1.11.0)
|
44
|
+
tzinfo (2.0.5)
|
45
|
+
concurrent-ruby (~> 1.0)
|
46
|
+
unicode-display_width (2.2.0)
|
47
|
+
|
48
|
+
PLATFORMS
|
49
|
+
x86_64-linux-musl
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
exposant!
|
53
|
+
minitest (~> 5.0)
|
54
|
+
rake (~> 13.0)
|
55
|
+
rubocop (~> 1.21)
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
2.3.7
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Thomas Kienlen
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Exposant
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/exposant`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'exposant'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install exposant
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kmmndr/exposant.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << 'test'
|
8
|
+
t.libs << 'lib'
|
9
|
+
t.test_files = FileList['test/**/test_*.rb']
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'rubocop/rake_task'
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task default: %i[test rubocop]
|
data/exposant.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/exposant/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'exposant'
|
7
|
+
spec.version = Exposant::VERSION
|
8
|
+
spec.authors = ['Thomas Kienlen']
|
9
|
+
spec.email = ['kommander@laposte.net']
|
10
|
+
|
11
|
+
spec.summary = 'Simple way to create decorators and presenters'
|
12
|
+
spec.homepage = 'http://127.0.0.1:3000'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = '>= 2.6.0'
|
15
|
+
|
16
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
17
|
+
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
20
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
spec.bindir = 'exe'
|
30
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ['lib']
|
32
|
+
|
33
|
+
# Uncomment to register a new dependency of your gem
|
34
|
+
spec.add_dependency 'activemodel', '~> 7.0'
|
35
|
+
spec.add_dependency 'activesupport', '~> 7.0'
|
36
|
+
|
37
|
+
# For more information and examples about making a new gem, check out our
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
39
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
40
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Exposant
|
2
|
+
class CollectionExhibitor < SimpleDelegator
|
3
|
+
include Exhibitor
|
4
|
+
extend ActiveModel::Naming
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def self.exhibitor_variant
|
8
|
+
self::MODEL_PRESENTER_VARIANT if const_defined?('MODEL_PRESENTER_VARIANT')
|
9
|
+
end
|
10
|
+
|
11
|
+
def each
|
12
|
+
return enum_for(:each) unless block_given?
|
13
|
+
|
14
|
+
__getobj__.each { |o| yield o.exhibitor(self.class.exhibitor_variant) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_model
|
18
|
+
self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Exhibitor
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
def obj
|
5
|
+
__getobj__
|
6
|
+
end
|
7
|
+
|
8
|
+
def exhibitor_for(obj)
|
9
|
+
self.class.exhibitor_for(obj)
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def exhibitor_for_super(method, klass = nil)
|
14
|
+
define_method(method) do |*args|
|
15
|
+
klass ||= self.class
|
16
|
+
klass.new(super(*args))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def exhibitor_for(obj)
|
21
|
+
new(obj)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Exposant
|
2
|
+
module Presentable
|
3
|
+
module Model
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def exhibitor(variant = nil)
|
7
|
+
self.class.exhibitor_class(variant).new(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def exhibitor(obj, variant = nil)
|
12
|
+
obj.extend(Presentable::Collection)
|
13
|
+
obj.model_klass = self
|
14
|
+
|
15
|
+
obj.exhibitor(variant)
|
16
|
+
end
|
17
|
+
|
18
|
+
def exhibitor_class(variant = nil)
|
19
|
+
klass = [
|
20
|
+
name,
|
21
|
+
variant&.downcase&.capitalize,
|
22
|
+
'Exhibitor'
|
23
|
+
].join
|
24
|
+
|
25
|
+
raise "Missing exhibitor #{klass}" unless const_defined?(klass)
|
26
|
+
|
27
|
+
klass.constantize
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module Collection
|
33
|
+
attr_accessor :model_klass
|
34
|
+
|
35
|
+
def exhibitor(variant = nil)
|
36
|
+
exhibitor_class(variant).new(self)
|
37
|
+
end
|
38
|
+
|
39
|
+
def exhibitor_class(variant = nil)
|
40
|
+
klass_name = model_klass.name
|
41
|
+
|
42
|
+
klass = [
|
43
|
+
klass_name.pluralize,
|
44
|
+
variant&.downcase&.capitalize,
|
45
|
+
'Exhibitor'
|
46
|
+
].join
|
47
|
+
|
48
|
+
begin
|
49
|
+
klass.constantize
|
50
|
+
rescue NameError
|
51
|
+
raise "Missing exhibitor #{klass}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Exposant
|
2
|
+
class ModelExhibitor < SimpleDelegator
|
3
|
+
include Exhibitor
|
4
|
+
extend ActiveModel::Naming
|
5
|
+
|
6
|
+
def to_model
|
7
|
+
obj
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.human_attribute_name(*args)
|
11
|
+
exhibited_class.human_attribute_name(*args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.exhibited_class
|
15
|
+
return ancestors[1].exhibited_class unless ancestors[1] == ModelExhibitor
|
16
|
+
|
17
|
+
name.gsub(/Exhibitor$/, '').constantize
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.exhibitor_variant
|
21
|
+
variant = name[parent_exhibitor.exhibited_class.name.length..].gsub(/Exhibitor$/, '').downcase
|
22
|
+
|
23
|
+
return nil if variant.blank?
|
24
|
+
|
25
|
+
variant.to_sym
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.parent_exhibitor
|
29
|
+
return ancestors[1].parent_exhibitor unless ancestors[1] == ModelExhibitor
|
30
|
+
|
31
|
+
name.constantize
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/exposant.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'delegate'
|
4
|
+
require 'active_support'
|
5
|
+
require 'active_model'
|
6
|
+
|
7
|
+
require_relative 'exposant/concerns/presentable'
|
8
|
+
require_relative 'exposant/concerns/exhibitor'
|
9
|
+
require_relative 'exposant/collection_exhibitor'
|
10
|
+
require_relative 'exposant/model_exhibitor'
|
11
|
+
require_relative 'exposant/version'
|
12
|
+
|
13
|
+
module Exposant
|
14
|
+
class Error < StandardError; end
|
15
|
+
# Your code goes here...
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: exposant
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thomas Kienlen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-10-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '7.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '7.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '7.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '7.0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- kommander@laposte.net
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".rubocop.yml"
|
49
|
+
- ".rubocop_todo.yml"
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- exposant.gemspec
|
56
|
+
- lib/exposant.rb
|
57
|
+
- lib/exposant/collection_exhibitor.rb
|
58
|
+
- lib/exposant/concerns/exhibitor.rb
|
59
|
+
- lib/exposant/concerns/presentable.rb
|
60
|
+
- lib/exposant/model_exhibitor.rb
|
61
|
+
- lib/exposant/version.rb
|
62
|
+
homepage: http://127.0.0.1:3000
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata:
|
66
|
+
homepage_uri: http://127.0.0.1:3000
|
67
|
+
rubygems_mfa_required: 'true'
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 2.6.0
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubygems_version: 3.3.7
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Simple way to create decorators and presenters
|
87
|
+
test_files: []
|