Module: Rumx::Bean::ClassMethods

Defined in:
lib/rumx/bean.rb

Instance Method Summary collapse

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, options={})
  bean_add_attribute(name, type, description, true, true, options)
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, options)
  # Dummy up the things that are defined like attributes but are really beans
  if type_name == :bean
    bean_embeds_local[name.to_sym] = nil
  elsif type_name == :list && options[:list_type] == :bean
    bean_embeds_local[name.to_sym] = ListBean
  elsif type_name == :hash && options[:hash_type] == :bean
    bean_embeds_local[name.to_sym] = HashBean
  else
    type = Type.find(type_name)
    bean_attributes_local << type.create_attribute(name, description, allow_read, allow_write, options)
  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, options={})
  attr_accessor(name)
  bean_accessor(name, type, description, options)
end

#bean_attr_embed(name, description) ⇒ Object



70
71
72
# File 'lib/rumx/bean.rb', line 70

def bean_attr_embed(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 bean_attr_embed_list(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, options={})
  attr_reader(name)
  bean_reader(name, type, description, options)
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, options={})
  attr_writer(name)
  bean_writer(name, type, description, options)
end

#bean_attributesObject



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_localObject



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 bean_embed(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 bean_embed_list(name, description)
  raise "bean_embed_list no longer used, instead use 'bean_attr_reader :#{name}, :list, #{description.inspect}, :list_type => :bean'"
end

#bean_embedsObject



137
138
139
140
141
142
143
144
# File 'lib/rumx/bean.rb', line 137

def bean_embeds
  embeds = {}
  # Merge in all the module embeds that are beans
  self.ancestors.reverse_each do |mod|
    embeds = embeds.merge(mod.bean_embeds_local) if mod.include?(Rumx::Bean)
  end
  return embeds
end

#bean_embeds_localObject



146
147
148
# File 'lib/rumx/bean.rb', line 146

def bean_embeds_local
  @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, options={})
  raise "bean_list_accessor no longer used, instead use 'bean_accessor :#{name}, :list, #{description.inspect}, #{options.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, options={})
  raise "bean_list_attr_accessor no longer used, instead use 'bean_attr_accessor :#{name}, :list, #{description.inspect}, #{options.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, options={})
  raise "bean_list_attr_reader no longer used, instead use 'bean_attr_reader :#{name}, :list, #{description.inspect}, #{options.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, options={})
  raise "bean_list_attr_writer no longer used, instead use 'bean_attr_writer :#{name}, :list, #{description.inspect}, #{options.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, options={})
  raise "bean_list_reader no longer used, instead use 'bean_reader :#{name}, :list, #{description.inspect}, #{options.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, options={})
  raise "bean_list_writer no longer used, instead use 'bean_writer :#{name}, :list, #{description.inspect}, #{options.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_operationsObject



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_localObject



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, options={})
  bean_add_attribute(name, type, description, true, false, options)
end

#bean_writer(name, type, description, options = {}) ⇒ Object



32
33
34
# File 'lib/rumx/bean.rb', line 32

def bean_writer(name, type, description, options={})
  bean_add_attribute(name, type, description, false, true, options)
end