AR2H 0.0.0
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 +10 -0
- data/AR2H.gemspec +28 -0
- data/Gemfile +3 -0
- data/README.md +28 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/AR2H.rb +7 -0
- data/lib/AR2H/executor.rb +44 -0
- data/lib/AR2H/extensions/base.rb +31 -0
- data/lib/AR2H/extensions/relation.rb +15 -0
- data/lib/AR2H/hashers/collection.rb +37 -0
- data/lib/AR2H/hashers/hasher.rb +20 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1ddcf2999c0a5f1d385fa137606b3a12823e6fea
|
4
|
+
data.tar.gz: 0dad5c3f0262e3d7e383436f9335fda42f8e1668
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 225b070df89f6c25865c136550f0fe25c1cfd0a6ea7ba270894dd373c76f5bde1af47013a2153db3c71cc7a707f1d57c85fd0e1341f57d2c2444e1b4a0ec6a42
|
7
|
+
data.tar.gz: d3cc358a946eb4ca388afb67eeaf3be46b7b422dcfeea1a3d5ea4c4b9a2e449a5ca05d00fcc9425dec643748e6e46c43a2be57cae712a9b570f25f2fadc17f67
|
data/.gitignore
ADDED
data/AR2H.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'AR2H'
|
7
|
+
spec.version = '0.0.0'
|
8
|
+
spec.authors = ['Eugene Yak']
|
9
|
+
spec.email = ['GeneAYak@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = ''
|
12
|
+
spec.description = ''
|
13
|
+
spec.homepage = 'https://gitlab.com/yak/AR2H'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
25
|
+
|
26
|
+
spec.add_runtime_dependency 'activerecord'
|
27
|
+
spec.add_runtime_dependency 'activesupport'
|
28
|
+
end
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# AR2H
|
2
|
+
|
3
|
+
Describe: TODO
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'AR2H'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install AR2H
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Usage: TODO
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
Bug reports and pull requests are welcome on GitLab at https://gitlab.com/yak/AR2H.
|
28
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "AR2H"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/AR2H.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module AR2H
|
2
|
+
class Executor
|
3
|
+
def self.run(object, hasher)
|
4
|
+
self.new(object, hasher).execute
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(object, hasher)
|
8
|
+
@object = object
|
9
|
+
@hasher = object.hashers.find hasher
|
10
|
+
@result = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :object
|
14
|
+
|
15
|
+
def execute
|
16
|
+
instance_eval &@hasher.block
|
17
|
+
@result
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def attr(attr)
|
23
|
+
@result[attr] = block_given? ? yield : object[attr]
|
24
|
+
end
|
25
|
+
|
26
|
+
def attrs(*attrs)
|
27
|
+
attrs.each { |attr| attr(attr) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def has_one(node)
|
31
|
+
node(node)
|
32
|
+
end
|
33
|
+
|
34
|
+
def has_many(node)
|
35
|
+
node(node)
|
36
|
+
end
|
37
|
+
|
38
|
+
def branch(node)
|
39
|
+
hasher = block_given? ? yield : @hasher.name
|
40
|
+
@result[node] = object.send(node).hasherize(hasher)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module AR2H
|
2
|
+
module Extensions
|
3
|
+
module Base
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def hasherize(hasher = :default)
|
7
|
+
# require 'AR2H/executor'
|
8
|
+
logger.info { " Hashing #{self.class}" }
|
9
|
+
Executor.run(self, hasher)
|
10
|
+
end
|
11
|
+
|
12
|
+
def hashers
|
13
|
+
self.class.hashers
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
# require 'AR2H/hashers'
|
18
|
+
|
19
|
+
def hasher(name = :default, &block)
|
20
|
+
hashers.add Hashers::Hasher.new(name, block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def hashers
|
24
|
+
@hashers ||= Hashers::Collection.new(self.name)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
ActiveRecord::Base.send :include, Base
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module AR2H
|
2
|
+
module Extensions
|
3
|
+
module Relation
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def hasherize(hasher = :default)
|
7
|
+
logger.info { " Hashing #{self.model.to_s.pluralize}" }
|
8
|
+
self.map { |e| Executor.run(e, hasher) }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
ActiveRecord::Relation.send :include, Relation
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module AR2H
|
2
|
+
module Hashers
|
3
|
+
class Collection
|
4
|
+
def initialize(label)
|
5
|
+
@label = label
|
6
|
+
@hashers = Array.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def add(hasher)
|
10
|
+
raise Exception.new('NOT hasher') if hasher.class != Hasher
|
11
|
+
if self.include? hasher.name
|
12
|
+
raise Exception.new('DOUBLING hasher')
|
13
|
+
else
|
14
|
+
@hashers << hasher
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def include?(name)
|
19
|
+
list.include? name
|
20
|
+
end
|
21
|
+
|
22
|
+
def all
|
23
|
+
@hashers
|
24
|
+
end
|
25
|
+
|
26
|
+
def list
|
27
|
+
@hashers.map{ |hasher| hasher.name }
|
28
|
+
end
|
29
|
+
|
30
|
+
def find(name)
|
31
|
+
hasher = @hashers.find{ |hasher| hasher.name == name }
|
32
|
+
raise Exception.new("#{@label}: hasher :#{name} NOT FOUND") unless hasher
|
33
|
+
hasher
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: AR2H
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eugene Yak
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: ''
|
84
|
+
email:
|
85
|
+
- GeneAYak@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- AR2H.gemspec
|
92
|
+
- Gemfile
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- lib/AR2H.rb
|
98
|
+
- lib/AR2H/executor.rb
|
99
|
+
- lib/AR2H/extensions/base.rb
|
100
|
+
- lib/AR2H/extensions/relation.rb
|
101
|
+
- lib/AR2H/hashers/collection.rb
|
102
|
+
- lib/AR2H/hashers/hasher.rb
|
103
|
+
homepage: https://gitlab.com/yak/AR2H
|
104
|
+
licenses: []
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.5.1
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: ''
|
126
|
+
test_files: []
|