Module: Metadatable
- Included in:
- ConceptQL::Operators::Operator
- Defined in:
- lib/conceptql/behaviors/metadatable.rb
Instance Method Summary collapse
- #allows_many_upstreams ⇒ Object
- #allows_one_upstream ⇒ Object
- #argument(name, options = {}) ⇒ Object
- #category(category) ⇒ Object
- #desc(value = nil) ⇒ Object
- #humanized_class_name ⇒ Object
- #inherited(upstream) ⇒ Object
- #just_class_name ⇒ Object
- #option(name, options = {}) ⇒ Object
- #predominant_types(*values) ⇒ Object
- #preferred_name(value = nil) ⇒ Object
- #reset_categories ⇒ Object
- #to_metadata ⇒ Object
- #types(*type_list) ⇒ Object
Instance Method Details
#allows_many_upstreams ⇒ Object
42 43 44 |
# File 'lib/conceptql/behaviors/metadatable.rb', line 42 def allows_many_upstreams @max_upstreams = 99 end |
#allows_one_upstream ⇒ Object
46 47 48 |
# File 'lib/conceptql/behaviors/metadatable.rb', line 46 def allows_one_upstream @max_upstreams = 1 end |
#argument(name, options = {}) ⇒ Object
20 21 22 23 |
# File 'lib/conceptql/behaviors/metadatable.rb', line 20 def argument(name, = {}) (@arguments ||= []) @arguments << [name, ] end |
#category(category) ⇒ Object
58 59 60 61 |
# File 'lib/conceptql/behaviors/metadatable.rb', line 58 def category(category) (@categories ||= []) @categories << Array(category) end |
#desc(value = nil) ⇒ Object
10 11 12 13 |
# File 'lib/conceptql/behaviors/metadatable.rb', line 10 def desc(value = nil) return @desc unless value @desc = value end |
#humanized_class_name ⇒ Object
54 55 56 |
# File 'lib/conceptql/behaviors/metadatable.rb', line 54 def humanized_class_name just_class_name.gsub(/([A-Z])/, ' \1').lstrip end |
#inherited(upstream) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/conceptql/behaviors/metadatable.rb', line 67 def inherited(upstream) ( || {}).each do |name, opt| upstream.option name, opt end (@categories || []).each do |cat| upstream.category cat end case @max_upstreams when 1 upstream.allows_one_upstream when 99 upstream.allows_many_upstreams end end |
#just_class_name ⇒ Object
50 51 52 |
# File 'lib/conceptql/behaviors/metadatable.rb', line 50 def just_class_name self.to_s.split('::').last end |
#option(name, options = {}) ⇒ Object
25 26 27 28 |
# File 'lib/conceptql/behaviors/metadatable.rb', line 25 def option(name, = {}) ||= {} [name] = end |
#predominant_types(*values) ⇒ Object
15 16 17 18 |
# File 'lib/conceptql/behaviors/metadatable.rb', line 15 def predominant_types(*values) return @predominant_types if values.empty? @predominant_types = values end |
#preferred_name(value = nil) ⇒ Object
5 6 7 8 |
# File 'lib/conceptql/behaviors/metadatable.rb', line 5 def preferred_name(value = nil) return @preferred_name unless value @preferred_name = value end |
#reset_categories ⇒ Object
63 64 65 |
# File 'lib/conceptql/behaviors/metadatable.rb', line 63 def reset_categories @categories = [] end |
#to_metadata ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/conceptql/behaviors/metadatable.rb', line 84 def { preferred_name: @preferred_name || humanized_class_name, operation: just_class_name.snakecase, max_upstreams: @max_upstreams || 0, arguments: @arguments || [], options: || {}, predominant_types: @types || @predominant_types || [], desc: @desc, categories: @categories || [] } end |
#types(*type_list) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/conceptql/behaviors/metadatable.rb', line 30 def types(*type_list) @types = type_list define_method(:types) do type_list end if type_list.length == 1 define_method(:type) do type_list.first end end end |