Sha256: 62e3492fa3934b1828775b6107bc836e2635eb35d30fa638bd7055b1a5f42d0b
Contents?: true
Size: 1.88 KB
Versions: 10
Compression:
Stored size: 1.88 KB
Contents
module AnnotatedModule def self.add_consummable_annotation(target, *annotations) if annotations.length == 1 and Hash === annotations.first annotations.first.each do |annotation, default| target.send(:attr_accessor, annotation) target.send(:define_method, "consume_#{annotation}") do value = instance_variable_get("@#{annotation}") || default.dup instance_variable_set("@#{annotation}", default.dup) value end end else annotations.each do |annotation| target.send(:attr_accessor, annotation) target.send(:define_method, "consume_#{annotation}") do value = instance_variable_get("@#{annotation}") instance_variable_set("@#{annotation}", nil) end end end end add_consummable_annotation(self, :description => "", :inputs => [], :required_inputs => [], :input_types => {}, :input_descriptions => {}, :input_defaults => {}, :input_options => {}) def input(name, type = nil, desc = nil, default = nil, options = nil) name = name.to_sym type = type.to_sym @inputs = [] if @inputs.nil? @input_types = {} if @input_types.nil? @input_descriptions = {} if @input_descriptions.nil? @input_defaults = {} if @input_defaults.nil? @input_options = {} if @input_options.nil? @required_inputs = [] if @required_inputs.nil? required = Misc.process_options options, :required if options required, default = true, nil if default == :required @required_inputs << name if required @inputs << name @input_types[name] = type unless type.nil? @input_descriptions[name] = desc unless desc.nil? @input_defaults[name] = default unless default.nil? @input_options[name] = options unless options.nil? end end
Version data entries
10 entries across 10 versions & 1 rubygems