Class: ObjCIvarTemplate
- Inherits:
-
Object
- Object
- ObjCIvarTemplate
- Defined in:
- lib/mt_tool/short_hand/objc_generate_from_shorthand.rb
Instance Attribute Summary collapse
-
#ivar ⇒ Object
readonly
Returns the value of attribute ivar.
Instance Method Summary collapse
- #capitalized_property_name ⇒ Object
- #did_set ⇒ Object
-
#initialize(ivar) ⇒ ObjCIvarTemplate
constructor
A new instance of ObjCIvarTemplate.
- #is_assign ⇒ Object
- #is_object_type ⇒ Object
- #ivar_name ⇒ Object
- #ivar_type ⇒ Object
- #memory_management_call ⇒ Object
- #memory_management_marker ⇒ Object
- #needs_explicit_getter ⇒ Object
- #needs_explicit_setter ⇒ Object
- #outlet_marker ⇒ Object
- #property_modifiers ⇒ Object
- #property_name ⇒ Object
- #will_get ⇒ Object
- #will_set ⇒ Object
Constructor Details
#initialize(ivar) ⇒ ObjCIvarTemplate
Returns a new instance of ObjCIvarTemplate.
54 55 56 |
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 54 def initialize ivar @ivar = ivar end |
Instance Attribute Details
#ivar ⇒ Object (readonly)
Returns the value of attribute ivar.
58 59 60 |
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 58 def ivar @ivar end |
Instance Method Details
#capitalized_property_name ⇒ Object
127 128 129 130 131 |
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 127 def capitalized_property_name p = property_name.to_s.dup p[0,1] = p[0,1].upcase p end |
#did_set ⇒ Object
137 138 139 |
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 137 def did_set ivar..include? :did_set end |
#is_assign ⇒ Object
153 154 155 156 |
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 153 def is_assign marker = memory_management_marker marker != 'retain' and marker != 'copy' end |
#is_object_type ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 70 def is_object_type t = ivar.objc_type return true if ivar..include?(:object) return false if (t == :int or t == :uint or t == :bool) return true if t.kind_of?(Symbol) (t =~ /^\s*id\s*(<|$)/) != nil end |
#ivar_name ⇒ Object
79 80 81 |
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 79 def ivar_name "#{ivar.name}_" end |
#ivar_type ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 60 def ivar_type t = ivar.objc_type t = "NSString*" if t == :str t = "NSInteger" if t == :int t = "NSUInteger" if t == :uint t = "BOOL" if t == :bool t = "#{t}*" if t.kind_of? Symbol and t != :id and t != :Class t end |
#memory_management_call ⇒ Object
158 159 160 |
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 158 def memory_management_call memory_management_marker end |
#memory_management_marker ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 87 def memory_management_marker if is_object_type if ivar..include? :retain 'retain' elsif ivar..include? :copy 'copy' elsif ivar..include? :assign 'assign' elsif ivar.name.to_s == 'delegate' or ivar.name.to_s =~ /Delegate$/ and not ivar..include? :ro 'assign' elsif not ivar..include? :ro 'retain' end end end |
#needs_explicit_getter ⇒ Object
149 150 151 |
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 149 def needs_explicit_getter will_get end |
#needs_explicit_setter ⇒ Object
145 146 147 |
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 145 def needs_explicit_setter will_set || did_set end |
#outlet_marker ⇒ Object
83 84 85 |
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 83 def outlet_marker 'IBOutlet' if ivar..include? :outlet end |
#property_modifiers ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 103 def property_modifiers s = [] marker = memory_management_marker s << marker if marker s << 'nonatomic' unless ivar..include? :atomic if ivar..include? :ro s << 'readonly' end getter_name = ivar..select { |x| x.kind_of? ObjCIvarGetterNameOption }[0] if getter_name s << "getter = #{getter_name.name}" end return "(#{s.join ','})" end |
#property_name ⇒ Object
123 124 125 |
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 123 def property_name ivar.name end |
#will_get ⇒ Object
141 142 143 |
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 141 def will_get ivar..include? :will_get end |
#will_set ⇒ Object
133 134 135 |
# File 'lib/mt_tool/short_hand/objc_generate_from_shorthand.rb', line 133 def will_set ivar..include? :will_set end |