abstracts 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/lib/abstracts.rb +43 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3b234002c8e5eea46a96985ba2a59e58a6598436
|
4
|
+
data.tar.gz: c85fb1cbed920896dc89c2e92a4704bbca47a3bf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 637066eb1cadd8f765a520c57c23aeb0993e44942699b43bac7ddd83d3d20702090db5c8293bb5371df7e9e59d008d2f9248e17bbb589fd0f668f0e831044476
|
7
|
+
data.tar.gz: 55ee18a21000e176b8e6174a90134b5451b56629f6694f194127d1c2d7a9fe963880c1fb5954586b3839d87faa10d8e302216c18a1b3aa670b460beae7f51346
|
data/lib/abstracts.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Abstract module: have to be moved somewhere to core
|
2
|
+
module Abstract
|
3
|
+
# AbstractObject class
|
4
|
+
class Object
|
5
|
+
# Get an array of attr_accessor names besides class name itself
|
6
|
+
# @return [Array] - Array of attribute accessor methods
|
7
|
+
def attrs
|
8
|
+
self.class.instance_eval do
|
9
|
+
@attrs.each do |attr|
|
10
|
+
attr_accessor attr
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# AbstractBuilder class
|
17
|
+
class Builder
|
18
|
+
attr_reader :object,
|
19
|
+
:attrs
|
20
|
+
|
21
|
+
# Create an instance of AbstractObject class and yield block to it
|
22
|
+
# @return @object [AbstractObject] - AbstractObject class instance
|
23
|
+
def self.build
|
24
|
+
builder = new(@build_class)
|
25
|
+
yield builder if block_given?
|
26
|
+
builder.object
|
27
|
+
end
|
28
|
+
|
29
|
+
# Define attribute writers to Builder instance according to
|
30
|
+
# existing accessors of AbstractObject instance
|
31
|
+
# @param object [AbstractObject] - AbstractObject instance
|
32
|
+
# @return [AbstractBuilder] - builder object
|
33
|
+
def initialize(object)
|
34
|
+
@object = Class.const_get(object).new
|
35
|
+
@attrs = @object.attrs
|
36
|
+
@object.attrs.each do |attr|
|
37
|
+
define_singleton_method "#{attr}=" do |param|
|
38
|
+
@object.public_send("#{attr}=", param)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: abstracts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vsevolod Suzdaltsev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Abstract classes gem
|
14
|
+
email: suzdaltsev_v@mail.ru
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/abstracts.rb
|
20
|
+
homepage: http://rubygems.org/gems/abstracts
|
21
|
+
licenses: []
|
22
|
+
metadata: {}
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
requirements: []
|
38
|
+
rubyforge_project:
|
39
|
+
rubygems_version: 2.6.6
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Abstract classes
|
43
|
+
test_files: []
|