Module: MasterView::DirectiveMetadata::ClassMethods
- Defined in:
- lib/masterview/directive_metadata.rb
Class Method Summary collapse
-
.extended(base) ⇒ Object
:nodoc:.
-
.inherited(directive_class) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#attribute_name ⇒ Object
Answer the (unqualified) attribute name of the directive.
-
#attribute_qname ⇒ Object
Answer the fully-qualified attribute name of the directive.
-
#default_directive_name ⇒ Object
Answer the default directive attribute name for a directive class.
-
#default_namespace_prefix ⇒ Object
Answer the default namespace prefix for a directive class.
-
#harden_metadata(defaults = {}) ⇒ Object
Fill in any defaults and ensure that all required metadata properties are defined.
-
#metadata(md_props) ⇒ Object
Declare metadata properties of the directive Specify one more prop_name => value entries :attibute_name, :namespace, :summary, :description.
-
#metadata_values ⇒ Object
the metadata values for the directive class.
- #namespace ⇒ Object
-
#namespace_name ⇒ Object
ISSUE: deprecate this??.
- #namespace_prefix ⇒ Object
- #priority ⇒ Object
Class Method Details
.extended(base) ⇒ Object
:nodoc:
171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/masterview/directive_metadata.rb', line 171 def self.extended(base) #:nodoc: STDOUT.puts "...adding #{self} into #{base} (id=#{base.object_id})" if DEBUG_MD_INSTALLATION #base.class_eval '@@metadata_values = {}' #md_accessor_code = <<-END # def #{base}.metadata_values # @@metadata_values ||= {} # end #END #base.class_eval md_accessor_code DirectiveMetadataRegistry[base.name] = {} STDOUT.puts "...#{base}.@@metadata_values=#{base..object_id}" if DEBUG_MD_INSTALLATION end |
.inherited(directive_class) ⇒ Object
:nodoc:
183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/masterview/directive_metadata.rb', line 183 def self.inherited(directive_class) #:nodoc: STDOUT.puts "\n###inherited #{self} in #{directive_class} (id=#{directive_class.object_id})" if DEBUG_MD_INSTALLATION #directive_class.class_eval '@@metadata_values = {}' #md_accessor_code = <<-END # def #{directive_class}.metadata_values # @@metadata_values ||= {} # end #END #directive_class.class_eval md_accessor_code DirectiveMetadataRegistry[directive_class.name] = {} STDOUT.puts "...#{directive_class}.@@metadata_values=#{directive_class..object_id}" if DEBUG_MD_INSTALLATION end |
Instance Method Details
#attribute_name ⇒ Object
Answer the (unqualified) attribute name of the directive
197 198 199 |
# File 'lib/masterview/directive_metadata.rb', line 197 def attribute_name [:attribute_name] || default_directive_name end |
#attribute_qname ⇒ Object
Answer the fully-qualified attribute name of the directive
215 216 217 |
# File 'lib/masterview/directive_metadata.rb', line 215 def attribute_qname [:attribute_qname] || "#{namespace}:#{attribute_name}" end |
#default_directive_name ⇒ Object
Answer the default directive attribute name for a directive class.
If not explicitly specified, lowercased name of the class is assumed to be the attribute name used in template markup.
228 229 230 231 232 233 |
# File 'lib/masterview/directive_metadata.rb', line 228 def default_directive_name #:nodoc: simple_name = self.name.split(':').last # strip off module qualifiers simple_name = simple_name.downcase_first_letter # convert camel-case class name FooBar to snake-case foo_bar simple_name.gsub( /[A-Z]/ ) { |letter| "_#{letter.downcase}" } end |
#default_namespace_prefix ⇒ Object
Answer the default namespace prefix for a directive class.
237 238 239 240 241 242 243 244 245 |
# File 'lib/masterview/directive_metadata.rb', line 237 def default_namespace_prefix #:nodoc: # this is a bit squirrelly to rely on module namespace convention # masterview brings in String#starts_with? from facets, thank you if self.name.starts_with?('MasterView::Directives::') MasterView::ConfigSettings.namespace_prefix else MasterView::ConfigSettings.namespace_prefix_extensions end end |
#harden_metadata(defaults = {}) ⇒ Object
Fill in any defaults and ensure that all required metadata properties are defined.
Ordinarily done exactly once by the directive loading mechanisms.
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/masterview/directive_metadata.rb', line 272 def (defaults={}) trace_enabled = DEBUG_MD_PROPS || DEBUG_MD_INSTALLATION if ! DirectiveMetadataRegistry.has_key?( self.name ) DirectiveMetadataRegistry[self.name] = {} STDOUT.puts "...#{self}.@@metadata_values=#{self..inspect} (id=#{self..object_id}) <harden_metadata>" if trace_enabled STDOUT.puts "...DirectiveMetadataRegistry=#{DirectiveMetadataRegistry.inspect}" if trace_enabled end dc_md = STDOUT.puts "\n****HARDENING: #{self}.metadata_values=#{dc_md.inspect} (id=#{dc_md.object_id})" if trace_enabled # install any defaults for properties which aren't explicitly set md_to_add = defaults.reject { |key, value| dc_md.has_key?( key ) } #assert ! md_to_add.equal?(defaults), 'safe to mess with our own copy now' DirectiveMetadata.( md_to_add ) # this should check and normalize any namespace-related entries raise RuntimeError, "BAD: attr naming inappropriate in md defaults #{md_to_add.inspect}" if md_to_add.has_key?(:attribute_name) || md_to_add.has_key?(:attribute_qname) # ensure that required properties are set if ! dc_md.has_key?( :attribute_name ) md_to_add[:attribute_name] = default_directive_name end if ! dc_md.has_key?( :priority ) md_to_add[:priority] = DirectivePriorities::Default end if ! dc_md.has_key?( :namespace ) raise RuntimeError, "BUG: inconsistent #{self.name}.metadata_values ns entries: #{dc_md.inspect}" if dc_md.has_key?(:namespace_prefix) || dc_md.has_key?(:attribute_qname) if md_to_add.has_key?( :namespace ) #ok, we'll fill in namespace from defaults # quadruple-check programming errors in this mess until this stuff stabilizes [DJL 06-Oct-2006] raise RuntimeError, 'BUG: validate_metadata_props! did not handle defaults normalization: #{md_to_add.inspect}' if ! md_to_add.has_key?(:namespace_prefix) elsif md_to_add.has_key?( :namespace_prefix ) # quadruple-check programming errors in this mess until this stuff stabilizes [DJL 06-Oct-2006] raise RuntimeError, 'BUG: validate_metadata_props! did not handle defaults normalization: #{md_to_add.inspect}' else default_prefix = default_namespace_prefix md_to_add[:namespace] = default_prefix[0...-1] md_to_add[:namespace_prefix] = default_prefix end end if ! dc_md.has_key?( :namespace_prefix ) # we should have just taken care of this raise RuntimeError, "BUG: inconsistent #{self.name}.metadata_values ns entries: #{dc_md.inspect}" if dc_md.has_key?(:namespace) || dc_md.has_key?(:attribute_qname) raise RuntimeError, "BUG: incorrect construction of #{self.name} md_to_add: #{md_to_add}" if ! (md_to_add.has_key?(:namespace) && md_to_add.has_key?(:namespace_prefix)) end dc_md.merge! md_to_add #assert dc_md.has_key?( :namespace) && dc_md.has_key?( :namespace_prefix) if true # ! dc_md.has_key?( :attribute_qname ) # just always do this, there's something funky about load/include/extend # somehow we're getting backstop defaults in ahead of even the first class load # I do not understand something subtle, so giving up and just hammering here [DJL 06-Oct-2006] dc_md[:attribute_qname] = "#{dc_md[:namespace]}:#{dc_md[:attribute_name]}" end #???dc_md[:hardened] = true??? #??dc_md.freeze if DEBUG_MD_PROPS # quadruple-check programming errors in this mess until this stuff stabilizes [DJL 06-Oct-2006] oops = false HARDENED_PROPERTY_NAMES.each { |md_prop_name| oops = true if ! .has_key?(md_prop_name) } if oops raise RuntimeError, "BAD MD HARDENING IN #{self.name}: #{.inspect}" end if [:namespace_prefix] != "#{[:namespace]}:" raise RuntimeError, "BAD MD HARDENING IN #{self.name}: #{.inspect}" end if [:attribute_qname] != "#{[:namespace]}:#{[:attribute_name]}" raise RuntimeError, "BAD MD HARDENING IN #{self.name}: #{.inspect}" end end STDOUT.puts "...HARDENED MD: #{self..inspect}\n" if DEBUG_MD_PROPS end |
#metadata(md_props) ⇒ Object
Declare metadata properties of the directive Specify one more prop_name => value entries :attibute_name, :namespace, :summary, :description
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/masterview/directive_metadata.rb', line 250 def (md_props) md_props = md_props.clone DirectiveMetadata.(md_props) if ! DirectiveMetadataRegistry.has_key?( self.name ) DirectiveMetadataRegistry[self.name] = {} STDOUT.puts "...#{self}.@@metadata_values=#{self..object_id} <metadata decl>" if DEBUG_MD_INSTALLATION else # ISSUE: not clear why we need to do this, but something's getting initialized # by initial class load/include/extend magic that I can't figure out. # This probably is safe, there should be exactly one metadata decl in # a directive implementation and it should probably always have a clean # point of view. # [DJL 06-Oct-2006] DirectiveMetadataRegistry[self.name].clear() end .merge! md_props end |
#metadata_values ⇒ Object
the metadata values for the directive class
168 169 170 |
# File 'lib/masterview/directive_metadata.rb', line 168 def #:nodoc: return DirectiveMetadataRegistry[self.name] || {} end |
#namespace ⇒ Object
201 202 203 |
# File 'lib/masterview/directive_metadata.rb', line 201 def namespace [:namespace] || default_namespace_prefix[0...-1] end |
#namespace_name ⇒ Object
ISSUE: deprecate this??
206 207 208 |
# File 'lib/masterview/directive_metadata.rb', line 206 def namespace_name namespace end |
#namespace_prefix ⇒ Object
210 211 212 |
# File 'lib/masterview/directive_metadata.rb', line 210 def namespace_prefix [:namespace_prefix] || default_namespace_prefix end |
#priority ⇒ Object
219 220 221 |
# File 'lib/masterview/directive_metadata.rb', line 219 def priority [:priority] || DirectivePriorities::Default end |