Class: Seasar::Beans::BeanDesc
- Inherits:
-
Object
- Object
- Seasar::Beans::BeanDesc
- Defined in:
- lib/seasar/beans/bean-desc.rb
Overview
Bean定義を表すクラスです。publicな属性を管理します。publicでタイプヒントされた属性を管理します。セッターメソッドを管理します。タイプヒントされたセッターメソッドを管理します。
Constant Summary collapse
- DI_SYMBOL =
[:di, :DI, :Di, :dI]
- DI_REGEXP =
/^di (.*)$/i
Instance Attribute Summary collapse
-
#property_descs ⇒ Object
Returns the value of attribute property_descs.
-
#typehint_property_descs ⇒ Object
Returns the value of attribute typehint_property_descs.
Instance Method Summary collapse
-
#get_property_desc(name) ⇒ Object
渡された属性名の属性定義を返します。.
-
#get_typehint_property_desc(name) ⇒ Object
渡された属性名のタイプヒント付き属性定義を返します。.
-
#has_property_desc(name) ⇒ Object
渡された属性名の属性が存在するかどうかを返します。.
-
#has_typehint_property_desc(name) ⇒ Object
渡された属性名のタイプヒント付き属性定義が存在するかどうかを返します。.
-
#initialize(component) ⇒ BeanDesc
constructor
BeanDescを構築します。.
-
#setup_attribute_accessor_descs(component) ⇒ Object
-
args 1.
-
-
#setup_instance_variable_descs(component) ⇒ Object
属性定義を生成します 属性名が「_」ではじまる場合は無視されます。 属性値が文字列で「DI:」ではじまる場合に属性定義が作成されます。 属性値が文字列で「DI:」の後ろの文字列がコンポーネントキーになります。空文字列の場合は、 属性名がコンポーネントキーとして扱われます。 属性値が文字列で「[]」で終わる場合は、複数のコンポーネントを配列で受けることができます。.
-
#setup_property_desc_array(property_desc, name, no_at_name, key, value) ⇒ Object
(also: #setup_property_desc_hash)
-
args 1.
-
-
#setup_property_desc_nil(property_desc, name, no_at_name) ⇒ Object
-
args 1.
-
-
#setup_property_desc_string(property_desc, name, no_at_name, value) ⇒ Object
-
args 1.
-
-
#setup_property_desc_symbol(property_desc, name, value) ⇒ Object
(also: #setup_property_desc_class)
-
args 1.
-
Constructor Details
#initialize(component) ⇒ BeanDesc
BeanDescを構築します。
-
args
-
Object component
-
37 38 39 40 41 42 43 |
# File 'lib/seasar/beans/bean-desc.rb', line 37 def initialize(component) @bean_class = component.class @property_descs = {} @typehint_property_descs = {} self.setup_instance_variable_descs(component) self.setup_attribute_accessor_descs(component) end |
Instance Attribute Details
#property_descs ⇒ Object
Returns the value of attribute property_descs.
44 45 46 |
# File 'lib/seasar/beans/bean-desc.rb', line 44 def property_descs @property_descs end |
#typehint_property_descs ⇒ Object
Returns the value of attribute typehint_property_descs.
44 45 46 |
# File 'lib/seasar/beans/bean-desc.rb', line 44 def typehint_property_descs @typehint_property_descs end |
Instance Method Details
#get_property_desc(name) ⇒ Object
渡された属性名の属性定義を返します。
-
args
-
Symbol name
-
-
return
-
Seasar::Beans::AbstractPropertyDesc
-
64 65 66 67 68 69 |
# File 'lib/seasar/beans/bean-desc.rb', line 64 def get_property_desc(name) if self.has_property_desc(name) return @property_descs[name] end raise Seasar::Exception::PropertyNotFoundRuntimeException.new(@bean_class, name) end |
#get_typehint_property_desc(name) ⇒ Object
渡された属性名のタイプヒント付き属性定義を返します。
-
args
-
Symbol name
-
-
return
-
Seasar::Beans::AbstractPropertyDesc
-
89 90 91 92 93 94 |
# File 'lib/seasar/beans/bean-desc.rb', line 89 def get_typehint_property_desc(name) if self.has_typehint_property_desc(name) return @typehint_property_descs[name] end raise Seasar::Exception::PropertyNotFoundRuntimeException.new(@bean_class, name) end |
#has_property_desc(name) ⇒ Object
渡された属性名の属性が存在するかどうかを返します。
-
args
-
Symbol name
-
-
return
-
Boolean
-
53 54 55 |
# File 'lib/seasar/beans/bean-desc.rb', line 53 def has_property_desc(name) return @property_descs.key?(name) end |
#has_typehint_property_desc(name) ⇒ Object
渡された属性名のタイプヒント付き属性定義が存在するかどうかを返します。
-
args
-
Symbol name
-
-
return
-
Boolean
-
78 79 80 |
# File 'lib/seasar/beans/bean-desc.rb', line 78 def has_typehint_property_desc(name) return @typehint_property_descs.key?(name) end |
#setup_attribute_accessor_descs(component) ⇒ Object
-
args
-
Object component
-
-
return
-
nil
-
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/seasar/beans/bean-desc.rb', line 102 def setup_attribute_accessor_descs(component) Seasar::Util::ClassUtil.get_accessor_attributes(component).each {|name| next if has_property_desc(name) property_desc = Seasar::Beans::AttributeAccessorDesc.new(name) no_at_name = name.to_s no_at_name = no_at_name[1..no_at_name.length].to_sym @property_descs[name] = property_desc setup_property_desc_nil(property_desc, name, no_at_name) } end |
#setup_instance_variable_descs(component) ⇒ Object
属性定義を生成します属性名が「_」ではじまる場合は無視されます。属性値が文字列で「DI:」ではじまる場合に属性定義が作成されます。属性値が文字列で「DI:」の後ろの文字列がコンポーネントキーになります。空文字列の場合は、属性名がコンポーネントキーとして扱われます。属性値が文字列で「[]」で終わる場合は、複数のコンポーネントを配列で受けることができます。
-
args
-
Object component
-
-
return
-
nil
-
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/seasar/beans/bean-desc.rb', line 125 def setup_instance_variable_descs(component) attributes = Seasar::Util::ClassUtil.get_instance_attributes(component) attributes.each {|name, value| no_at_name = name.to_s no_at_name = no_at_name[1..no_at_name.length].to_sym property_desc = Seasar::Beans::InstanceVariableDesc.new(name) @property_descs[name] = property_desc if value.nil? setup_property_desc_nil(property_desc, name, no_at_name) elsif value.is_a?(Class) setup_property_desc_class(property_desc, name, value) elsif value.is_a?(Symbol) setup_property_desc_symbol(property_desc, name, value) elsif value.is_a?(String) and DI_REGEXP.match(value) setup_property_desc_string(property_desc, name, no_at_name, $1) elsif value.is_a?(Array) and value.size == 2 setup_property_desc_array(property_desc, name, no_at_name, value[0], value[1]) elsif value.is_a?(Hash) and value.size == 1 key = value.keys[0] setup_property_desc_hash(property_desc, name, no_at_name, key, value[key]) end } end |
#setup_property_desc_array(property_desc, name, no_at_name, key, value) ⇒ Object Also known as: setup_property_desc_hash
-
args
-
Seasar::Beans::AbstractPropertyDesc property_desc
-
Symbol name
-
Symbol no_at_name
-
String key
-
miced value
-
-
return
-
nil
-
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/seasar/beans/bean-desc.rb', line 211 def setup_property_desc_array(property_desc, name, no_at_name, key, value) if DI_SYMBOL.member?(key) or key.downcase == "di" @typehint_property_descs[name] = property_desc if value.nil? setup_property_desc_nil(property_desc, name, no_at_name, value) elsif value.is_a?(Class) setup_property_desc_class(property_desc, name, value) elsif value.is_a?(Symbol) setup_property_desc_symbol(property_desc, name, value) elsif value.is_a?(String) setup_property_desc_string(property_desc, name, no_at_name, value) else raise ArgumentError.new("invalid value #{value.inspect} for :DI. property [#{name}] of class [#{@bean_class.name}].") end end end |
#setup_property_desc_nil(property_desc, name, no_at_name) ⇒ Object
-
args
-
Seasar::Beans::AbstractPropertyDesc property_desc
-
Symbol name
-
Symbol no_at_name
-
-
return
-
nil
-
172 173 174 175 176 |
# File 'lib/seasar/beans/bean-desc.rb', line 172 def setup_property_desc_nil(property_desc, name, no_at_name) @typehint_property_descs[name] = property_desc property_desc.typehint = no_at_name property_desc.array_acceptable = false end |
#setup_property_desc_string(property_desc, name, no_at_name, value) ⇒ Object
-
args
-
Seasar::Beans::AbstractPropertyDesc property_desc
-
Symbol name
-
Symbol no_at_name
-
String value
-
-
return
-
nil
-
187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/seasar/beans/bean-desc.rb', line 187 def setup_property_desc_string(property_desc, name, no_at_name, value) @typehint_property_descs[name] = property_desc typehint = value.strip typehint = no_at_name if typehint == '' if /^(.*?)\[\]$/i =~ typehint property_desc.array_acceptable = true typehint = $1.strip typehint = no_at_name if typehint == '' else property_desc.array_acceptable = false end property_desc.typehint = typehint end |
#setup_property_desc_symbol(property_desc, name, value) ⇒ Object Also known as: setup_property_desc_class
-
args
-
Seasar::Beans::AbstractPropertyDesc property_desc
-
Symbol name
-
Symbol value
-
-
return
-
nil
-
157 158 159 160 161 |
# File 'lib/seasar/beans/bean-desc.rb', line 157 def setup_property_desc_symbol(property_desc, name, value) @typehint_property_descs[name] = property_desc property_desc.typehint = value property_desc.array_acceptable = false end |