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
51 52 53 |
# File 'lib/rumx/bean.rb', line 51 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?
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/rumx/bean.rb', line 101 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
59 60 61 62 |
# File 'lib/rumx/bean.rb', line 59 def bean_attr_accessor(name, type, description, ={}) attr_accessor(name) bean_accessor(name, type, description, ) end |
#bean_attr_embed(name, description) ⇒ Object
72 73 74 |
# File 'lib/rumx/bean.rb', line 72 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
80 81 82 |
# File 'lib/rumx/bean.rb', line 80 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
25 26 27 28 |
# File 'lib/rumx/bean.rb', line 25 def bean_attr_reader(name, type, description, ={}) attr_reader(name) bean_reader(name, type, description, ) end |
#bean_attr_writer(name, type, description, options = {}) ⇒ Object
42 43 44 45 |
# File 'lib/rumx/bean.rb', line 42 def bean_attr_writer(name, type, description, ={}) attr_writer(name) bean_writer(name, type, description, ) end |
#bean_attributes ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/rumx/bean.rb', line 115 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
123 124 125 |
# File 'lib/rumx/bean.rb', line 123 def bean_attributes_local @attributes ||= [] end |
#bean_embed(name, description) ⇒ Object
68 69 70 |
# File 'lib/rumx/bean.rb', line 68 def (name, description) raise "bean_embed no longer used, instead use 'bean_reader :#{name}, :bean, #{description.inspect}'" end |
#bean_embed_list(name, description) ⇒ Object
76 77 78 |
# File 'lib/rumx/bean.rb', line 76 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
139 140 141 142 143 144 145 146 |
# File 'lib/rumx/bean.rb', line 139 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
148 149 150 |
# File 'lib/rumx/bean.rb', line 148 def @embeds ||= {} end |
#bean_list_accessor(name, type, description, options = {}) ⇒ Object
55 56 57 |
# File 'lib/rumx/bean.rb', line 55 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
64 65 66 |
# File 'lib/rumx/bean.rb', line 64 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
30 31 32 |
# File 'lib/rumx/bean.rb', line 30 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
47 48 49 |
# File 'lib/rumx/bean.rb', line 47 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
21 22 23 |
# File 'lib/rumx/bean.rb', line 21 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
38 39 40 |
# File 'lib/rumx/bean.rb', line 38 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' ]
]
89 90 91 92 93 94 95 |
# File 'lib/rumx/bean.rb', line 89 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
127 128 129 130 131 132 133 |
# File 'lib/rumx/bean.rb', line 127 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
135 136 137 |
# File 'lib/rumx/bean.rb', line 135 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.
17 18 19 |
# File 'lib/rumx/bean.rb', line 17 def bean_reader(name, type, description, ={}) bean_add_attribute(name, type, description, true, false, ) end |
#bean_writer(name, type, description, options = {}) ⇒ Object
34 35 36 |
# File 'lib/rumx/bean.rb', line 34 def bean_writer(name, type, description, ={}) bean_add_attribute(name, type, description, false, true, ) end |