cmdlet 0.0.7 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.builders/.templates/cmdlet.rb +26 -0
- data/.builders/.templates/{command_spec.rb → cmdlet_spec.rb} +4 -4
- data/.builders/.templates/require_all_cmdlets.rb +5 -0
- data/.builders/_.rb +7 -1
- data/.builders/boot.rb +2 -0
- data/.builders/data/categories.json +2 -10
- data/.builders/data/cmdlets/array.json +121 -0
- data/.builders/data/cmdlets/comparison.json +245 -0
- data/.builders/director/category_builder.rb +26 -0
- data/.builders/director/category_dao.rb +38 -0
- data/.builders/director/category_director.rb +24 -10
- data/.builders/director/cmdlet_builder.rb +27 -34
- data/.builders/director/cmdlet_child.rb +16 -44
- data/.builders/director/cmdlet_dao.rb +29 -0
- data/.builders/director/cmdlet_director.rb +37 -13
- data/.builders/director/dao.rb +16 -0
- data/.builders/documents/commands.rb +15 -16
- data/.builders/documents/use_cases.rb +32 -34
- data/.builders/documents/x_functions.rb +7 -10
- data/.builders/generators/01-bootstrap.rb +112 -112
- data/.builders/generators/20-categories.rb +16 -0
- data/.builders/generators/30-commands-bak.rb +53 -0
- data/.builders/generators/cmdlets/array.rb +109 -0
- data/.builders/generators/cmdlets/comparison.rb +164 -0
- data/CHANGELOG.md +22 -0
- data/Guardfile +1 -1
- data/lib/cmdlet/_.rb +14 -0
- data/lib/cmdlet/array/join.rb +8 -10
- data/lib/cmdlet/array/join_post.rb +22 -0
- data/lib/cmdlet/array/join_pre.rb +22 -0
- data/lib/cmdlet/base_cmdlet.rb +17 -0
- data/lib/cmdlet/comparison/and.rb +16 -0
- data/lib/cmdlet/comparison/default.rb +20 -0
- data/lib/cmdlet/comparison/eq.rb +20 -0
- data/lib/cmdlet/comparison/gt.rb +17 -0
- data/lib/cmdlet/comparison/gte.rb +17 -0
- data/lib/cmdlet/comparison/lt.rb +17 -0
- data/lib/cmdlet/comparison/lte.rb +17 -0
- data/lib/cmdlet/comparison/ne.rb +20 -0
- data/lib/cmdlet/comparison/or.rb +16 -0
- data/lib/cmdlet/version.rb +1 -1
- data/lib/cmdlet.rb +3 -0
- data/package-lock.json +2 -2
- data/package.json +1 -1
- metadata +28 -9
- data/.builders/.templates/all_commands.rb +0 -5
- data/.builders/.templates/command.rb +0 -26
- data/.builders/documents/categories.rb +0 -24
- data/.builders/documents/cmdlets.rb +0 -30
- data/.builders/generators/20-commands.rb +0 -54
- data/.builders/generators/25-categories.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4aaf22abcff261a22b71b4c4adeaf77dd8d629836936eabb1b20b2d8a61b3a28
|
4
|
+
data.tar.gz: 4d249fee0dd48b4774881e16bcc92b303f788e45b22c54c14a321a70468bcabf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab39c705f59887093ecbf3a8ad2ec66f133bf14048f544b142b3de324fdb25006dfa19bb66efdf5e281d0167bac8b4bd2958769cff3ad8879515f833f24fa5d5
|
7
|
+
data.tar.gz: e78c0098b63350dfcc77bb7c6c50d902b8da963a9fc8531639a5c6835df4fdae3158b8518f2efd2f87a2fda9dfd9fb3a573f774159c04fad451dca50da09ac43
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cmdlet
|
4
|
+
# {{cmdlet.category_description}}
|
5
|
+
module {{camel cmdlet.category}}
|
6
|
+
# {{camel cmdlet.name}}: {{cmdlet.description}}
|
7
|
+
class {{camel cmdlet.name}} < Cmdlet::BaseCmdlet
|
8
|
+
{{#each cmdlet.usecases}}
|
9
|
+
# @example
|
10
|
+
#
|
11
|
+
# puts {{camel ./function}}.new.call({{{nice_inputs}}})
|
12
|
+
#
|
13
|
+
# {{expected_output}}
|
14
|
+
#
|
15
|
+
{{/each}}
|
16
|
+
#
|
17
|
+
{{#each cmdlet.parameters}}
|
18
|
+
# @param [{{./param_type}}] {{./name}} - {{./description}}
|
19
|
+
{{/each}}
|
20
|
+
# @return [String] {{cmdlet.result}}
|
21
|
+
def call({{#each cmdlet.parameters}}{{#if ./splat}}{{./splat}}{{/if}}{{./name}}{{#if ./default}} = {{{./default}}}{{/if}}{{#if @last}}{{^}}, {{/if}}{{/each}})
|
22
|
+
{{{cmdlet.ruby}}}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# {{camel
|
4
|
-
RSpec.describe
|
3
|
+
# {{camel cmdlet.name}}: {{cmdlet.description}}
|
4
|
+
RSpec.describe Cmdlet::{{camel cmdlet.category}}::{{camel cmdlet.name}} do
|
5
5
|
let(:instance) { described_class.new }
|
6
6
|
|
7
7
|
describe 'initialize' do
|
@@ -10,8 +10,8 @@ RSpec.describe Funcky::{{camel command.category}}::{{camel command.name}} do
|
|
10
10
|
it { is_expected.not_to be_nil }
|
11
11
|
end
|
12
12
|
|
13
|
-
describe '#
|
14
|
-
subject { instance.
|
13
|
+
describe '#call' do
|
14
|
+
subject { instance.call(value) }
|
15
15
|
|
16
16
|
let(:value) { nil }
|
17
17
|
|
data/.builders/_.rb
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './director/category_dao'
|
4
|
+
require_relative './director/cmdlet_dao'
|
5
|
+
require_relative './director/dao'
|
6
|
+
|
7
|
+
require_relative './director/category_builder'
|
2
8
|
require_relative './director/category_director'
|
3
9
|
require_relative './director/cmdlet_builder'
|
4
10
|
require_relative './director/cmdlet_director'
|
data/.builders/boot.rb
CHANGED
@@ -17,20 +17,12 @@
|
|
17
17
|
"description": "String handling helpers"
|
18
18
|
},
|
19
19
|
{
|
20
|
-
"name": "
|
20
|
+
"name": "array",
|
21
21
|
"description": "Array handling routines, eg. join, join_prefix, join_post"
|
22
22
|
},
|
23
23
|
{
|
24
|
-
"name": "
|
24
|
+
"name": "transform",
|
25
25
|
"description": "Tokenize and apply case and/or separator"
|
26
|
-
},
|
27
|
-
{
|
28
|
-
"name": "a_comparison",
|
29
|
-
"description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc."
|
30
|
-
},
|
31
|
-
{
|
32
|
-
"name": "a_inflection",
|
33
|
-
"description": "Inflection handling routines, eg. pluralize, singular, ordinalize"
|
34
26
|
}
|
35
27
|
]
|
36
28
|
}
|
@@ -0,0 +1,121 @@
|
|
1
|
+
{
|
2
|
+
"category_key": "array",
|
3
|
+
"cmdlets": [
|
4
|
+
{
|
5
|
+
"name": "join",
|
6
|
+
"description": "join an array of values with separator as a string",
|
7
|
+
"result": "new String formed by joining the array elements with seperator",
|
8
|
+
"category": "array",
|
9
|
+
"category_description": "Array handling routines, eg. join, join_prefix, join_post",
|
10
|
+
"base_class_require": null,
|
11
|
+
"base_class": null,
|
12
|
+
"parameters": [
|
13
|
+
{
|
14
|
+
"name": "values",
|
15
|
+
"description": "array of values to join",
|
16
|
+
"splat": null,
|
17
|
+
"default": null,
|
18
|
+
"param_type": "String|Int"
|
19
|
+
},
|
20
|
+
{
|
21
|
+
"name": "separator",
|
22
|
+
"description": "separator between values, defaults to comma",
|
23
|
+
"splat": null,
|
24
|
+
"default": "','",
|
25
|
+
"param_type": "String"
|
26
|
+
}
|
27
|
+
],
|
28
|
+
"examples": [
|
29
|
+
|
30
|
+
],
|
31
|
+
"ruby": " return false if values.nil? || values.length == 0\n values = values.reject(&:blank?)\n return '' if values.length.zero?\n\n values.join(separator)\n"
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"name": "join_pre",
|
35
|
+
"description": "join an array of values with separator as a string and using the separator at the beginning of string",
|
36
|
+
"result": null,
|
37
|
+
"category": "array",
|
38
|
+
"category_description": "Array handling routines, eg. join, join_prefix, join_post",
|
39
|
+
"base_class_require": null,
|
40
|
+
"base_class": null,
|
41
|
+
"parameters": [
|
42
|
+
{
|
43
|
+
"name": "values",
|
44
|
+
"description": "array of values to join",
|
45
|
+
"splat": null,
|
46
|
+
"default": null,
|
47
|
+
"param_type": "String|Int"
|
48
|
+
},
|
49
|
+
{
|
50
|
+
"name": "separator",
|
51
|
+
"description": "separator between values, defaults to comma",
|
52
|
+
"splat": null,
|
53
|
+
"default": "','",
|
54
|
+
"param_type": "String"
|
55
|
+
}
|
56
|
+
],
|
57
|
+
"examples": [
|
58
|
+
|
59
|
+
],
|
60
|
+
"ruby": " return '' if values.nil? || !values.is_a?(::Array)\n values = values.reject(&:blank?)\n return '' if values.length.zero?\n\n \"#{separator}#{values.join(separator)}\"\n"
|
61
|
+
},
|
62
|
+
{
|
63
|
+
"name": "join_pre",
|
64
|
+
"description": "join an array of values with separator as a string and using the separator at the beginning of string",
|
65
|
+
"result": null,
|
66
|
+
"category": "array",
|
67
|
+
"category_description": "Array handling routines, eg. join, join_prefix, join_post",
|
68
|
+
"base_class_require": null,
|
69
|
+
"base_class": null,
|
70
|
+
"parameters": [
|
71
|
+
{
|
72
|
+
"name": "values",
|
73
|
+
"description": "array of values to join",
|
74
|
+
"splat": null,
|
75
|
+
"default": null,
|
76
|
+
"param_type": "String|Int"
|
77
|
+
},
|
78
|
+
{
|
79
|
+
"name": "separator",
|
80
|
+
"description": "separator between values, defaults to comma",
|
81
|
+
"splat": null,
|
82
|
+
"default": "','",
|
83
|
+
"param_type": "String"
|
84
|
+
}
|
85
|
+
],
|
86
|
+
"examples": [
|
87
|
+
|
88
|
+
],
|
89
|
+
"ruby": " return '' if values.nil? || !values.is_a?(::Array)\n values = values.reject(&:blank?)\n return '' if values.length.zero?\n\n \"#{separator}#{values.join(separator)}\"\n"
|
90
|
+
},
|
91
|
+
{
|
92
|
+
"name": "join_post",
|
93
|
+
"description": "join an array of values with separator as a string and using the separator at the end of string",
|
94
|
+
"result": null,
|
95
|
+
"category": "array",
|
96
|
+
"category_description": "Array handling routines, eg. join, join_prefix, join_post",
|
97
|
+
"base_class_require": null,
|
98
|
+
"base_class": null,
|
99
|
+
"parameters": [
|
100
|
+
{
|
101
|
+
"name": "values",
|
102
|
+
"description": "array of values to join",
|
103
|
+
"splat": null,
|
104
|
+
"default": null,
|
105
|
+
"param_type": "String|Int"
|
106
|
+
},
|
107
|
+
{
|
108
|
+
"name": "separator",
|
109
|
+
"description": "separator between values, defaults to comma",
|
110
|
+
"splat": null,
|
111
|
+
"default": "','",
|
112
|
+
"param_type": "String"
|
113
|
+
}
|
114
|
+
],
|
115
|
+
"examples": [
|
116
|
+
|
117
|
+
],
|
118
|
+
"ruby": " return '' if values.nil? || !values.is_a?(::Array)\n values = values.reject(&:blank?)\n return '' if values.length.zero?\n\n \"#{values.join(separator)}#{separator}\"\n"
|
119
|
+
}
|
120
|
+
]
|
121
|
+
}
|
@@ -0,0 +1,245 @@
|
|
1
|
+
{
|
2
|
+
"category_key": "comparison",
|
3
|
+
"cmdlets": [
|
4
|
+
{
|
5
|
+
"name": "and",
|
6
|
+
"description": "Return true if **all of** the given values are truthy.",
|
7
|
+
"result": "return true when every value is truthy",
|
8
|
+
"category": "comparison",
|
9
|
+
"category_description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.",
|
10
|
+
"base_class_require": null,
|
11
|
+
"base_class": null,
|
12
|
+
"parameters": [
|
13
|
+
{
|
14
|
+
"name": "values",
|
15
|
+
"description": "list of values (via *splat) to be checked via AND condition",
|
16
|
+
"splat": "*",
|
17
|
+
"default": null,
|
18
|
+
"param_type": "Object"
|
19
|
+
}
|
20
|
+
],
|
21
|
+
"examples": [
|
22
|
+
|
23
|
+
],
|
24
|
+
"ruby": " values.all? { |value| value }\n"
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"name": "default",
|
28
|
+
"description": "Return true if **all of** the given values are truthy.",
|
29
|
+
"result": "return true when every value is truthy",
|
30
|
+
"category": "comparison",
|
31
|
+
"category_description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.",
|
32
|
+
"base_class_require": null,
|
33
|
+
"base_class": null,
|
34
|
+
"parameters": [
|
35
|
+
{
|
36
|
+
"name": "values",
|
37
|
+
"description": "one or more paramaters that may or may not contain nil",
|
38
|
+
"splat": "*",
|
39
|
+
"default": null,
|
40
|
+
"param_type": "Object"
|
41
|
+
}
|
42
|
+
],
|
43
|
+
"examples": [
|
44
|
+
|
45
|
+
],
|
46
|
+
"ruby": " default_value = values[-1]\n\n find_value = values[0..-2].find { |value| !value.nil? }\n\n find_value || default_value\n"
|
47
|
+
},
|
48
|
+
{
|
49
|
+
"name": "eq",
|
50
|
+
"description": "Return true if two values are equal",
|
51
|
+
"result": "return truthy value if left hand side equals right hand side",
|
52
|
+
"category": "comparison",
|
53
|
+
"category_description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.",
|
54
|
+
"base_class_require": null,
|
55
|
+
"base_class": null,
|
56
|
+
"parameters": [
|
57
|
+
{
|
58
|
+
"name": "lhs",
|
59
|
+
"description": "lhs - left hand side value",
|
60
|
+
"splat": null,
|
61
|
+
"default": null,
|
62
|
+
"param_type": "Object"
|
63
|
+
},
|
64
|
+
{
|
65
|
+
"name": "rhs",
|
66
|
+
"description": "rhs - right hand side value",
|
67
|
+
"splat": null,
|
68
|
+
"default": null,
|
69
|
+
"param_type": "Object"
|
70
|
+
}
|
71
|
+
],
|
72
|
+
"examples": [
|
73
|
+
|
74
|
+
],
|
75
|
+
"ruby": " lhs = lhs.to_s if lhs.is_a?(Symbol)\n rhs = rhs.to_s if rhs.is_a?(Symbol)\n\n lhs == rhs\n"
|
76
|
+
},
|
77
|
+
{
|
78
|
+
"name": "gt",
|
79
|
+
"description": "Return true if left hand side GREATER THAN right hand side",
|
80
|
+
"result": "truthy value if left hand side GREATER THAN right hand side",
|
81
|
+
"category": "comparison",
|
82
|
+
"category_description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.",
|
83
|
+
"base_class_require": null,
|
84
|
+
"base_class": null,
|
85
|
+
"parameters": [
|
86
|
+
{
|
87
|
+
"name": "lhs",
|
88
|
+
"description": "lhs - left hand side value",
|
89
|
+
"splat": null,
|
90
|
+
"default": null,
|
91
|
+
"param_type": "Object"
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"name": "rhs",
|
95
|
+
"description": "rhs - right hand side value",
|
96
|
+
"splat": null,
|
97
|
+
"default": null,
|
98
|
+
"param_type": "Object"
|
99
|
+
}
|
100
|
+
],
|
101
|
+
"examples": [
|
102
|
+
|
103
|
+
],
|
104
|
+
"ruby": " lhs > rhs\n"
|
105
|
+
},
|
106
|
+
{
|
107
|
+
"name": "gte",
|
108
|
+
"description": "Return true if left hand side GREATER THAN or EQUAL TO right hand side",
|
109
|
+
"result": "truthy value if left hand side GREATER THAN or EQUAL TO right hand side",
|
110
|
+
"category": "comparison",
|
111
|
+
"category_description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.",
|
112
|
+
"base_class_require": null,
|
113
|
+
"base_class": null,
|
114
|
+
"parameters": [
|
115
|
+
{
|
116
|
+
"name": "lhs",
|
117
|
+
"description": "lhs - left hand side value",
|
118
|
+
"splat": null,
|
119
|
+
"default": null,
|
120
|
+
"param_type": "Object"
|
121
|
+
},
|
122
|
+
{
|
123
|
+
"name": "rhs",
|
124
|
+
"description": "rhs - right hand side value",
|
125
|
+
"splat": null,
|
126
|
+
"default": null,
|
127
|
+
"param_type": "Object"
|
128
|
+
}
|
129
|
+
],
|
130
|
+
"examples": [
|
131
|
+
|
132
|
+
],
|
133
|
+
"ruby": " lhs >= rhs\n"
|
134
|
+
},
|
135
|
+
{
|
136
|
+
"name": "lt",
|
137
|
+
"description": "Return true if left hand side LESS THAN right hand side",
|
138
|
+
"result": "truthy value if left hand side LESS THAN right hand side",
|
139
|
+
"category": "comparison",
|
140
|
+
"category_description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.",
|
141
|
+
"base_class_require": null,
|
142
|
+
"base_class": null,
|
143
|
+
"parameters": [
|
144
|
+
{
|
145
|
+
"name": "lhs",
|
146
|
+
"description": "lhs - left hand side value",
|
147
|
+
"splat": null,
|
148
|
+
"default": null,
|
149
|
+
"param_type": "Object"
|
150
|
+
},
|
151
|
+
{
|
152
|
+
"name": "rhs",
|
153
|
+
"description": "rhs - right hand side value",
|
154
|
+
"splat": null,
|
155
|
+
"default": null,
|
156
|
+
"param_type": "Object"
|
157
|
+
}
|
158
|
+
],
|
159
|
+
"examples": [
|
160
|
+
|
161
|
+
],
|
162
|
+
"ruby": " lhs < rhs\n"
|
163
|
+
},
|
164
|
+
{
|
165
|
+
"name": "lte",
|
166
|
+
"description": "Return true if left hand side LESS THAN or EQUAL TO right hand side",
|
167
|
+
"result": "truthy value if left hand side LESS THAN or EQUAL TO right hand side",
|
168
|
+
"category": "comparison",
|
169
|
+
"category_description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.",
|
170
|
+
"base_class_require": null,
|
171
|
+
"base_class": null,
|
172
|
+
"parameters": [
|
173
|
+
{
|
174
|
+
"name": "lhs",
|
175
|
+
"description": "lhs - left hand side value",
|
176
|
+
"splat": null,
|
177
|
+
"default": null,
|
178
|
+
"param_type": "Object"
|
179
|
+
},
|
180
|
+
{
|
181
|
+
"name": "rhs",
|
182
|
+
"description": "rhs - right hand side value",
|
183
|
+
"splat": null,
|
184
|
+
"default": null,
|
185
|
+
"param_type": "Object"
|
186
|
+
}
|
187
|
+
],
|
188
|
+
"examples": [
|
189
|
+
|
190
|
+
],
|
191
|
+
"ruby": " lhs <= rhs\n"
|
192
|
+
},
|
193
|
+
{
|
194
|
+
"name": "ne",
|
195
|
+
"description": "Return true if left hand side is NOT equal to right hand side",
|
196
|
+
"result": "truthy value if left hand side is NOT equal to right hand side",
|
197
|
+
"category": "comparison",
|
198
|
+
"category_description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.",
|
199
|
+
"base_class_require": null,
|
200
|
+
"base_class": null,
|
201
|
+
"parameters": [
|
202
|
+
{
|
203
|
+
"name": "lhs",
|
204
|
+
"description": "lhs - left hand side value",
|
205
|
+
"splat": null,
|
206
|
+
"default": null,
|
207
|
+
"param_type": "Object"
|
208
|
+
},
|
209
|
+
{
|
210
|
+
"name": "rhs",
|
211
|
+
"description": "rhs - right hand side value",
|
212
|
+
"splat": null,
|
213
|
+
"default": null,
|
214
|
+
"param_type": "Object"
|
215
|
+
}
|
216
|
+
],
|
217
|
+
"examples": [
|
218
|
+
|
219
|
+
],
|
220
|
+
"ruby": " lhs = lhs.to_s if lhs.is_a?(Symbol)\n rhs = rhs.to_s if rhs.is_a?(Symbol)\n\n lhs != rhs\n"
|
221
|
+
},
|
222
|
+
{
|
223
|
+
"name": "or",
|
224
|
+
"description": "Return true if any value is truthy.",
|
225
|
+
"result": "return true when first value is truthy",
|
226
|
+
"category": "comparison",
|
227
|
+
"category_description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.",
|
228
|
+
"base_class_require": null,
|
229
|
+
"base_class": null,
|
230
|
+
"parameters": [
|
231
|
+
{
|
232
|
+
"name": "values",
|
233
|
+
"description": "list of values (via *splat) to be checked via AND condition",
|
234
|
+
"splat": "*",
|
235
|
+
"default": null,
|
236
|
+
"param_type": "Object"
|
237
|
+
}
|
238
|
+
],
|
239
|
+
"examples": [
|
240
|
+
|
241
|
+
],
|
242
|
+
"ruby": " values.any? { |value| value }\n"
|
243
|
+
}
|
244
|
+
]
|
245
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CategoryBuilder < KDirector::Builders::ActionsBuilder
|
4
|
+
def category(name, description)
|
5
|
+
value = {
|
6
|
+
name: name,
|
7
|
+
description: description
|
8
|
+
}
|
9
|
+
|
10
|
+
add(:categories, value: value)
|
11
|
+
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def save_categories(**opts)
|
16
|
+
k_builder
|
17
|
+
.cd(:builder_data)
|
18
|
+
.add('categories.json', content: to_json, **opts)
|
19
|
+
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def osave_categories(**opts)
|
24
|
+
save_categories(**{ open: true }.merge(opts))
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CategoryDao
|
4
|
+
attr_reader :k_builder
|
5
|
+
attr_reader :load_time
|
6
|
+
attr_reader :data
|
7
|
+
|
8
|
+
def initialize(k_builder)
|
9
|
+
@k_builder = k_builder
|
10
|
+
@load_time = nil
|
11
|
+
@data = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def file_name
|
15
|
+
k_builder.target_folders.join(:builder_data, 'categories.json')
|
16
|
+
end
|
17
|
+
|
18
|
+
def reload?
|
19
|
+
@load_time.nil? || @load_time < File.mtime(file_name)
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_category(name)
|
23
|
+
result = categories.find { |category| category[:name] == name.to_s }
|
24
|
+
|
25
|
+
raise "Category #{name} not found" if result.nil?
|
26
|
+
|
27
|
+
result
|
28
|
+
end
|
29
|
+
|
30
|
+
def categories
|
31
|
+
if reload?
|
32
|
+
@data = JSON.parse(File.read(file_name), symbolize_names: true)
|
33
|
+
@categories = data[:categories]
|
34
|
+
@load_time = File.mtime(file_name)
|
35
|
+
end
|
36
|
+
@categories
|
37
|
+
end
|
38
|
+
end
|
@@ -1,25 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class CategoryDirector < KDirector::Directors::BaseDirector
|
4
|
-
|
5
|
-
value = {
|
6
|
-
name: name,
|
7
|
-
description: description
|
8
|
-
}
|
4
|
+
defaults(builder_type: CategoryBuilder, on_exist: :write, on_action: :execute)
|
9
5
|
|
10
|
-
|
6
|
+
def category(name, description)
|
7
|
+
builder.category(name, description)
|
11
8
|
|
12
9
|
self
|
13
10
|
end
|
14
11
|
|
15
|
-
def
|
16
|
-
|
12
|
+
def generate
|
13
|
+
generate_require_all_cmdlets
|
14
|
+
|
15
|
+
self
|
17
16
|
end
|
18
17
|
|
19
|
-
def save_categories
|
18
|
+
def save_categories(**opts)
|
20
19
|
cd(:builder_data)
|
21
|
-
add('categories.json', content: builder.to_json)
|
20
|
+
add('categories.json', content: builder.to_json, **opts)
|
22
21
|
|
23
22
|
self
|
24
23
|
end
|
24
|
+
|
25
|
+
def osave_categories(**opts)
|
26
|
+
save_categories(**{ open: true }.merge(opts))
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def generate_require_all_cmdlets
|
32
|
+
cd(:lib)
|
33
|
+
add('_.rb',
|
34
|
+
template_file: 'require_all_cmdlets.rb',
|
35
|
+
cmdlets: data_access.cmdlet.all_cmdlets)
|
36
|
+
|
37
|
+
end
|
38
|
+
|
25
39
|
end
|