evt-configure 0.1.2.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/configure/activate.rb +17 -0
- data/lib/configure/controls/classes/keyword_argument.rb +33 -0
- data/lib/configure/controls/classes/no_arguments.rb +13 -0
- data/lib/configure/controls/classes/positional_argument.rb +33 -0
- data/lib/configure/controls/factory_method.rb +19 -0
- data/lib/configure/controls.rb +4 -0
- data/lib/configure/macro.rb +56 -0
- data/lib/configure.rb +2 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f3ec868f44b61d255834390a5c42219a8a3af7e
|
4
|
+
data.tar.gz: 44a9d0e25c95ac52e3f8df5f14de520ad89563f2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fa1af2697c3dc0a38c368c1265b3df966bcfc468f2ec4447a760bd7f815e30b597d1e60539dedf09541d5aee9c9b25bd924a2a538fa3f57a86f72c6dfb5a4dbb
|
7
|
+
data.tar.gz: 2c05e8b16d12f52dc5e3d1b2d4eebdb7cac2f6fa37c0de192cbbbee172edf5a6149fe444269172e57b9c6c94b76d338f6a5c985760837058261a32ce9511193b
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Configure
|
2
|
+
def self.activate(target_class=nil, factory_method: nil, constructor: nil)
|
3
|
+
target_class ||= Object
|
4
|
+
|
5
|
+
unless constructor.nil?
|
6
|
+
factory_method = constructor
|
7
|
+
end
|
8
|
+
|
9
|
+
macro_module = Configure::Macro
|
10
|
+
|
11
|
+
return if target_class.is_a? macro_module
|
12
|
+
|
13
|
+
target_class.extend(macro_module)
|
14
|
+
|
15
|
+
target_class.default_factory_method = factory_method
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Configure
|
2
|
+
module Controls
|
3
|
+
module Classes
|
4
|
+
class KeywordArgument
|
5
|
+
extend Configure::Macro
|
6
|
+
|
7
|
+
configure :some_attr_name
|
8
|
+
|
9
|
+
singleton_class.send :alias_method, :build, :new
|
10
|
+
|
11
|
+
attr_reader :arg
|
12
|
+
|
13
|
+
def initialize(arg:)
|
14
|
+
@arg = arg
|
15
|
+
end
|
16
|
+
|
17
|
+
class Optional
|
18
|
+
extend Configure::Macro
|
19
|
+
|
20
|
+
configure :some_attr_name
|
21
|
+
|
22
|
+
singleton_class.send :alias_method, :build, :new
|
23
|
+
|
24
|
+
attr_reader :arg
|
25
|
+
|
26
|
+
def initialize(arg: nil)
|
27
|
+
@arg = arg
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Configure
|
2
|
+
module Controls
|
3
|
+
module Classes
|
4
|
+
class PositionalArgument
|
5
|
+
extend Configure::Macro
|
6
|
+
|
7
|
+
configure :some_attr_name
|
8
|
+
|
9
|
+
singleton_class.send :alias_method, :build, :new
|
10
|
+
|
11
|
+
attr_reader :arg
|
12
|
+
|
13
|
+
def initialize(arg)
|
14
|
+
@arg = arg
|
15
|
+
end
|
16
|
+
|
17
|
+
class Optional
|
18
|
+
extend Configure::Macro
|
19
|
+
|
20
|
+
configure :some_attr_name
|
21
|
+
|
22
|
+
singleton_class.send :alias_method, :build, :new
|
23
|
+
|
24
|
+
attr_reader :arg
|
25
|
+
|
26
|
+
def initialize(arg=nil)
|
27
|
+
@arg = arg
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Configure
|
2
|
+
module Controls
|
3
|
+
module FactoryMethod
|
4
|
+
def make
|
5
|
+
instance = new
|
6
|
+
self.factory_method_called = true
|
7
|
+
instance
|
8
|
+
end
|
9
|
+
|
10
|
+
module Proof
|
11
|
+
attr_accessor :factory_method_called
|
12
|
+
|
13
|
+
def factory_method_called?
|
14
|
+
factory_method_called ? true : false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Configure
|
2
|
+
module Macro
|
3
|
+
def self.extended(cls)
|
4
|
+
cls.extend DefaultFactoryMethod
|
5
|
+
end
|
6
|
+
|
7
|
+
def configure_macro(receiver_attribute, factory_method: nil, constructor: nil, &build_action)
|
8
|
+
unless constructor.nil?
|
9
|
+
factory_method = constructor
|
10
|
+
end
|
11
|
+
|
12
|
+
factory_method ||= default_factory_method
|
13
|
+
|
14
|
+
singleton_class.class_exec receiver_attribute, factory_method do |receiver_attribute, factory_method|
|
15
|
+
|
16
|
+
unless build_action.nil?
|
17
|
+
define_method factory_method do |*args, **keyword_args|
|
18
|
+
if args.empty?
|
19
|
+
build_action.()
|
20
|
+
elsif keyword_args.empty?
|
21
|
+
build_action.(*args)
|
22
|
+
else
|
23
|
+
build_action.(*args, **keyword_args)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
define_method :configure do |receiver, *args, attr_name: nil, **keyword_args|
|
29
|
+
if receiver.is_a?(Symbol) && attr_name.nil? && args.empty? && keyword_args.empty?
|
30
|
+
return super receiver
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_name ||= receiver_attribute
|
34
|
+
|
35
|
+
if keyword_args.empty?
|
36
|
+
instance = public_send factory_method, *args
|
37
|
+
else
|
38
|
+
instance = public_send factory_method, *args, **keyword_args
|
39
|
+
end
|
40
|
+
|
41
|
+
receiver.public_send "#{attr_name}=", instance
|
42
|
+
instance
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
alias :configure :configure_macro
|
47
|
+
|
48
|
+
module DefaultFactoryMethod
|
49
|
+
attr_writer :default_factory_method
|
50
|
+
|
51
|
+
def default_factory_method
|
52
|
+
@default_factory_method ||= :build
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/configure.rb
ADDED
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: evt-configure
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- The Eventide Project
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: evt-telemetry-logger
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ntl-test_bench
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: " "
|
42
|
+
email: opensource@eventide-project.org
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/configure.rb
|
48
|
+
- lib/configure/activate.rb
|
49
|
+
- lib/configure/controls.rb
|
50
|
+
- lib/configure/controls/classes/keyword_argument.rb
|
51
|
+
- lib/configure/controls/classes/no_arguments.rb
|
52
|
+
- lib/configure/controls/classes/positional_argument.rb
|
53
|
+
- lib/configure/controls/factory_method.rb
|
54
|
+
- lib/configure/macro.rb
|
55
|
+
homepage: https://github.com/eventide-project/settings
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 2.3.3
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.5.2
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Generates class level configure methods
|
79
|
+
test_files: []
|