Skip to content

Commit 705ec8b

Browse files
authored
Merge pull request #15 from andrewtblake/master
Fix keyword argument passing in endpoint_prop.rb
2 parents f7b0a5b + 4c26dda commit 705ec8b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lib/sinatra_doc/docs/endpoint_prop.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module PropMethods
44
attr_reader :props
55

66
def prop(name, type, description = nil, **options, &block)
7-
prop = Prop.new(name, type, description, options)
7+
prop = Prop.new(name, type, description, **options)
88
if block_given?
99
raise ArgumentError, "Block given but not being used" unless prop.sub_props_allowed
1010
prop.instance_eval(&block)
@@ -23,7 +23,26 @@ def prop_template(name, only: nil)
2323

2424
def model(ref, only: nil, except: nil, methods: nil, required_props: nil, rename_props: nil)
2525
model = SinatraDoc.models.find{|x| x.ref.to_sym == ref.to_sym }
26+
27+
## this bit makes mutual references impossible
2628
raise ArgumentError, "No model found with that ref" if model.nil?
29+
30+
## for example, if an :as_json template for class A returns some class B elements
31+
## but class B's template will return some elements of class A,
32+
## then one model has to be defined first, and it won't find the definition of the other
33+
34+
## the solution proposed here is:
35+
## if you find the model, fine, execute the following code immediately
36+
## otherwise, save in a global hash
37+
## the model name (as the key), and an array of all the parameters (as the value) and return true
38+
## note that this might happen more than once,
39+
## so the value of the model key will be an array of arrays,
40+
## adding a new array of params every time this happens
41+
42+
## then, in the Model class's doc_ref method (where the model is defined),
43+
## look to see if there have been any entries for this model,
44+
## and if so, execute this code
45+
2746
model.attributes.each do |prop_name, prop|
2847
next if only.is_a?(Array) && !only.include?(prop_name)
2948
next if except.is_a?(Array) && except.include?(prop_name)

0 commit comments

Comments
 (0)