lib/jsduck/accessors.rb in jsduck-3.2.1 vs lib/jsduck/accessors.rb in jsduck-3.3.0
- old
+ new
@@ -7,11 +7,11 @@
# @accessor tag. Modifies the class by adding these methods.
# When class already contains a getter or setter, the method is
# not added.
def create(cls)
# Grab all configs tagged as @accessor
- accessors = cls[:members][:cfg].find_all {|cfg| cfg[:accessor] && !cfg[:private] }
+ accessors = cls[:members][:cfg].find_all {|cfg| cfg[:accessor] }
# Build lookup tables of method and event names
methods = build_lookup_table(cls[:members][:method])
events = build_lookup_table(cls[:members][:event])
@@ -43,29 +43,26 @@
map
end
def create_getter(cfg)
name = "get" + upcase_first(cfg[:name])
- return {
+ return add_shared({
:tagname => :method,
:name => name,
:doc => "Returns the value of {@link #cfg-#{cfg[:name]}}.",
:params => [],
:return => {
:type => cfg[:type],
:doc => "",
},
- :owner => cfg[:owner],
- :files => cfg[:files],
:id => "method-" + name,
- :meta => clone_meta(cfg),
- }
+ }, cfg)
end
def create_setter(cfg)
name = "set" + upcase_first(cfg[:name]);
- return {
+ return add_shared({
:tagname => :method,
:name => name,
:doc => "Sets the value of {@link #cfg-#{cfg[:name]}}.",
:params => [{
:type => cfg[:type],
@@ -74,21 +71,18 @@
}],
:return => {
:type => "undefined",
:doc => "",
},
- :owner => cfg[:owner],
- :files => cfg[:files],
:id => "method-" + name,
- :meta => clone_meta(cfg),
- }
+ }, cfg)
end
def create_event(cfg)
name = cfg[:name].downcase + "change"
setter_name = "set" + upcase_first(cfg[:name]);
- return {
+ return add_shared({
:tagname => :event,
:name => name,
:doc =>
"Fires when the {@link ##{cfg[:id]}} configuration is changed by {@link #method-#{setter_name}}." +
"\n\n" +
@@ -110,15 +104,21 @@
:name => "oldValue",
:type => cfg[:type],
:doc => "The existing value."
},
],
+ :id => "event-" + name,
+ }, cfg)
+ end
+
+ def add_shared(hash, cfg)
+ hash.merge!({
:owner => cfg[:owner],
:files => cfg[:files],
- :id => "event-" + name,
+ :private => cfg[:private],
:meta => clone_meta(cfg),
- }
+ })
end
def upcase_first(str)
str[0,1].upcase + str[1..-1]
end
@@ -127,10 +127,10 @@
# :required which only applies to configs and must not be
# propagated to methods or events.
def clone_meta(cfg)
h = {}
cfg[:meta].each_pair do |key, value|
- h[:key] = value unless key == :required
+ h[key] = value unless key == :required
end
h
end
end