brief 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/brief/dsl.rb +22 -3
- data/lib/brief/model/definition.rb +14 -26
- data/lib/brief/model.rb +7 -2
- data/lib/brief/version.rb +1 -1
- data/spec/lib/brief/dsl_spec.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f76fe6d3f07ffe657ecf1457f3b3895a882b5e7c
|
4
|
+
data.tar.gz: 7721891fd080e174065958f0112757506c31fe1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64c0b59e9917dec20b4affbe230e358418af652b47b16a8ca56f5789c2b44463291883e08ca60c9ff6db12f05f7aad24c84f4063764ea7c5d79ba99efb415eaf
|
7
|
+
data.tar.gz: 677548043e04af7deddf8a30211b939101265587620a280c5987351c8728311091c41274c1203419029013f670a42b73b646fa2e2ed454953e9299a48e4f3891
|
data/lib/brief/dsl.rb
CHANGED
@@ -7,9 +7,28 @@ module Brief
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def define(*args, &block)
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
options = args.dup.extract_options!
|
11
|
+
name = args.first
|
12
|
+
type_alias = options.fetch(:type_alias) { name.downcase.parameterize.gsub(/-/, '_') }
|
13
|
+
|
14
|
+
namespace = Brief.configuration.model_namespace || Brief::Model
|
15
|
+
|
16
|
+
klass = namespace.const_get(type_alias.camelize) rescue nil
|
17
|
+
|
18
|
+
if klass
|
19
|
+
# raise class already defined
|
20
|
+
end
|
21
|
+
|
22
|
+
klass ||= namespace.const_set(type_alias.camelize, Class.new).tap do |k|
|
23
|
+
k.send(:include, Brief::Model)
|
24
|
+
k.definition ||= Brief::Model::Definition.new(args.first, args.extract_options!)
|
25
|
+
k.name ||= name
|
26
|
+
k.type_alias ||= type_alias
|
27
|
+
Brief::Model.classes << k
|
28
|
+
end
|
29
|
+
|
30
|
+
klass.definition.instance_eval(&block) if block_given?
|
31
|
+
klass.definition.validate!
|
13
32
|
end
|
14
33
|
|
15
34
|
# defines a method on the model instance named after the identifier
|
@@ -6,6 +6,7 @@ module Brief
|
|
6
6
|
:content_schema,
|
7
7
|
:options,
|
8
8
|
:defined_helpers,
|
9
|
+
:defined_actions,
|
9
10
|
:section_mappings,
|
10
11
|
:template_body,
|
11
12
|
:example_body
|
@@ -25,20 +26,7 @@ module Brief
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def validate!
|
28
|
-
definition = self
|
29
|
-
|
30
29
|
if valid?
|
31
|
-
create_model_class.tap do |k|
|
32
|
-
k.send(:include, Brief::Model)
|
33
|
-
|
34
|
-
k.definition ||= definition
|
35
|
-
|
36
|
-
k.name ||= name
|
37
|
-
k.type_alias ||= type_alias
|
38
|
-
|
39
|
-
Brief::Model.classes << k
|
40
|
-
end
|
41
|
-
|
42
30
|
apply_config
|
43
31
|
end
|
44
32
|
end
|
@@ -56,16 +44,13 @@ module Brief
|
|
56
44
|
end
|
57
45
|
|
58
46
|
# defined helpers adds an anonymous module include
|
59
|
-
Array(defined_helpers).each { |mod| model_class.send(:include, mod) }
|
47
|
+
Array(self.defined_helpers).each { |mod| model_class.send(:include, mod) }
|
60
48
|
|
61
|
-
model_class.defined_actions += Array(defined_actions)
|
62
49
|
true
|
63
50
|
end
|
64
51
|
|
65
|
-
def
|
66
|
-
|
67
|
-
model_namespace.const_set(type_alias.camelize, Class.new)
|
68
|
-
end
|
52
|
+
def defined_helper_methods
|
53
|
+
defined_helpers.map(&:instance_methods).flatten
|
69
54
|
end
|
70
55
|
|
71
56
|
def model_class
|
@@ -103,24 +88,27 @@ module Brief
|
|
103
88
|
end
|
104
89
|
|
105
90
|
def has_actions?
|
106
|
-
|
91
|
+
self.defined_actions.empty?
|
107
92
|
end
|
108
93
|
|
109
94
|
def actions(&block)
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
def defined_actions
|
114
|
-
Array(defined_helpers).map(&:instance_methods).flatten
|
95
|
+
self.defined_actions ||= []
|
96
|
+
helpers(true, &block)
|
115
97
|
end
|
116
98
|
|
117
|
-
def helpers(&block)
|
99
|
+
def helpers(include_in_command_list=false, &block)
|
118
100
|
self.defined_helpers ||= []
|
119
101
|
|
120
102
|
if block
|
121
103
|
mod = Module.new
|
122
104
|
mod.module_eval(&block)
|
123
105
|
|
106
|
+
if include_in_command_list
|
107
|
+
self.defined_actions ||= []
|
108
|
+
self.defined_actions += mod.instance_methods
|
109
|
+
self.defined_actions.uniq!
|
110
|
+
end
|
111
|
+
|
124
112
|
self.defined_helpers << mod
|
125
113
|
end
|
126
114
|
end
|
data/lib/brief/model.rb
CHANGED
@@ -13,10 +13,9 @@ module Brief
|
|
13
13
|
include AccessorMethods
|
14
14
|
include Persistence
|
15
15
|
|
16
|
-
class_attribute :models, :after_initialization_hooks
|
16
|
+
class_attribute :models, :after_initialization_hooks
|
17
17
|
|
18
18
|
self.models = Array(models).to_set
|
19
|
-
self.defined_actions = Array(defined_actions).to_set
|
20
19
|
|
21
20
|
class << self
|
22
21
|
include Enumerable
|
@@ -94,6 +93,10 @@ module Brief
|
|
94
93
|
definition.has_actions?
|
95
94
|
end
|
96
95
|
|
96
|
+
def defined_actions
|
97
|
+
definition.defined_actions ||= []
|
98
|
+
end
|
99
|
+
|
97
100
|
def finalize
|
98
101
|
klass = self
|
99
102
|
|
@@ -182,6 +185,8 @@ module Brief
|
|
182
185
|
if %w(meta content template example actions helpers).include?(meth.to_s)
|
183
186
|
definition.send(meth, *args, &block)
|
184
187
|
finalize
|
188
|
+
elsif %w(defined_helper_methods defined_actions).include?(meth.to_s)
|
189
|
+
definition.send(meth)
|
185
190
|
elsif meth.to_s.match(/^on_(.*)_change$/)
|
186
191
|
create_change_handler(Regexp.last_match[1], *args, &block)
|
187
192
|
else
|
data/lib/brief/version.rb
CHANGED
data/spec/lib/brief/dsl_spec.rb
CHANGED
@@ -7,4 +7,13 @@ describe "The Configuration DSL" do
|
|
7
7
|
it "can create methods on our models" do
|
8
8
|
expect(briefcase.user_stories.first.defined_helper_method).to eq(true)
|
9
9
|
end
|
10
|
+
|
11
|
+
it "treats actions as available commands" do
|
12
|
+
expect(Brief::Epic.defined_actions).to include(:custom_action)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "doesnt treat helpers as available commands" do
|
16
|
+
expect(Brief::Epic.defined_helper_methods).to include(:user_stories)
|
17
|
+
expect(Brief::Epic.defined_actions).not_to include(:user_stories)
|
18
|
+
end
|
10
19
|
end
|