glipper 0.0.3
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 +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.md +42 -0
- data/glipper.gemspec +25 -0
- data/lib/glipper/base.rb +8 -0
- data/lib/glipper/descedants.rb +74 -0
- data/lib/glipper/helpers.rb +20 -0
- data/lib/glipper/initializer.rb +30 -0
- data/lib/glipper/validation.rb +49 -0
- data/lib/glipper/version.rb +3 -0
- data/lib/glipper.rb +9 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ce544e74e5154e4be3030fdbfb32ceffa7b7a9a751f2a3d6bbb9ab205a5386c7
|
4
|
+
data.tar.gz: c23d2de4844c7a0f3611754b16989fcb5cc213206a27b75042593d8754ed5cb5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 070dc7deef0cc6184c5b67f5965d291f8f390153aec461a8610f11341ec2413b0c3dccb557a4bec817a1c112603ae953b32cdc7d138a987f8b01cd644af35b88
|
7
|
+
data.tar.gz: 4e80d101c3d49f40f7f513752e42a7fdfd667b73bbae4bc136a138c4e95418016f5f066151b309916bda09fad1c8e55a65cbf38bf927cd8cdf64d9c1caf1de41
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Glipper
|
2
|
+
|
3
|
+
**pending**
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'glipper'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install glipper
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
**pending**
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
module GliperHelper
|
25
|
+
|
26
|
+
protected def glip(resource)
|
27
|
+
ApplicationDrapper.decorate(resource, self)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
Files `app/drappers/*_drapper.rb`.
|
34
|
+
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it ( https://github.com/[my-github-username]/glipper/fork )
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create a new Pull Request
|
data/glipper.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'glipper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "glipper"
|
8
|
+
spec.version = Glipper::VERSION
|
9
|
+
spec.authors = ["Alexey Osipenko"]
|
10
|
+
spec.email = ["alexey@cimon.io"]
|
11
|
+
spec.summary = %q{Implementation of drapers for the rails views}
|
12
|
+
spec.description = %q{Implementation of drapers for the rails views}
|
13
|
+
spec.homepage = "https://github.com/cimon-ci/glipper"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'actionpack', '>= 4.1.1', '< 8.0'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '>= 2.2.33'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
end
|
data/lib/glipper/base.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
module Glipper
|
2
|
+
module Descedants
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def descendants
|
7
|
+
descendant_files
|
8
|
+
.map { |i| Pathname.new(i).relative_path_from(descendant_root) }
|
9
|
+
.map(&:to_s)
|
10
|
+
.map { |i| i.gsub(/\.rb\z/, '') }
|
11
|
+
.map(&:classify)
|
12
|
+
.map(&:constantize)
|
13
|
+
.select { |k| k < self } + [self]
|
14
|
+
end
|
15
|
+
|
16
|
+
def descendants_with_targets
|
17
|
+
result = []
|
18
|
+
|
19
|
+
self.descendants.each do |d|
|
20
|
+
d.object_classes.each do |object_class|
|
21
|
+
result.push [object_class, d]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Hash[result]
|
26
|
+
end
|
27
|
+
|
28
|
+
def find_drapper_for(resource)
|
29
|
+
object_klasses = ->(klass) {
|
30
|
+
return [klass] if self.root_classes.include? klass
|
31
|
+
Array.wrap(klass) + object_klasses[klass.superclass]
|
32
|
+
}
|
33
|
+
key = object_klasses[resource.class].find { |klass| self.descendants_with_targets.key?(klass) }
|
34
|
+
self.descendants_with_targets[key]
|
35
|
+
end
|
36
|
+
|
37
|
+
def root_classes
|
38
|
+
[ActiveRecord::Base, ActiveRecord::Relation, Array]
|
39
|
+
end
|
40
|
+
|
41
|
+
def engine_root
|
42
|
+
Rails.root
|
43
|
+
end
|
44
|
+
|
45
|
+
def descendant_files
|
46
|
+
Dir[descendant_path]
|
47
|
+
end
|
48
|
+
|
49
|
+
def descendant_root
|
50
|
+
engine_root.join('app', descendant_folder_name)
|
51
|
+
end
|
52
|
+
|
53
|
+
def descendant_folder_name
|
54
|
+
'glippers'
|
55
|
+
end
|
56
|
+
|
57
|
+
def descendant_file_mask
|
58
|
+
'*_glipper.rb'
|
59
|
+
end
|
60
|
+
|
61
|
+
def descendant_path
|
62
|
+
descendant_root.join('**', descendant_file_mask)
|
63
|
+
end
|
64
|
+
|
65
|
+
def decorates(*object_classes)
|
66
|
+
@object_classes = object_classes
|
67
|
+
end
|
68
|
+
|
69
|
+
def object_classes
|
70
|
+
@object_classes
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Glipper
|
2
|
+
module Helpers
|
3
|
+
def helpers
|
4
|
+
@helpers
|
5
|
+
end
|
6
|
+
alias_method :h, :helpers
|
7
|
+
|
8
|
+
def method_missing(name, *args, **options, &block)
|
9
|
+
if h.respond_to?(name)
|
10
|
+
h.public_send(name, *args, **options, &block)
|
11
|
+
else
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def respond_to_missing?(name, include_private = false)
|
17
|
+
h.respond_to?(name) || super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Glipper
|
2
|
+
module Initializer
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attr_reader :helpers
|
7
|
+
attr_reader :object
|
8
|
+
attr_reader :object_classes
|
9
|
+
alias_method :o, :object
|
10
|
+
alias_method :resource, :object
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def decorate(resource, helpers=ActionController::Base.helpers)
|
15
|
+
self.find_drapper_for(resource).new(resource, helpers)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(object, helpers=ActionController::Base.helpers)
|
20
|
+
raise "#{object} is not instance of #{@object_classes.join(', ')}" unless self.class.object_classes.find { |object_class| object.is_a?(object_class) }
|
21
|
+
@helpers = helpers
|
22
|
+
@object = object
|
23
|
+
end
|
24
|
+
|
25
|
+
def decorate(another_resource)
|
26
|
+
self.class.decorate(another_resource)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Glipper
|
2
|
+
module Validation
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
# module ApplicationHelper
|
6
|
+
# def glip(resource)
|
7
|
+
# glipper_class.decorate(resource, self)
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# def glipper_class
|
11
|
+
# ::Sample::ApplicationGlipper
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# def method_missing(name, *args, instead_nil: '', **params, &block)
|
15
|
+
# return super(name, *args, **params, &block) unless glipper_class.glip_method?(name, *args, **params, &block)
|
16
|
+
# return instead_nil.html_safe if glipper_class.glip_skip?(name, *args, **params, &block)
|
17
|
+
# return super(name, *args, **params, &block) unless glipper_class.glip_arguments?(name, *args, **params, &block)
|
18
|
+
#
|
19
|
+
# glip(args.first).public_send(glipper_class.glip_method_name(name), *args[1..-1], **params, &block)
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# def respond_to_missing?(name, include_private = false)
|
23
|
+
# glipper_class.glip_method?(name)
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
|
27
|
+
module ClassMethods
|
28
|
+
def glip_arguments?(name, *args, &block)
|
29
|
+
name.starts_with?('glip_')
|
30
|
+
end
|
31
|
+
|
32
|
+
def glip_method?(name, *args, &block)
|
33
|
+
name.starts_with?('glip_')
|
34
|
+
end
|
35
|
+
|
36
|
+
def glip_arguments?(name, *args, &block)
|
37
|
+
root_classes.any? { |k| args&.first.is_a?(k) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def glip_skip?(name, *args, &block)
|
41
|
+
name.starts_with?('glip_') && name.ends_with?('!') && args.first.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
def glip_method_name(name)
|
45
|
+
name.to_s.gsub(/!\z/, '').to_sym
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/glipper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: glipper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexey Osipenko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.1.1
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '8.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 4.1.1
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '8.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 2.2.33
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.2.33
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
description: Implementation of drapers for the rails views
|
62
|
+
email:
|
63
|
+
- alexey@cimon.io
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- ".gitignore"
|
69
|
+
- Gemfile
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.md
|
72
|
+
- glipper.gemspec
|
73
|
+
- lib/glipper.rb
|
74
|
+
- lib/glipper/base.rb
|
75
|
+
- lib/glipper/descedants.rb
|
76
|
+
- lib/glipper/helpers.rb
|
77
|
+
- lib/glipper/initializer.rb
|
78
|
+
- lib/glipper/validation.rb
|
79
|
+
- lib/glipper/version.rb
|
80
|
+
homepage: https://github.com/cimon-ci/glipper
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubygems_version: 3.2.3
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Implementation of drapers for the rails views
|
103
|
+
test_files: []
|