smart_initializer 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +19 -0
- data/.travis.yml +20 -0
- data/CHANGELOG.md +2 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +80 -0
- data/LICENSE.txt +21 -0
- data/README.md +55 -0
- data/Rakefile +21 -0
- data/bin/console +8 -0
- data/bin/setup +8 -0
- data/lib/smart_core/initializer.rb +24 -0
- data/lib/smart_core/initializer/attribute.rb +68 -0
- data/lib/smart_core/initializer/attribute/definer.rb +180 -0
- data/lib/smart_core/initializer/attribute/factory.rb +140 -0
- data/lib/smart_core/initializer/attribute/finalizer.rb +37 -0
- data/lib/smart_core/initializer/attribute/finalizer/anonymous_block.rb +32 -0
- data/lib/smart_core/initializer/attribute/finalizer/instance_method.rb +32 -0
- data/lib/smart_core/initializer/attribute/list.rb +64 -0
- data/lib/smart_core/initializer/attribute/parameters.rb +97 -0
- data/lib/smart_core/initializer/dsl.rb +110 -0
- data/lib/smart_core/initializer/errors.rb +19 -0
- data/lib/smart_core/initializer/version.rb +11 -0
- data/smart_initializer.gemspec +38 -0
- metadata +170 -0
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @api private
|
4
|
+
# @since 0.1.0
|
5
|
+
class SmartCore::Initializer::Attribute::Parameters
|
6
|
+
# @return [Hash<Symbol,Symbol>]
|
7
|
+
#
|
8
|
+
# @api private
|
9
|
+
# @since 0.1.0
|
10
|
+
PRIVACY_MODES = {
|
11
|
+
public: :public,
|
12
|
+
protected: :protected,
|
13
|
+
private: :private,
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
# @return [Symbol]
|
17
|
+
#
|
18
|
+
# @api private
|
19
|
+
# @since 0.1.0
|
20
|
+
DEFAULT_PRIVACY_MODE = PRIVACY_MODES[:public]
|
21
|
+
|
22
|
+
# @return [Boolean]
|
23
|
+
#
|
24
|
+
# @api private
|
25
|
+
# @since 0.1.0
|
26
|
+
DEFAULT_CAST_BEHAVIOUR = false
|
27
|
+
|
28
|
+
# @return [Proc]
|
29
|
+
#
|
30
|
+
# @api private
|
31
|
+
# @since 0.1.0
|
32
|
+
DEFAULT_FINALIZER = proc { |value| value }.freeze
|
33
|
+
|
34
|
+
# @return [Hash]
|
35
|
+
#
|
36
|
+
# @api private
|
37
|
+
# @since 0.1.0
|
38
|
+
DEFAULT_DYNAMIC_OPTIONS = {}.freeze
|
39
|
+
|
40
|
+
# @return [String]
|
41
|
+
#
|
42
|
+
# @api private
|
43
|
+
# @since 0.1.0
|
44
|
+
attr_reader :name
|
45
|
+
|
46
|
+
# @return [SmartCore::Types::Primitive]
|
47
|
+
#
|
48
|
+
# @api private
|
49
|
+
# @since 0.1.0
|
50
|
+
attr_reader :type
|
51
|
+
|
52
|
+
# @return [Symbol]
|
53
|
+
#
|
54
|
+
# @api private
|
55
|
+
# @since 0.1.0
|
56
|
+
attr_reader :privacy
|
57
|
+
|
58
|
+
# @return [SmartCore::Initializer::Attribute::Finalizer::AnonymousBlock]
|
59
|
+
# @return [SmartCore::Initializer::Attribute::Finalizer::InstanceMethod]
|
60
|
+
#
|
61
|
+
# @api private
|
62
|
+
# @since 0.1.0
|
63
|
+
attr_reader :finalizer
|
64
|
+
|
65
|
+
# @return [Boolean]
|
66
|
+
#
|
67
|
+
# @api private
|
68
|
+
# @since 0.1.0
|
69
|
+
attr_reader :cast
|
70
|
+
|
71
|
+
# @param name [String]
|
72
|
+
# @param type [SmartCore::Types::Primitive]
|
73
|
+
# @param privacy [Symbol]
|
74
|
+
# @param finalizer [SmartCore::Initializer::Attribute::AnonymousBlock/InstanceMethod]
|
75
|
+
# @param cast [Boolean]
|
76
|
+
# @param dynamic_options [Hash<Symbol,Any>]
|
77
|
+
# @return [void]
|
78
|
+
#
|
79
|
+
# @api private
|
80
|
+
# @since 0.1.0
|
81
|
+
def initialize(name, type, privacy, finalizer, cast, dynamic_options)
|
82
|
+
@name = name
|
83
|
+
@type = type
|
84
|
+
@privacy = privacy
|
85
|
+
@finalizer = finalizer
|
86
|
+
@cast = cast
|
87
|
+
@dynamic_options = dynamic_options
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
# @return [Hash<Symbol,Any>]
|
93
|
+
#
|
94
|
+
# @api private
|
95
|
+
# @since 0.1.0
|
96
|
+
attr_reader :dynamic_options
|
97
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @api private
|
4
|
+
# @since 0.1.0
|
5
|
+
module SmartCore::Initializer::DSL
|
6
|
+
class << self
|
7
|
+
# @param base_klass [Class]
|
8
|
+
# @return [void]
|
9
|
+
#
|
10
|
+
# @api private
|
11
|
+
# @since 0.1.0
|
12
|
+
def included(base_klass)
|
13
|
+
base_klass.instance_eval do
|
14
|
+
instance_variable_set(:@__params__, SmartCore::Initializer::Attribute::List.new)
|
15
|
+
instance_variable_set(:@__options__, SmartCore::Initializer::Attribute::List.new)
|
16
|
+
instance_variable_set(:@__definer__, SmartCore::Initializer::Attribute::Definer.new(self))
|
17
|
+
end
|
18
|
+
|
19
|
+
base_klass.extend(ClassMethods)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# @api private
|
24
|
+
# @since 0.1.0
|
25
|
+
module ClassMethods
|
26
|
+
# @return [SmartCore::Initializer::Attribute::List]
|
27
|
+
#
|
28
|
+
# @api private
|
29
|
+
# @since 0.1.0
|
30
|
+
def __params__
|
31
|
+
@__params__
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [SmartCore::Initializer::Attribute::List]
|
35
|
+
#
|
36
|
+
# @api private
|
37
|
+
# @since 0.1.0
|
38
|
+
def __options__
|
39
|
+
@__options__
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [SmartCore::Initializer::Attribute::Definer]
|
43
|
+
#
|
44
|
+
# @api private
|
45
|
+
# @since 0.1.0
|
46
|
+
def __definer__
|
47
|
+
@__definer__
|
48
|
+
end
|
49
|
+
|
50
|
+
# @param name [String, Symbol]
|
51
|
+
# @param type [String, Symbol, SmartCore::Types::Primitive]
|
52
|
+
# @option cast [Boolean]
|
53
|
+
# @option privacy [String, Symbol]
|
54
|
+
# @option finalize [String, Symbol, Proc]
|
55
|
+
# @param dynamic_options [Hash<Symbol,Any>]
|
56
|
+
# @return [void]
|
57
|
+
#
|
58
|
+
# @api public
|
59
|
+
# @since 0.1.0
|
60
|
+
def param(
|
61
|
+
name,
|
62
|
+
type = SmartCore::Types::Value::Any,
|
63
|
+
privacy: SmartCore::Initializer::Attribute::Parameters::DEFAULT_PRIVACY_MODE,
|
64
|
+
finalize: SmartCore::Initializer::Attribute::Parameters::DEFAULT_FINALIZER,
|
65
|
+
cast: SmartCore::Initializer::Attribute::Parameters::DEFAULT_CAST_BEHAVIOUR,
|
66
|
+
**dynamic_options
|
67
|
+
)
|
68
|
+
__definer__.define_parameter(name, type, privacy, finalize, cast, dynamic_options)
|
69
|
+
end
|
70
|
+
|
71
|
+
# @param names [Array<String, Symbol>]
|
72
|
+
# @return [void]
|
73
|
+
#
|
74
|
+
# @api public
|
75
|
+
# @since 0.1.0
|
76
|
+
def params(*names)
|
77
|
+
__definer__.define_parameters(*names)
|
78
|
+
end
|
79
|
+
|
80
|
+
# @param name [String, Symbol]
|
81
|
+
# @param type [String, Symbol, SmartCore::Types::Primitive]
|
82
|
+
# @option cast [Boolean]
|
83
|
+
# @option privacy [String, Symbol]
|
84
|
+
# @option finalize [String, Symbol, Proc]
|
85
|
+
# @param dynamic_options [Hash<Symbol,Any>]
|
86
|
+
# @return [void]
|
87
|
+
#
|
88
|
+
# @api public
|
89
|
+
# @since 0.1.0
|
90
|
+
def option(
|
91
|
+
name,
|
92
|
+
type = SmartCore::Types::Value::Any,
|
93
|
+
privacy: SmartCore::Initializer::Attribute::Parameters::DEFAULT_PRIVACY_MODE,
|
94
|
+
finalize: SmartCore::Initializer::Attribute::Parameters::DEFAULT_FINALIZER,
|
95
|
+
cast: SmartCore::Initializer::Attribute::Parameters::DEFAULT_CAST_BEHAVIOUR,
|
96
|
+
**dynamic_options
|
97
|
+
)
|
98
|
+
__definer__.define_option(name, type, privacy, finalize, cast, dynamic_options)
|
99
|
+
end
|
100
|
+
|
101
|
+
# @param names [Array<String, Symbol>]
|
102
|
+
# @return [void]
|
103
|
+
#
|
104
|
+
# @api public
|
105
|
+
# @since 0.1.0
|
106
|
+
def options(*names)
|
107
|
+
__definer__.define_options(*names)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SmartCore::Initializer
|
4
|
+
# @api public
|
5
|
+
# @since 0.1.0
|
6
|
+
Error = Class.new(SmartCore::Error)
|
7
|
+
|
8
|
+
# @api public
|
9
|
+
# @since 0.1.0
|
10
|
+
ArgumentError = Class.new(SmartCore::ArgumentError)
|
11
|
+
|
12
|
+
# @api public
|
13
|
+
# @since 0.1.0
|
14
|
+
OptionOverlapError = Class.new(ArgumentError)
|
15
|
+
|
16
|
+
# @api public
|
17
|
+
# @since 0.1.0
|
18
|
+
ParameterOverlapError = Class.new(ArgumentError)
|
19
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/smart_core/initializer/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.9')
|
7
|
+
|
8
|
+
spec.name = 'smart_initializer'
|
9
|
+
spec.version = SmartCore::Initializer::VERSION
|
10
|
+
spec.authors = ['Rustam Ibragimov']
|
11
|
+
spec.email = ['iamdaiver@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Initializer DSL'
|
14
|
+
spec.description = 'A simple and convenient way to declare complex constructors.'
|
15
|
+
spec.homepage = 'https://github.com/smart-rb/smart_initialier'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
spec.metadata['source_code_uri'] = 'https://github.com/smart-rb/smart_initializer'
|
20
|
+
spec.metadata['changelog_uri'] = 'https://github.com/smart-rb/smart_initializer/blob/master/CHANGELOG.md'
|
21
|
+
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.add_dependency 'smart_engine', '~> 0.4'
|
31
|
+
spec.add_dependency 'smart_types', '~> 0.1.0.alpha'
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 2.1'
|
34
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.9'
|
36
|
+
spec.add_development_dependency 'armitage-rubocop', '~> 0.78'
|
37
|
+
spec.add_development_dependency 'simplecov', '~> 0.17'
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smart_initializer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rustam Ibragimov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: smart_engine
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: smart_types
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.0.alpha
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.0.alpha
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '13.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '13.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: armitage-rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.78'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.78'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.17'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.17'
|
111
|
+
description: A simple and convenient way to declare complex constructors.
|
112
|
+
email:
|
113
|
+
- iamdaiver@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".rubocop.yml"
|
121
|
+
- ".travis.yml"
|
122
|
+
- CHANGELOG.md
|
123
|
+
- CODE_OF_CONDUCT.md
|
124
|
+
- Gemfile
|
125
|
+
- Gemfile.lock
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- bin/console
|
130
|
+
- bin/setup
|
131
|
+
- lib/smart_core/initializer.rb
|
132
|
+
- lib/smart_core/initializer/attribute.rb
|
133
|
+
- lib/smart_core/initializer/attribute/definer.rb
|
134
|
+
- lib/smart_core/initializer/attribute/factory.rb
|
135
|
+
- lib/smart_core/initializer/attribute/finalizer.rb
|
136
|
+
- lib/smart_core/initializer/attribute/finalizer/anonymous_block.rb
|
137
|
+
- lib/smart_core/initializer/attribute/finalizer/instance_method.rb
|
138
|
+
- lib/smart_core/initializer/attribute/list.rb
|
139
|
+
- lib/smart_core/initializer/attribute/parameters.rb
|
140
|
+
- lib/smart_core/initializer/dsl.rb
|
141
|
+
- lib/smart_core/initializer/errors.rb
|
142
|
+
- lib/smart_core/initializer/version.rb
|
143
|
+
- smart_initializer.gemspec
|
144
|
+
homepage: https://github.com/smart-rb/smart_initialier
|
145
|
+
licenses:
|
146
|
+
- MIT
|
147
|
+
metadata:
|
148
|
+
homepage_uri: https://github.com/smart-rb/smart_initialier
|
149
|
+
source_code_uri: https://github.com/smart-rb/smart_initializer
|
150
|
+
changelog_uri: https://github.com/smart-rb/smart_initializer/blob/master/CHANGELOG.md
|
151
|
+
post_install_message:
|
152
|
+
rdoc_options: []
|
153
|
+
require_paths:
|
154
|
+
- lib
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 2.4.9
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
requirements: []
|
166
|
+
rubygems_version: 3.1.2
|
167
|
+
signing_key:
|
168
|
+
specification_version: 4
|
169
|
+
summary: Initializer DSL
|
170
|
+
test_files: []
|