Module: Rumx::Bean::ClassMethods
- Defined in:
- lib/rumx/bean.rb
Instance Method Summary collapse
- #bean_accessor(name, type, description, options = {}) ⇒ Object
-
#bean_add_attribute(name, type_name, description, allow_read, allow_write, options) ⇒ Object
private - TODO: Local helper methods, how should I designate them as private or just nodoc them?.
- #bean_attr_accessor(name, type, description, options = {}) ⇒ Object
- #bean_attr_embed(name, description) ⇒ Object
- #bean_attr_embed_list(name, description) ⇒ Object
- #bean_attr_reader(name, type, description, options = {}) ⇒ Object
- #bean_attr_writer(name, type, description, options = {}) ⇒ Object
- #bean_attributes ⇒ Object
- #bean_attributes_local ⇒ Object
- #bean_embed(name, description) ⇒ Object
- #bean_embed_list(name, description) ⇒ Object
- #bean_embeds ⇒ Object
- #bean_embeds_local ⇒ Object
- #bean_list_accessor(name, type, description, options = {}) ⇒ Object
- #bean_list_attr_accessor(name, type, description, options = {}) ⇒ Object
- #bean_list_attr_reader(name, type, description, options = {}) ⇒ Object
- #bean_list_attr_writer(name, type, description, options = {}) ⇒ Object
- #bean_list_reader(name, type, description, options = {}) ⇒ Object
- #bean_list_writer(name, type, description, options = {}) ⇒ Object
-
#bean_operation(name, type, description, args) ⇒ Object
bean_operation :my_operation, :string, ‘My operation’, [ [ :arg_int, :int, ‘An int argument’ ], [ :arg_float, :float, ‘A float argument’ ], [ :arg_string, :string, ‘A string argument’ ] ].
- #bean_operations ⇒ Object
- #bean_operations_local ⇒ Object
-
#bean_reader(name, type, description, options = {}) ⇒ Object
options type => :list list_type - type of each list element max_size - the max size the list can be indexed for setting.
- #bean_writer(name, type, description, options = {}) ⇒ Object
Instance Method Details
#bean_accessor(name, type, description, options = {}) ⇒ Object
49 50 51 |
# File 'lib/rumx/bean.rb', line 49 def bean_accessor(name, type, description, ={}) bean_add_attribute(name, type, description, true, true, ) end |
#bean_add_attribute(name, type_name, description, allow_read, allow_write, options) ⇒ Object
private - TODO: Local helper methods, how should I designate them as private or just nodoc them?
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rumx/bean.rb', line 99 def bean_add_attribute(name, type_name, description, allow_read, allow_write, ) # Dummy up the things that are defined like attributes but are really beans if type_name == :bean [name.to_sym] = nil elsif type_name == :list && [:list_type] == :bean [name.to_sym] = ListBean elsif type_name == :hash && [:hash_type] == :bean [name.to_sym] = HashBean else type = Type.find(type_name) bean_attributes_local << type.create_attribute(name, description, allow_read, allow_write, ) end end |
#bean_attr_accessor(name, type, description, options = {}) ⇒ Object
57 58 59 60 |
# File 'lib/rumx/bean.rb', line 57 def bean_attr_accessor(name, type, description, ={}) attr_accessor(name) bean_accessor(name, type, description, ) end |
#bean_attr_embed(name, description) ⇒ Object
70 71 72 |
# File 'lib/rumx/bean.rb', line 70 def (name, description) raise "bean_attr_embed no longer used, instead use 'bean_attr_reader :#{name}, :bean, #{description.inspect}'" end |
#bean_attr_embed_list(name, description) ⇒ Object
78 79 80 |
# File 'lib/rumx/bean.rb', line 78 def (name, description) raise "bean_attr_embed_list no longer used, instead use 'bean_attr_reader :#{name}, :list, #{description.inspect}, :list_type => :bean'" end |
#bean_attr_reader(name, type, description, options = {}) ⇒ Object
23 24 25 26 |
# File 'lib/rumx/bean.rb', line 23 def bean_attr_reader(name, type, description, ={}) attr_reader(name) bean_reader(name, type, description, ) end |
#bean_attr_writer(name, type, description, options = {}) ⇒ Object
40 41 42 43 |
# File 'lib/rumx/bean.rb', line 40 def bean_attr_writer(name, type, description, ={}) attr_writer(name) bean_writer(name, type, description, ) end |
#bean_attributes ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/rumx/bean.rb', line 113 def bean_attributes attributes = [] self.ancestors.reverse_each do |mod| attributes += mod.bean_attributes_local if mod.include?(Rumx::Bean) end return attributes end |
#bean_attributes_local ⇒ Object
121 122 123 |
# File 'lib/rumx/bean.rb', line 121 def bean_attributes_local @attributes ||= [] end |
#bean_embed(name, description) ⇒ Object
66 67 68 |
# File 'lib/rumx/bean.rb', line 66 def (name, description) raise "bean_embed no longer used, instead use 'bean_reader :#{name}, :bean, #{description.inspect}'" end |
#bean_embed_list(name, description) ⇒ Object
74 75 76 |
# File 'lib/rumx/bean.rb', line 74 def (name, description) raise "bean_embed_list no longer used, instead use 'bean_attr_reader :#{name}, :list, #{description.inspect}, :list_type => :bean'" end |
#bean_embeds ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/rumx/bean.rb', line 137 def = {} # Merge in all the module embeds that are beans self.ancestors.reverse_each do |mod| = .merge(mod.) if mod.include?(Rumx::Bean) end return end |
#bean_embeds_local ⇒ Object
146 147 148 |
# File 'lib/rumx/bean.rb', line 146 def @embeds ||= {} end |
#bean_list_accessor(name, type, description, options = {}) ⇒ Object
53 54 55 |
# File 'lib/rumx/bean.rb', line 53 def bean_list_accessor(name, type, description, ={}) raise "bean_list_accessor no longer used, instead use 'bean_accessor :#{name}, :list, #{description.inspect}, #{.merge(:list_type => type).inspect}'" end |
#bean_list_attr_accessor(name, type, description, options = {}) ⇒ Object
62 63 64 |
# File 'lib/rumx/bean.rb', line 62 def bean_list_attr_accessor(name, type, description, ={}) raise "bean_list_attr_accessor no longer used, instead use 'bean_attr_accessor :#{name}, :list, #{description.inspect}, #{.merge(:list_type => type).inspect}'" end |
#bean_list_attr_reader(name, type, description, options = {}) ⇒ Object
28 29 30 |
# File 'lib/rumx/bean.rb', line 28 def bean_list_attr_reader(name, type, description, ={}) raise "bean_list_attr_reader no longer used, instead use 'bean_attr_reader :#{name}, :list, #{description.inspect}, #{.merge(:list_type => type).inspect}'" end |
#bean_list_attr_writer(name, type, description, options = {}) ⇒ Object
45 46 47 |
# File 'lib/rumx/bean.rb', line 45 def bean_list_attr_writer(name, type, description, ={}) raise "bean_list_attr_writer no longer used, instead use 'bean_attr_writer :#{name}, :list, #{description.inspect}, #{.merge(:list_type => type).inspect}'" end |
#bean_list_reader(name, type, description, options = {}) ⇒ Object
19 20 21 |
# File 'lib/rumx/bean.rb', line 19 def bean_list_reader(name, type, description, ={}) raise "bean_list_reader no longer used, instead use 'bean_reader :#{name}, :list, #{description.inspect}, #{.merge(:list_type => type).inspect}'" end |
#bean_list_writer(name, type, description, options = {}) ⇒ Object
36 37 38 |
# File 'lib/rumx/bean.rb', line 36 def bean_list_writer(name, type, description, ={}) raise "bean_list_writer no longer used, instead use 'bean_writer :#{name}, :list, #{description.inspect}, #{.merge(:list_type => type).inspect}'" end |
#bean_operation(name, type, description, args) ⇒ Object
bean_operation :my_operation, :string, ‘My operation’, [
[ :arg_int, :int, 'An int argument' ],
[ :arg_float, :float, 'A float argument' ],
[ :arg_string, :string, 'A string argument' ]
]
87 88 89 90 91 92 93 |
# File 'lib/rumx/bean.rb', line 87 def bean_operation(name, type, description, args) arguments = args.map do |arg| raise 'Invalid bean_operation format' unless arg.kind_of?(Array) && (arg.size == 3 || arg.size == 4) Argument.new(*arg) end bean_operations_local << Operation.new(name, type, description, arguments) end |
#bean_operations ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/rumx/bean.rb', line 125 def bean_operations operations = [] self.ancestors.reverse_each do |mod| operations += mod.bean_operations_local if mod.include?(Rumx::Bean) end return operations end |
#bean_operations_local ⇒ Object
133 134 135 |
# File 'lib/rumx/bean.rb', line 133 def bean_operations_local @operations ||= [] end |
#bean_reader(name, type, description, options = {}) ⇒ Object
options
type => :list
list_type - type of each list element
max_size - the max size the list can be indexed for setting. Can be an integer or
a symbol that represents an attribute or method of the bean. Defaults to the
current size of the list.
15 16 17 |
# File 'lib/rumx/bean.rb', line 15 def bean_reader(name, type, description, ={}) bean_add_attribute(name, type, description, true, false, ) end |
#bean_writer(name, type, description, options = {}) ⇒ Object
32 33 34 |
# File 'lib/rumx/bean.rb', line 32 def bean_writer(name, type, description, ={}) bean_add_attribute(name, type, description, false, true, ) end |