TemplateInfo 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (226) hide show
  1. data/.DS_Store +0 -0
  2. data/.gitignore +2 -0
  3. data/TemplateInfo.gemspec +1 -1
  4. data/bin/tif_create.rb +157 -0
  5. data/lib/TemplateInfo/version.rb +1 -1
  6. data/test.xctemplate/.DS_Store +0 -0
  7. data/test.xctemplate/TemplateInfo.plist +2830 -0
  8. data/test.xctemplate/TemplateInfo.xml +2842 -0
  9. data/test.xctemplate/libs/BeeFramework/Bee.h +35 -0
  10. data/test.xctemplate/libs/BeeFramework/Bee_Precompile.h +143 -0
  11. data/test.xctemplate/libs/BeeFramework/Core/Bee_Core.h +36 -0
  12. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Foundation.h +54 -0
  13. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Foundation.mm +33 -0
  14. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Log.h +64 -0
  15. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Log.mm +164 -0
  16. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Performance.h +111 -0
  17. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Performance.mm +122 -0
  18. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Runtime.h +98 -0
  19. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Runtime.mm +437 -0
  20. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Sandbox.h +45 -0
  21. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Sandbox.mm +81 -0
  22. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Singleton.h +47 -0
  23. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Singleton.mm +34 -0
  24. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_SystemInfo.h +62 -0
  25. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_SystemInfo.m +147 -0
  26. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Thread.h +64 -0
  27. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Bee_Thread.mm +91 -0
  28. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSArray+BeeExtension.h +76 -0
  29. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSArray+BeeExtension.m +300 -0
  30. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSData+BeeExtension.h +44 -0
  31. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSData+BeeExtension.m +92 -0
  32. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSDate+BeeExtension.h +44 -0
  33. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSDate+BeeExtension.m +85 -0
  34. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSDictionary+BeeExtension.h +90 -0
  35. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSDictionary+BeeExtension.m +509 -0
  36. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSNumber+BeeExtension.h +50 -0
  37. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSNumber+BeeExtension.m +64 -0
  38. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeJSON.h +43 -0
  39. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeJSON.m +116 -0
  40. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeNotification.h +66 -0
  41. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeNotification.m +150 -0
  42. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeProperty.h +210 -0
  43. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeProperty.m +34 -0
  44. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeTicker.h +41 -0
  45. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeTicker.m +156 -0
  46. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeTypeConversion.h +49 -0
  47. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSObject+BeeTypeConversion.m +109 -0
  48. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSString+BeeExtension.h +86 -0
  49. data/test.xctemplate/libs/BeeFramework/Core/Foundation/Extension/NSString+BeeExtension.m +464 -0
  50. data/test.xctemplate/libs/BeeFramework/Core/Network/Bee_Network.h +36 -0
  51. data/test.xctemplate/libs/BeeFramework/Core/Network/Bee_Network.m +33 -0
  52. data/test.xctemplate/libs/BeeFramework/Core/Network/Bee_Request.h +144 -0
  53. data/test.xctemplate/libs/BeeFramework/Core/Network/Bee_Request.m +560 -0
  54. data/test.xctemplate/libs/BeeFramework/Core/Network/Bee_RequestQueue.h +99 -0
  55. data/test.xctemplate/libs/BeeFramework/Core/Network/Bee_RequestQueue.m +742 -0
  56. data/test.xctemplate/libs/BeeFramework/Core/Network/Extension/NSObject+BeeRequest.h +62 -0
  57. data/test.xctemplate/libs/BeeFramework/Core/Network/Extension/NSObject+BeeRequest.m +175 -0
  58. data/test.xctemplate/libs/BeeFramework/Core/Storage/0.2.4.zip +0 -0
  59. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_ActiveBase.h +133 -0
  60. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_ActiveBase.m +641 -0
  61. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_ActiveRecord.h +106 -0
  62. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_ActiveRecord.m +1956 -0
  63. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_Cache.h +91 -0
  64. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_Cache.m +318 -0
  65. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_Database.h +223 -0
  66. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_Database.m +3007 -0
  67. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_Keychain.h +55 -0
  68. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_Keychain.m +173 -0
  69. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_Storage.h +39 -0
  70. data/test.xctemplate/libs/BeeFramework/Core/Storage/Bee_Storage.m +33 -0
  71. data/test.xctemplate/libs/BeeFramework/Core/Storage/Extension/NSObject+BeeDatabase.h +47 -0
  72. data/test.xctemplate/libs/BeeFramework/Core/Storage/Extension/NSObject+BeeDatabase.m +81 -0
  73. data/test.xctemplate/libs/BeeFramework/Core/Storage/Extension/NSObject+BeeKeychain.h +44 -0
  74. data/test.xctemplate/libs/BeeFramework/Core/Storage/Extension/NSObject+BeeKeychain.m +57 -0
  75. data/test.xctemplate/libs/BeeFramework/MVC/Bee_MVC.h +49 -0
  76. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Bee_Controller.h +66 -0
  77. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Bee_Controller.mm +228 -0
  78. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Bee_Message.h +209 -0
  79. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Bee_Message.mm +873 -0
  80. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Bee_MessageQueue.h +75 -0
  81. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Bee_MessageQueue.mm +389 -0
  82. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/BeeMessage+ActiveRecord.h +52 -0
  83. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/BeeMessage+ActiveRecord.m +150 -0
  84. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/BeeMessage+HTTP.h +49 -0
  85. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/BeeMessage+HTTP.mm +201 -0
  86. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/BeeMessage+JSON.h +52 -0
  87. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/BeeMessage+JSON.mm +118 -0
  88. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/BeeMessage+XML.h +49 -0
  89. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/BeeMessage+XML.mm +78 -0
  90. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/NSObject+BeeMessage.h +57 -0
  91. data/test.xctemplate/libs/BeeFramework/MVC/Controller/Extension/NSObject+BeeMessage.mm +138 -0
  92. data/test.xctemplate/libs/BeeFramework/MVC/Model/Bee_Model.h +64 -0
  93. data/test.xctemplate/libs/BeeFramework/MVC/Model/Bee_Model.m +190 -0
  94. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIActionSheet.h +71 -0
  95. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIActionSheet.m +307 -0
  96. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIActivityIndicatorView.h +52 -0
  97. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIActivityIndicatorView.m +152 -0
  98. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIAlertView.h +73 -0
  99. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIAlertView.m +234 -0
  100. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIButton.h +97 -0
  101. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIButton.m +424 -0
  102. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIDatePicker.h +78 -0
  103. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIDatePicker.m +362 -0
  104. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIGridCell.h +82 -0
  105. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIGridCell.m +298 -0
  106. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIImageView.h +110 -0
  107. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIImageView.m +541 -0
  108. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIKeyboard.h +74 -0
  109. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIKeyboard.m +243 -0
  110. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UILabel.h +46 -0
  111. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UILabel.m +99 -0
  112. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIMatrixView.h +124 -0
  113. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIMatrixView.m +821 -0
  114. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UINavigationBar.h +57 -0
  115. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UINavigationBar.m +161 -0
  116. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIOrientation.h +60 -0
  117. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIOrientation.m +146 -0
  118. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIPageControl.h +61 -0
  119. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIPageControl.m +190 -0
  120. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIProgressView.h +47 -0
  121. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIProgressView.m +113 -0
  122. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIPullLoader.h +71 -0
  123. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIPullLoader.m +236 -0
  124. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIScrollView.h +146 -0
  125. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIScrollView.m +1487 -0
  126. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UISegmentedControl.h +60 -0
  127. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UISegmentedControl.m +192 -0
  128. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UISignal.h +126 -0
  129. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UISignal.m +453 -0
  130. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UITabBar.h +70 -0
  131. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UITabBar.m +249 -0
  132. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UITextField.h +67 -0
  133. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UITextField.m +242 -0
  134. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UITextView.h +75 -0
  135. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UITextView.m +311 -0
  136. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UITipsView.h +184 -0
  137. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UITipsView.m +911 -0
  138. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIWebView.h +65 -0
  139. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIWebView.m +242 -0
  140. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIZoomView.h +91 -0
  141. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_UIZoomView.m +444 -0
  142. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_View.h +72 -0
  143. data/test.xctemplate/libs/BeeFramework/MVC/View/Bee_View.m +38 -0
  144. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/CGRect+BeeExtension.h +79 -0
  145. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/CGRect+BeeExtension.m +288 -0
  146. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIColor+BeeExtension.h +65 -0
  147. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIColor+BeeExtension.m +161 -0
  148. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIFont+BeeExtension.h +45 -0
  149. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIFont+BeeExtension.m +137 -0
  150. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIImage+BeeExtension.h +56 -0
  151. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIImage+BeeExtension.m +218 -0
  152. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+BeeExtension.h +105 -0
  153. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+BeeExtension.m +556 -0
  154. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+BeeUISignal.h +53 -0
  155. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+BeeUISignal.m +104 -0
  156. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+HoldGesture.h +52 -0
  157. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+HoldGesture.m +170 -0
  158. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+PanGesture.h +54 -0
  159. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+PanGesture.m +166 -0
  160. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+SwipeGesture.h +54 -0
  161. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+SwipeGesture.m +184 -0
  162. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+TapGesture.h +57 -0
  163. data/test.xctemplate/libs/BeeFramework/MVC/View/Extension/UIView+TapGesture.m +275 -0
  164. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Bee_UIBoard.h +212 -0
  165. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Bee_UIBoard.m +1219 -0
  166. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Bee_UIStack.h +111 -0
  167. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Bee_UIStack.m +694 -0
  168. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Bee_UIStackGroup.h +71 -0
  169. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Bee_UIStackGroup.m +258 -0
  170. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Bee_ViewController.h +45 -0
  171. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Bee_ViewController.m +36 -0
  172. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Extension/UIViewController+BeeExtension.h +57 -0
  173. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Extension/UIViewController+BeeExtension.m +151 -0
  174. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Extension/UIViewController+BeeUISignal.h +53 -0
  175. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Extension/UIViewController+BeeUISignal.m +92 -0
  176. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Extension/UIViewController+UINavigationBar.h +72 -0
  177. data/test.xctemplate/libs/BeeFramework/MVC/ViewController/Extension/UIViewController+UINavigationBar.m +175 -0
  178. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UICollection.h +59 -0
  179. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UICollection.m +249 -0
  180. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UILayout.h +199 -0
  181. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UILayout.m +1170 -0
  182. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UIQuery.h +113 -0
  183. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UIQuery.m +710 -0
  184. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UIStyle.h +66 -0
  185. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UIStyle.m +189 -0
  186. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplate.h +69 -0
  187. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplate.m +210 -0
  188. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateAndroid.h +45 -0
  189. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateAndroid.m +59 -0
  190. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateHTML.h +45 -0
  191. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateHTML.m +55 -0
  192. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateJSON.h +45 -0
  193. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateJSON.m +54 -0
  194. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateOmniGraffle.h +45 -0
  195. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateOmniGraffle.m +54 -0
  196. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateXML.h +45 -0
  197. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_UITemplateXML.m +438 -0
  198. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_ViewLayout.h +60 -0
  199. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Bee_ViewLayout.m +37 -0
  200. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/BeeUIQuery+BeeUIStyle.h +45 -0
  201. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/BeeUIQuery+BeeUIStyle.m +55 -0
  202. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/BeeUIStyle+BeeUIQuery.h +45 -0
  203. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/BeeUIStyle+BeeUIQuery.m +55 -0
  204. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIButton+BeeUIStyle.h +41 -0
  205. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIButton+BeeUIStyle.m +100 -0
  206. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIImageView+BeeUIStyle.h +41 -0
  207. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIImageView+BeeUIStyle.m +101 -0
  208. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UILabel+BeeUIStyle.h +41 -0
  209. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UILabel+BeeUIStyle.m +48 -0
  210. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UITextField+BeeUIStyle.h +41 -0
  211. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UITextField+BeeUIStyle.m +77 -0
  212. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UITextView+BeeUIStyle.h +41 -0
  213. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UITextView+BeeUIStyle.m +47 -0
  214. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIView+BeeUILayout.h +52 -0
  215. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIView+BeeUILayout.m +177 -0
  216. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIView+BeeUIQuery.h +44 -0
  217. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIView+BeeUIQuery.m +57 -0
  218. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIView+BeeUIStyle.h +50 -0
  219. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIView+BeeUIStyle.m +283 -0
  220. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIViewController+BeeUILayout.h +52 -0
  221. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIViewController+BeeUILayout.m +178 -0
  222. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIViewController+BeeUIQuery.h +44 -0
  223. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIViewController+BeeUIQuery.m +58 -0
  224. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIViewController+BeeUIStyle.h +44 -0
  225. data/test.xctemplate/libs/BeeFramework/MVC/ViewLayout/Extension/UIViewController+BeeUIStyle.m +57 -0
  226. metadata +226 -3
@@ -0,0 +1,1956 @@
1
+ //
2
+ // ______ ______ ______
3
+ // /\ __ \ /\ ___\ /\ ___\
4
+ // \ \ __< \ \ __\_ \ \ __\_
5
+ // \ \_____\ \ \_____\ \ \_____\
6
+ // \/_____/ \/_____/ \/_____/
7
+ //
8
+ // Copyright (c) 2012 BEE creators
9
+ // http://www.whatsbug.com
10
+ //
11
+ // Permission is hereby granted, free of charge, to any person obtaining a
12
+ // copy of this software and associated documentation files (the "Software"),
13
+ // to deal in the Software without restriction, including without limitation
14
+ // the rights to use, copy, modify, merge, publish, distribute, sublicense,
15
+ // and/or sell copies of the Software, and to permit persons to whom the
16
+ // Software is furnished to do so, subject to the following conditions:
17
+ //
18
+ // The above copyright notice and this permission notice shall be included in
19
+ // all copies or substantial portions of the Software.
20
+ //
21
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27
+ // IN THE SOFTWARE.
28
+ //
29
+ //
30
+ // Bee_ActiveRecord.h
31
+ //
32
+
33
+ #import "Bee_Precompile.h"
34
+ #import "Bee_Log.h"
35
+ #import "Bee_Runtime.h"
36
+
37
+ #import "NSObject+BeeTypeConversion.h"
38
+ #import "NSDictionary+BeeExtension.h"
39
+ #import "NSNumber+BeeExtension.h"
40
+ #import "NSObject+BeeDatabase.h"
41
+
42
+ #import "Bee_Database.h"
43
+ #import "Bee_ActiveBase.h"
44
+ #import "Bee_ActiveRecord.h"
45
+
46
+ #import "JSONKit.h"
47
+
48
+ #include <objc/runtime.h>
49
+
50
+ #pragma mark -
51
+
52
+ #undef __USE_ID_AS_KEY__
53
+ #define __USE_ID_AS_KEY__ (1) // 默认使用.id做为主键
54
+
55
+ #undef __USE_FIRST_AS_KEY__
56
+ #define __USE_FIRST_AS_KEY__ (1) // 默认使用第一个NSNumber类型的字段做为主键
57
+
58
+ #undef __USE_JSON_DEFAULT__
59
+ #define __USE_JSON_DEFAULT__ (1) // 默认保存JSON
60
+
61
+ #pragma mark -
62
+
63
+ @interface BeeActiveRecord()
64
+ - (void)initSelf;
65
+ - (void)setObservers;
66
+ - (void)resetProperties;
67
+ - (void)setPropertiesFrom:(NSDictionary *)dict;
68
+ + (void)setAssociateConditions;
69
+ + (void)setHasConditions;
70
+ @end
71
+
72
+ #pragma mark -
73
+
74
+ @implementation BeeActiveRecord
75
+
76
+ @dynamic primaryKey;
77
+ @dynamic primaryID;
78
+
79
+ @dynamic EXISTS;
80
+ @dynamic LOAD;
81
+ @dynamic SAVE;
82
+ @dynamic INSERT;
83
+ @dynamic UPDATE;
84
+ @dynamic DELETE;
85
+
86
+ @dynamic inserted;
87
+ @synthesize changed = _changed;
88
+ @synthesize deleted = _deleted;
89
+
90
+ @dynamic JSON;
91
+ @dynamic JSONData;
92
+ @dynamic JSONString;
93
+
94
+ + (BeeDatabase *)DB
95
+ {
96
+ [self prepareOnceWithRootClass:[BeeActiveRecord class]];
97
+
98
+ return super.DB.CLASS_TYPE( self );
99
+ }
100
+
101
+ + (NSString *)activePrimaryKeyFor:(Class)clazz
102
+ {
103
+ NSString * key = [super activePrimaryKeyFor:clazz];
104
+ if ( nil == key )
105
+ {
106
+ key = @"id";
107
+ }
108
+
109
+ return key;
110
+ }
111
+
112
+ + (NSString *)activeJSONKeyFor:(Class)clazz
113
+ {
114
+ NSString * key = [super activeJSONKeyFor:clazz];
115
+ if ( nil == key )
116
+ {
117
+ key = @"JSON";
118
+ }
119
+
120
+ return key;
121
+ }
122
+
123
+ + (void)mapRelation
124
+ {
125
+ #if defined(__USE_ID_AS_KEY__) && __USE_ID_AS_KEY__
126
+ BOOL foundPrimaryKey = NO;
127
+ #endif // #if defined(__USE_ID_AS_KEY__) && __USE_ID_AS_KEY__
128
+
129
+ for ( Class clazzType = self;; )
130
+ {
131
+ NSUInteger propertyCount = 0;
132
+ objc_property_t * properties = class_copyPropertyList( clazzType, &propertyCount );
133
+
134
+ for ( NSUInteger i = 0; i < propertyCount; i++ )
135
+ {
136
+ const char * name = property_getName(properties[i]);
137
+ NSString * propertyName = [NSString stringWithCString:name encoding:NSUTF8StringEncoding];
138
+
139
+ if ( [propertyName hasSuffix:@"_"] )
140
+ continue;
141
+
142
+ const char * attr = property_getAttributes(properties[i]);
143
+ NSUInteger type = [BeeTypeEncoding typeOf:attr];
144
+
145
+ NSString * className = nil;
146
+ BOOL isActiveRecord = NO;
147
+
148
+ NSObject * defaultValue = nil;
149
+ BOOL isPrimaryKey = NO;
150
+
151
+ if ( BeeTypeEncoding.NSNUMBER == type )
152
+ {
153
+ #if defined(__USE_ID_AS_KEY__) && __USE_ID_AS_KEY__
154
+ if ( NO == foundPrimaryKey && NSOrderedSame == [propertyName compare:@"id" options:NSCaseInsensitiveSearch] )
155
+ {
156
+ isPrimaryKey = YES;
157
+ foundPrimaryKey = YES;
158
+ }
159
+ #endif // #if defined(__USE_ID_AS_KEY__) && __USE_ID_AS_KEY__
160
+
161
+ #if defined(__USE_FIRST_AS_KEY__) && __USE_FIRST_AS_KEY__
162
+ if ( NO == foundPrimaryKey )
163
+ {
164
+ isPrimaryKey = YES;
165
+ foundPrimaryKey = YES;
166
+ }
167
+ #endif // #if defined(__USE_FIRST_AS_KEY__) && __USE_FIRST_AS_KEY__
168
+
169
+ if ( isPrimaryKey )
170
+ {
171
+ defaultValue = nil; // __INT(-1);
172
+ }
173
+ else
174
+ {
175
+ defaultValue = __INT(0);
176
+ }
177
+ }
178
+ else if ( BeeTypeEncoding.NSSTRING == type )
179
+ {
180
+ defaultValue = @"";
181
+ }
182
+ else if ( BeeTypeEncoding.NSDATE == type )
183
+ {
184
+ defaultValue = [NSDate dateWithTimeIntervalSince1970:0];
185
+ }
186
+ // else if ( BeeTypeEncoding.NSARRAY == type )
187
+ // {
188
+ // defaultValue = @"";
189
+ // }
190
+ // else if ( BeeTypeEncoding.NSDICTIONARY == type )
191
+ // {
192
+ // defaultValue = @"";
193
+ // }
194
+ else if ( BeeTypeEncoding.OBJECT == type )
195
+ {
196
+ defaultValue = __INT(0); // 嵌套的AR对象的主键
197
+
198
+ className = [BeeTypeEncoding classNameOf:attr];
199
+
200
+ Class class = NSClassFromString( className );
201
+ if ( [class isSubclassOfClass:[BeeActiveRecord class]] )
202
+ {
203
+ isActiveRecord = YES;
204
+ }
205
+ }
206
+ else
207
+ {
208
+ defaultValue = @"";
209
+ }
210
+
211
+ if ( isActiveRecord )
212
+ {
213
+ [self mapProperty:propertyName forClass:className atPath:nil defaultValue:defaultValue];
214
+ }
215
+ else
216
+ {
217
+ if ( isPrimaryKey )
218
+ {
219
+ [self mapPropertyAsKey:propertyName atPath:nil defaultValue:defaultValue];
220
+ }
221
+ else
222
+ {
223
+ [self mapProperty:propertyName atPath:nil defaultValue:defaultValue];
224
+ }
225
+ }
226
+ }
227
+
228
+ clazzType = class_getSuperclass( clazzType );
229
+ if ( nil == clazzType || clazzType == [BeeActiveRecord class] )
230
+ break;
231
+ }
232
+ }
233
+
234
+ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
235
+ {
236
+ if ( _deleted )
237
+ return;
238
+
239
+ NSDictionary * property = (NSDictionary *)context;
240
+ if ( nil == property )
241
+ return;
242
+
243
+ static BOOL __enterred = NO;
244
+ if ( NO == __enterred )
245
+ {
246
+ __enterred = YES;
247
+
248
+ NSObject * obj1 = [change objectForKey:@"new"];
249
+ NSObject * obj2 = [change objectForKey:@"old"];
250
+
251
+ if ( NO == [obj1 isEqual:obj2] )
252
+ {
253
+ _changed = YES;
254
+ }
255
+
256
+ NSString * name = [property objectForKey:@"name"];
257
+ NSString * path = [property objectForKey:@"path"];
258
+ NSNumber * type = [property objectForKey:@"type"];
259
+
260
+ NSObject * value = [change objectForKey:@"new"]; // [self valueForKey:name];
261
+
262
+ if ( object == self )
263
+ {
264
+ // sync property to JSON
265
+
266
+ // NSObject * value = [self valueForKey:name];
267
+ if ( value && NO == [value isKindOfClass:[NonValue class]] )
268
+ {
269
+ if ( BeeTypeEncoding.NSNUMBER == type.intValue )
270
+ {
271
+ value = [value asNSNumber];
272
+ }
273
+ else if ( BeeTypeEncoding.NSSTRING == type.intValue )
274
+ {
275
+ value = [value asNSString];
276
+ }
277
+ else if ( BeeTypeEncoding.NSDATE == type.intValue )
278
+ {
279
+ value = [value asNSString];
280
+ }
281
+ else if ( BeeTypeEncoding.OBJECT == type.intValue )
282
+ {
283
+ // 如果嵌套的AR对象变了,对应替换掉整个JSON
284
+
285
+ if ( [value isKindOfClass:[BeeActiveRecord class]] )
286
+ {
287
+ value = [(BeeActiveRecord *)value JSON];
288
+ }
289
+ else
290
+ {
291
+ value = nil;
292
+ }
293
+ }
294
+ }
295
+
296
+ if ( path && value )
297
+ {
298
+ [_JSON setObject:value atPath:path];
299
+ }
300
+ }
301
+ else if ( object == _JSON )
302
+ {
303
+ // sync JSON to property
304
+
305
+ // NSObject * value = [_JSON objectAtPath:path];
306
+ if ( value )
307
+ {
308
+ if ( BeeTypeEncoding.NSNUMBER == type.intValue )
309
+ {
310
+ value = [value asNSNumber];
311
+ }
312
+ else if ( BeeTypeEncoding.NSSTRING == type.intValue )
313
+ {
314
+ value = [value asNSString];
315
+ }
316
+ else if ( BeeTypeEncoding.NSDATE == type.intValue )
317
+ {
318
+ value = [value asNSDate];
319
+ }
320
+ else if ( BeeTypeEncoding.OBJECT == type.intValue )
321
+ {
322
+ // 如果嵌套的JSON对象变了,对应替换AR对象
323
+
324
+ NSString * className = [property objectForKey:@"className"];
325
+ if ( className )
326
+ {
327
+ Class class = NSClassFromString( className );
328
+ if ( [class isSubclassOfClass:[BeeActiveRecord class]] )
329
+ {
330
+ value = [class recordWithObject:value];
331
+ }
332
+ else
333
+ {
334
+ value = nil;
335
+ }
336
+ }
337
+ else
338
+ {
339
+ value = nil;
340
+ }
341
+ }
342
+ }
343
+
344
+ [self setValue:value forKey:name];
345
+ }
346
+
347
+ __enterred = NO;
348
+ }
349
+ }
350
+
351
+ - (void)initSelf
352
+ {
353
+ [[self class] prepareOnceWithRootClass:[BeeActiveRecord class]];
354
+
355
+ #if !defined(__USE_JSON_DEFAULT__) || (!__USE_JSON_DEFAULT__)
356
+ if ( [[self class] usingJSON] )
357
+ #endif // #if !defined(__USE_JSON_DEFAULT__) || (!__USE_JSON_DEFAULT__)
358
+ {
359
+ _JSON = [[NSMutableDictionary alloc] init];
360
+ }
361
+
362
+ [self resetProperties];
363
+ }
364
+
365
+ - (void)resetProperties
366
+ {
367
+ _changed = NO;
368
+ _deleted = NO;
369
+
370
+ NSMutableDictionary * propertySet = self.activePropertySet;
371
+ if ( nil == propertySet )
372
+ return;
373
+
374
+ NSString * primaryKey = self.activePrimaryKey;
375
+ if ( primaryKey )
376
+ {
377
+ [self setValue:[NSNumber numberWithInt:-1] forKey:primaryKey];
378
+ }
379
+
380
+ NSString * JSONKey = self.activeJSONKey;
381
+ if ( _JSON )
382
+ {
383
+ [_JSON removeAllObjects];
384
+
385
+ NSDictionary * property = [propertySet objectForKey:JSONKey];
386
+ if ( property )
387
+ {
388
+ NSString * path = [property objectForKey:@"path"];
389
+ [_JSON setObject:[NSNumber numberWithInt:-1] atPath:path];
390
+ }
391
+ }
392
+
393
+ if ( propertySet && propertySet.count )
394
+ {
395
+ for ( NSString * key in propertySet.allKeys )
396
+ {
397
+ NSDictionary * property = [propertySet objectForKey:key];
398
+
399
+ NSString * name = [property objectForKey:@"name"];
400
+ NSString * path = [property objectForKey:@"path"];
401
+ NSNumber * type = [property objectForKey:@"type"];
402
+
403
+ NSObject * json = nil;
404
+ NSObject * value = [property objectForKey:@"value"];
405
+ if ( value && NO == [value isKindOfClass:[NonValue class]] )
406
+ {
407
+ if ( value )
408
+ {
409
+ if ( BeeTypeEncoding.NSNUMBER == type.intValue )
410
+ {
411
+ value = [value asNSNumber];
412
+ json = value;
413
+ }
414
+ else if ( BeeTypeEncoding.NSSTRING == type.intValue )
415
+ {
416
+ value = [value asNSString];
417
+ json = value;
418
+ }
419
+ else if ( BeeTypeEncoding.NSDATE == type.intValue )
420
+ {
421
+ value = [value asNSString];
422
+ json = value;
423
+ }
424
+ else if ( BeeTypeEncoding.OBJECT == type.intValue )
425
+ {
426
+ BeeActiveRecord * arValue = nil;
427
+
428
+ // 尝试创建默认的AR对象
429
+ NSString * className = [property objectForKey:@"className"];
430
+ if ( className )
431
+ {
432
+ Class class = NSClassFromString( className );
433
+ if ( [class isSubclassOfClass:[BeeActiveRecord class]] )
434
+ {
435
+ NSNumber * primaryKey = [value asNSNumber];
436
+ if ( primaryKey && primaryKey.unsignedIntValue )
437
+ {
438
+ arValue = [class recordWithKey:[value asNSNumber]];
439
+ }
440
+ else
441
+ {
442
+ arValue = [class record];
443
+ }
444
+ }
445
+ }
446
+
447
+ value = arValue;
448
+ json = [arValue JSON];
449
+ }
450
+ }
451
+
452
+ [self setValue:value forKey:name];
453
+
454
+ if ( json )
455
+ {
456
+ [_JSON setObject:json atPath:path];
457
+ }
458
+ // else
459
+ // {
460
+ // [_JSON setObject:nil atPath:path];
461
+ // }
462
+ }
463
+ }
464
+ }
465
+ }
466
+
467
+ - (void)setObservers
468
+ {
469
+ NSMutableDictionary * propertySet = self.activePropertySet;
470
+ if ( propertySet && propertySet.count )
471
+ {
472
+ for ( NSString * key in propertySet.allKeys )
473
+ {
474
+ NSDictionary * property = [propertySet objectForKey:key];
475
+
476
+ NSString * name = [property objectForKey:@"name"];
477
+ NSString * path = [property objectForKey:@"path"];
478
+
479
+ [self addObserver:self
480
+ forKeyPath:name
481
+ options:NSKeyValueObservingOptionNew//|NSKeyValueObservingOptionOld
482
+ context:property];
483
+
484
+ [_JSON addObserver:self
485
+ forKeyPath:path
486
+ options:NSKeyValueObservingOptionNew//|NSKeyValueObservingOptionOld
487
+ context:property];
488
+ }
489
+ }
490
+ }
491
+
492
+ - (void)removeObservers
493
+ {
494
+ NSMutableDictionary * propertySet = self.activePropertySet;
495
+ if ( propertySet && propertySet.count )
496
+ {
497
+ for ( NSString * key in propertySet.allKeys )
498
+ {
499
+ NSDictionary * property = [propertySet objectForKey:key];
500
+
501
+ NSString * name = [property objectForKey:@"name"];
502
+ NSString * path = [property objectForKey:@"path"];
503
+
504
+ [self removeObserver:self forKeyPath:name];
505
+ [_JSON removeObserver:self forKeyPath:path];
506
+ }
507
+ }
508
+ }
509
+
510
+ - (id)init
511
+ {
512
+ [BeeDatabase scopeEnter];
513
+
514
+ self = [super init];
515
+ if ( self )
516
+ {
517
+ [self initSelf];
518
+
519
+ _changed = NO;
520
+ _deleted = NO;
521
+
522
+ [self setObservers];
523
+ [self load];
524
+ }
525
+
526
+ [BeeDatabase scopeLeave];
527
+
528
+ return self;
529
+ }
530
+
531
+ - (id)initWithObject:(NSObject *)object
532
+ {
533
+ [BeeDatabase scopeEnter];
534
+
535
+ self = [super init];
536
+ if ( self )
537
+ {
538
+ [self initSelf];
539
+ [self setPrimaryID:[NSNumber numberWithInt:-1]];
540
+
541
+ if ( [object isKindOfClass:[NSNumber class]] )
542
+ {
543
+ NSString * primaryKey = self.primaryKey;
544
+ if ( primaryKey )
545
+ {
546
+ BeeDatabase * db = [self class].DB;
547
+ if ( db )
548
+ {
549
+ db.WHERE( self.primaryKey, object ).GET();
550
+ if ( db.succeed )
551
+ {
552
+ NSObject * obj = [db.resultArray objectAtIndex:0];
553
+ if ( [obj isKindOfClass:[NSDictionary class]] )
554
+ {
555
+ [self setDictionary:(NSDictionary *)obj];
556
+ [self setPrimaryID:(NSNumber *)object];
557
+ }
558
+ }
559
+ }
560
+ }
561
+ }
562
+ else if ( [object isKindOfClass:[NSString class]] )
563
+ {
564
+ NSString * json = [(NSString *)object stringByReplacingOccurrencesOfString:@"'" withString:@"\""];
565
+ NSObject * dict = [json objectFromJSONString];
566
+ if ( dict && [dict isKindOfClass:[NSDictionary class]] )
567
+ {
568
+ [self setDictionary:(NSDictionary *)dict];
569
+ }
570
+ }
571
+ else if ( [object isKindOfClass:[NSData class]] )
572
+ {
573
+ NSObject * dict = [(NSData *)object objectFromJSONData];
574
+ if ( dict && [dict isKindOfClass:[NSDictionary class]] )
575
+ {
576
+ [self setDictionary:(NSDictionary *)dict];
577
+ }
578
+ }
579
+ else if ( [object isKindOfClass:[NSDictionary class]] )
580
+ {
581
+ [self setDictionary:(NSDictionary *)object];
582
+ }
583
+ else if ( [object isKindOfClass:[BeeActiveRecord class]] )
584
+ {
585
+ [self setDictionary:((BeeActiveRecord *)object).JSON];
586
+ }
587
+ else
588
+ {
589
+ CC( @"Unknown object type" );
590
+ }
591
+
592
+ _changed = NO;
593
+ _deleted = NO;
594
+
595
+ [self setObservers];
596
+ [self load];
597
+ }
598
+
599
+ [BeeDatabase scopeLeave];
600
+
601
+ return self;
602
+ }
603
+
604
+ - (id)initWithDictionary:(NSDictionary *)otherDictionary
605
+ {
606
+ [BeeDatabase scopeEnter];
607
+
608
+ self = [super init];
609
+ if ( self )
610
+ {
611
+ [self initSelf];
612
+ [self setDictionary:otherDictionary];
613
+
614
+ _changed = NO;
615
+ _deleted = NO;
616
+
617
+ [self setObservers];
618
+ [self load];
619
+ }
620
+
621
+ [BeeDatabase scopeLeave];
622
+
623
+ return self;
624
+ }
625
+
626
+ - (id)initWithJSONData:(NSData *)data
627
+ {
628
+ [BeeDatabase scopeEnter];
629
+
630
+ self = [super init];
631
+ if ( self )
632
+ {
633
+ [self initSelf];
634
+
635
+ NSObject * object = [data objectFromJSONData];
636
+ if ( object && [object isKindOfClass:[NSDictionary class]] )
637
+ {
638
+ [self setDictionary:(NSDictionary *)object];
639
+ }
640
+
641
+ _changed = NO;
642
+ _deleted = NO;
643
+
644
+ [self setObservers];
645
+ [self load];
646
+ }
647
+
648
+ [BeeDatabase scopeLeave];
649
+
650
+ return self;
651
+ }
652
+
653
+ - (id)initWithJSONString:(NSString *)string
654
+ {
655
+ [BeeDatabase scopeEnter];
656
+
657
+ self = [super init];
658
+ if ( self )
659
+ {
660
+ [self initSelf];
661
+
662
+ NSObject * object = [string objectFromJSONString];
663
+ if ( object && [object isKindOfClass:[NSDictionary class]] )
664
+ {
665
+ [self setDictionary:(NSDictionary *)object];
666
+ }
667
+
668
+ _changed = NO;
669
+ _deleted = NO;
670
+
671
+ [self setObservers];
672
+ [self load];
673
+ }
674
+
675
+ [BeeDatabase scopeLeave];
676
+
677
+ return self;
678
+ }
679
+
680
+ + (id)record
681
+ {
682
+ return [[[[self class] alloc] init] autorelease];
683
+ }
684
+
685
+ + (id)record:(NSObject *)otherObject
686
+ {
687
+ if ( [otherObject isKindOfClass:[NSNull class]] )
688
+ return nil;
689
+
690
+ return [[[[self class] alloc] initWithObject:otherObject] autorelease];
691
+ }
692
+
693
+ + (id)recordWithKey:(NSNumber *)key
694
+ {
695
+ if ( nil == key )
696
+ return nil;
697
+
698
+ return [[[[self class] alloc] initWithObject:key] autorelease];
699
+ }
700
+
701
+ + (id)recordWithObject:(NSObject *)otherObject
702
+ {
703
+ if ( [otherObject isKindOfClass:[NSNull class]] )
704
+ return nil;
705
+
706
+ return [[[[self class] alloc] initWithObject:otherObject] autorelease];
707
+ }
708
+
709
+ + (id)recordWithDictionary:(NSDictionary *)dict
710
+ {
711
+ return [[[[self class] alloc] initWithDictionary:dict] autorelease];
712
+ }
713
+
714
+ + (id)recordWithJSONData:(NSData *)data
715
+ {
716
+ return [[[[self class] alloc] initWithJSONData:data] autorelease];
717
+ }
718
+
719
+ + (id)recordWithJSONString:(NSString *)string
720
+ {
721
+ return [[[[self class] alloc] initWithJSONString:string] autorelease];
722
+ }
723
+
724
+ - (void)load
725
+ {
726
+
727
+ }
728
+
729
+ - (void)unload
730
+ {
731
+
732
+ }
733
+
734
+ - (void)dealloc
735
+ {
736
+ // [self update];
737
+
738
+ [self unload];
739
+ [self removeObservers];
740
+
741
+ [_JSON release];
742
+
743
+ [super dealloc];
744
+ }
745
+
746
+ - (id)valueForUndefinedKey:(NSString *)key
747
+ {
748
+ return nil;
749
+ }
750
+
751
+ - (void)setValue:(id)value forUndefinedKey:(NSString *)key
752
+ {
753
+ CC( @"[ERROR] undefined key '%@'", key );
754
+ }
755
+
756
+ - (NSString *)description
757
+ {
758
+ NSMutableString * desc = [NSMutableString string];
759
+ NSMutableDictionary * propertySet = self.activePropertySet;
760
+
761
+ [desc appendFormat:@"%s(%p) = { ", class_getName( [self class] ), self];
762
+
763
+ BOOL first = YES;
764
+
765
+ for ( NSString * key in propertySet.allKeys )
766
+ {
767
+ NSDictionary * property = [propertySet objectForKey:key];
768
+
769
+ NSString * name = [property objectForKey:@"name"];
770
+ NSNumber * type = [property objectForKey:@"type"];
771
+
772
+ NSObject * value = [self valueForKey:name];
773
+ if ( value && NO == [value isKindOfClass:[NonValue class]] )
774
+ {
775
+ if ( NO == first )
776
+ {
777
+ [desc appendFormat:@", "];
778
+ }
779
+
780
+ if ( BeeTypeEncoding.NSNUMBER == type.intValue )
781
+ {
782
+ value = [value asNSNumber];
783
+
784
+ [desc appendFormat:@"'%@' : %@", name, value];
785
+ }
786
+ else if ( BeeTypeEncoding.NSSTRING == type.intValue )
787
+ {
788
+ value = [value asNSString];
789
+
790
+ [desc appendFormat:@"'%@' : '%@'", name, value];
791
+ }
792
+ else if ( BeeTypeEncoding.NSDATE == type.intValue )
793
+ {
794
+ value = [value asNSDate];
795
+
796
+ [desc appendFormat:@"'%@' : '%@'", name, value];
797
+ }
798
+ else
799
+ {
800
+ // value = [value asNSNumber];
801
+
802
+ [desc appendFormat:@"'%@' : <%@>", name, value];
803
+ }
804
+
805
+ first = NO;
806
+ }
807
+ }
808
+
809
+ [desc appendFormat:@" }"];
810
+
811
+ return desc;
812
+ }
813
+
814
+ + (void)setAssociateConditions
815
+ {
816
+ NSMutableDictionary * propertySet = [[self class] activePropertySet];
817
+
818
+ for ( NSString * key in propertySet.allKeys )
819
+ {
820
+ NSDictionary * property = [propertySet objectForKey:key];
821
+
822
+ NSString * name = [property objectForKey:@"name"];
823
+ NSNumber * type = [property objectForKey:@"type"];
824
+
825
+ NSString * associateClass = [property objectForKey:@"associateClass"];
826
+ NSString * associateProperty = [property objectForKey:@"associateProperty"];
827
+
828
+ NSMutableArray * values = [NSMutableArray array];
829
+
830
+ if ( associateClass )
831
+ {
832
+ Class classType = NSClassFromString( associateClass );
833
+ if ( classType )
834
+ {
835
+ NSArray * objs = [super.DB associateObjectsFor:classType];
836
+ for ( NSObject * obj in objs )
837
+ {
838
+ if ( associateProperty )
839
+ {
840
+ NSObject * value = [obj valueForKey:associateProperty];
841
+ [values addObject:value];
842
+ }
843
+ else
844
+ {
845
+ NSObject * value = [obj valueForKey:classType.activePrimaryKey];
846
+ [values addObject:value];
847
+ }
848
+ }
849
+ }
850
+ }
851
+
852
+ for ( NSObject * value in values )
853
+ {
854
+ if ( value && NO == [value isKindOfClass:[NonValue class]] )
855
+ {
856
+ if ( BeeTypeEncoding.NSNUMBER == type.intValue )
857
+ {
858
+ value = [value asNSNumber];
859
+ }
860
+ else if ( BeeTypeEncoding.NSSTRING == type.intValue )
861
+ {
862
+ value = [value asNSString];
863
+ }
864
+ else if ( BeeTypeEncoding.NSDATE == type.intValue )
865
+ {
866
+ value = [[value asNSDate] description];
867
+ }
868
+ else
869
+ {
870
+ // value = [value asNSNumber];
871
+ }
872
+
873
+ super.DB.WHERE( name, value );
874
+ }
875
+ }
876
+ }
877
+ }
878
+
879
+ + (void)setHasConditions
880
+ {
881
+ NSArray * objs = [super.DB hasObjects];
882
+ for ( NSObject * obj in objs )
883
+ {
884
+ // TODO:
885
+
886
+ // Class clazz = [obj class];
887
+ // super.DB.WHERE( name, value );
888
+ }
889
+ }
890
+
891
+ - (void)setPropertiesFrom:(NSDictionary *)dict
892
+ {
893
+ // set properties
894
+
895
+ NSMutableDictionary * propertySet = self.activePropertySet;
896
+ for ( NSString * key in propertySet.allKeys )
897
+ {
898
+ NSDictionary * property = [propertySet objectForKey:key];
899
+
900
+ NSString * name = [property objectForKey:@"name"];
901
+ NSString * path = [property objectForKey:@"path"];
902
+ NSNumber * type = [property objectForKey:@"type"];
903
+
904
+ NSString * associateClass = [property objectForKey:@"associateClass"];
905
+ NSString * associateProperty = [property objectForKey:@"associateProperty"];
906
+
907
+ NSMutableArray * values = [NSMutableArray array];
908
+
909
+ if ( associateClass )
910
+ {
911
+ Class classType = NSClassFromString( associateClass );
912
+ if ( classType )
913
+ {
914
+ NSArray * objs = [super.DB associateObjectsFor:classType];
915
+ for ( NSObject * obj in objs )
916
+ {
917
+ if ( associateProperty )
918
+ {
919
+ NSObject * value = [obj valueForKey:associateProperty];
920
+ [values addObject:value];
921
+ }
922
+ else
923
+ {
924
+ NSObject * value = [obj valueForKey:classType.activePrimaryKey];
925
+ [values addObject:value];
926
+ }
927
+ }
928
+ }
929
+ }
930
+
931
+ NSObject * value = values.count ? values.lastObject : nil;
932
+
933
+ if ( nil == value )
934
+ {
935
+ value = [dict objectAtPath:path];
936
+ }
937
+
938
+ if ( value && NO == [value isKindOfClass:[NonValue class]] )
939
+ {
940
+ if ( BeeTypeEncoding.NSNUMBER == type.intValue )
941
+ {
942
+ value = [value asNSNumber];
943
+ }
944
+ else if ( BeeTypeEncoding.NSSTRING == type.intValue )
945
+ {
946
+ value = [value asNSString];
947
+ }
948
+ else if ( BeeTypeEncoding.NSDATE == type.intValue )
949
+ {
950
+ value = [value asNSDate];
951
+ }
952
+ else if ( BeeTypeEncoding.OBJECT == type.intValue )
953
+ {
954
+ // set inner AR objects
955
+
956
+ BeeActiveRecord * record = nil;
957
+
958
+ NSString * className = [property objectForKey:@"className"];
959
+ if ( className )
960
+ {
961
+ Class class = NSClassFromString( className );
962
+ if ( [class isSubclassOfClass:[BeeActiveRecord class]] )
963
+ {
964
+ record = [class recordWithObject:value];
965
+ }
966
+ }
967
+
968
+ value = record;
969
+ }
970
+ else
971
+ {
972
+ // value = [value asNSNumber];
973
+ }
974
+
975
+ if ( name && value )
976
+ {
977
+ [self setValue:value forKey:name];
978
+ }
979
+ }
980
+ }
981
+
982
+ // reset flags
983
+
984
+ _changed = YES;
985
+ _deleted = NO;
986
+ }
987
+
988
+ - (void)setDictionary:(NSDictionary *)dict
989
+ {
990
+ [self resetProperties];
991
+ [self setPropertiesFrom:dict];
992
+
993
+ [_JSON setDictionary:dict];
994
+ }
995
+
996
+ - (NSDictionary *)JSON
997
+ {
998
+ return _JSON;
999
+ }
1000
+
1001
+ - (void)setJSON:(NSMutableDictionary *)JSON
1002
+ {
1003
+ [self setDictionary:JSON];
1004
+ }
1005
+
1006
+ - (NSData *)JSONData
1007
+ {
1008
+ return [_JSON JSONData];
1009
+ }
1010
+
1011
+ - (void)setJSONData:(NSData *)data
1012
+ {
1013
+ NSObject * object = [data objectFromJSONData];
1014
+ if ( object && [object isKindOfClass:[NSDictionary class]] )
1015
+ {
1016
+ [self setDictionary:(NSDictionary *)object];
1017
+ }
1018
+ }
1019
+
1020
+ - (NSString *)JSONString
1021
+ {
1022
+ NSString * json = [_JSON JSONString];
1023
+
1024
+ if ( json )
1025
+ {
1026
+ json = [json stringByReplacingOccurrencesOfString:@"\\\\\\\"" withString:@"\""];
1027
+ json = [json stringByReplacingOccurrencesOfString:@"\\\"" withString:@"\""];
1028
+ }
1029
+
1030
+ return json;
1031
+ }
1032
+
1033
+ - (void)setJSONString:(NSString *)string
1034
+ {
1035
+ NSObject * object = [string objectFromJSONString];
1036
+ if ( object && [object isKindOfClass:[NSDictionary class]] )
1037
+ {
1038
+ [self setDictionary:(NSDictionary *)object];
1039
+ }
1040
+ }
1041
+
1042
+ - (NSDictionary *)JSONDictionary
1043
+ {
1044
+ return [NSMutableDictionary dictionaryWithDictionary:self.JSON];
1045
+ }
1046
+
1047
+ - (NSString *)primaryKey
1048
+ {
1049
+ return self.activePrimaryKey;
1050
+ }
1051
+
1052
+ - (NSNumber *)primaryID
1053
+ {
1054
+ return [self valueForKey:self.activePrimaryKey];
1055
+ }
1056
+
1057
+ - (void)setPrimaryID:(NSNumber *)pid
1058
+ {
1059
+ [self setValue:(pid ? pid : [NSNumber numberWithInt:-1])
1060
+ forKey:self.activePrimaryKey];
1061
+ }
1062
+
1063
+ - (BOOL)inserted
1064
+ {
1065
+ NSNumber * number = self.primaryID;
1066
+ if ( number && number.intValue >= 0 )
1067
+ {
1068
+ return YES;
1069
+ }
1070
+
1071
+ return NO;
1072
+ }
1073
+
1074
+ - (BOOL)get
1075
+ {
1076
+ NSString * primaryKey = self.activePrimaryKey;
1077
+ if ( nil == primaryKey )
1078
+ return NO;
1079
+
1080
+ NSNumber * primaryID = [self valueForKey:primaryKey];
1081
+ if ( nil == primaryID || primaryID.intValue < 0 )
1082
+ return NO;
1083
+
1084
+ super.DB
1085
+ .FROM( self.tableName )
1086
+ .WHERE( primaryKey, [self valueForKey:primaryKey] )
1087
+ .LIMIT( 1 )
1088
+ .GET();
1089
+
1090
+ if ( super.DB.succeed )
1091
+ {
1092
+ NSDictionary * dict = [super.DB.resultArray objectAtIndex:0];
1093
+ if ( dict )
1094
+ {
1095
+ [self resetProperties];
1096
+ [self setPropertiesFrom:dict];
1097
+
1098
+ NSString * json = [dict objectForKey:self.activeJSONKey];
1099
+ if ( json && json.length )
1100
+ {
1101
+ NSObject * object = [json objectFromJSONString];
1102
+ if ( object && [object isKindOfClass:[NSDictionary class]] )
1103
+ {
1104
+ [_JSON removeAllObjects];
1105
+ [_JSON setDictionary:(NSDictionary *)object];
1106
+ }
1107
+ }
1108
+
1109
+ return YES;
1110
+ }
1111
+ }
1112
+
1113
+ return NO;
1114
+ }
1115
+
1116
+ - (BOOL)exists
1117
+ {
1118
+ NSString * primaryKey = self.activePrimaryKey;
1119
+ if ( nil == primaryKey )
1120
+ return NO;
1121
+
1122
+ NSNumber * primaryID = [self valueForKey:primaryKey];
1123
+ if ( nil == primaryID || primaryID.intValue < 0 )
1124
+ return NO;
1125
+
1126
+ super.DB
1127
+ .FROM( self.tableName )
1128
+ .WHERE( primaryKey, [self valueForKey:primaryKey] )
1129
+ .LIMIT( 1 )
1130
+ .COUNT();
1131
+
1132
+ if ( super.DB.succeed && super.DB.resultCount > 0 )
1133
+ {
1134
+ return YES;
1135
+ }
1136
+
1137
+ return NO;
1138
+ }
1139
+
1140
+ - (BOOL)insert
1141
+ {
1142
+ if ( _deleted )
1143
+ return NO;
1144
+
1145
+ // if already inserted into table, no nessecery insert again
1146
+
1147
+ NSString * primaryKey = self.activePrimaryKey;
1148
+ // NSNumber * primaryID = [self valueForKey:primaryKey];
1149
+ //
1150
+ // if ( primaryID && primaryID.intValue >= 0 )
1151
+ // return NO;
1152
+
1153
+ NSString * JSONKey = self.activeJSONKey;
1154
+ NSDictionary * propertySet = self.activePropertySet;
1155
+
1156
+ // step 1, save inner AR objects
1157
+
1158
+ for ( NSString * key in propertySet.allKeys )
1159
+ {
1160
+ NSDictionary * property = [propertySet objectForKey:key];
1161
+ NSNumber * type = [property objectForKey:@"type"];
1162
+
1163
+ if ( BeeTypeEncoding.OBJECT == type.intValue )
1164
+ {
1165
+ NSString * name = [property objectForKey:@"name"];
1166
+ NSObject * value = [self valueForKey:name];
1167
+
1168
+ if ( value && [value isKindOfClass:[BeeActiveRecord class]] )
1169
+ {
1170
+ BeeActiveRecord * record = (BeeActiveRecord *)value;
1171
+ [record exists] ? [record update] : [record insert];
1172
+ }
1173
+ }
1174
+ }
1175
+
1176
+ // step 2, save this object
1177
+
1178
+ super.DB.FROM( self.tableName );
1179
+
1180
+ for ( NSString * key in propertySet.allKeys )
1181
+ {
1182
+ NSDictionary * property = [propertySet objectForKey:key];
1183
+
1184
+ NSString * name = [property objectForKey:@"name"];
1185
+ NSNumber * type = [property objectForKey:@"type"];
1186
+
1187
+ NSString * byClass = [property objectForKey:@"byClass"];
1188
+ if ( byClass )
1189
+ {
1190
+ Class byClassType = NSClassFromString( byClass );
1191
+ if ( byClassType && [NSObject usingAutoIncrementFor:byClassType andProperty:name] )
1192
+ {
1193
+ continue;
1194
+ }
1195
+ }
1196
+
1197
+ if ( [name isEqualToString:JSONKey] )
1198
+ continue;
1199
+
1200
+ NSObject * value = [self valueForKey:name];
1201
+ if ( value )
1202
+ {
1203
+ if ( BeeTypeEncoding.NSNUMBER == type.intValue )
1204
+ {
1205
+ value = [value asNSNumber];
1206
+
1207
+ // bug fix
1208
+ if ( [name isEqualToString:primaryKey] && [(NSNumber *)value integerValue] < 0 )
1209
+ {
1210
+ continue;
1211
+ }
1212
+ }
1213
+ else if ( BeeTypeEncoding.NSSTRING == type.intValue )
1214
+ {
1215
+ value = [value asNSString];
1216
+ }
1217
+ else if ( BeeTypeEncoding.NSDATE == type.intValue )
1218
+ {
1219
+ value = [[value asNSDate] description];
1220
+ }
1221
+ else if ( BeeTypeEncoding.OBJECT == type.intValue )
1222
+ {
1223
+ if ( [value isKindOfClass:[BeeActiveRecord class]] )
1224
+ {
1225
+ BeeActiveRecord * record = (BeeActiveRecord *)value;
1226
+ NSString * primaryKey = [value class].activePrimaryKey;
1227
+
1228
+ value = [record valueForKey:primaryKey];
1229
+ }
1230
+ else
1231
+ {
1232
+ value = nil;
1233
+ }
1234
+ }
1235
+ else
1236
+ {
1237
+ // value = [value asNSNumber];
1238
+ }
1239
+
1240
+ if ( name && value )
1241
+ {
1242
+ super.DB.SET( name, value );
1243
+ }
1244
+ }
1245
+ }
1246
+
1247
+ if ( [[self class] usingJSON] )
1248
+ {
1249
+ super.DB.SET( self.activeJSONKey, self.JSONString );
1250
+ }
1251
+
1252
+ super.DB.INSERT();
1253
+
1254
+ if ( super.DB.succeed )
1255
+ {
1256
+ _changed = NO;
1257
+
1258
+ if ( primaryKey )
1259
+ {
1260
+ [self setValue:[NSNumber numberWithInt:super.DB.insertID] forKey:primaryKey];
1261
+ }
1262
+
1263
+ return YES;
1264
+ }
1265
+
1266
+ return NO;
1267
+ }
1268
+
1269
+ - (BOOL)update
1270
+ {
1271
+ if ( _deleted || NO == _changed )
1272
+ return NO;
1273
+
1274
+ // if already inserted into table, no nessecery insert again
1275
+
1276
+ NSString * primaryKey = self.activePrimaryKey;
1277
+ if ( nil == primaryKey )
1278
+ return NO;
1279
+
1280
+ NSNumber * primaryID = [self valueForKey:primaryKey];
1281
+ if ( primaryID && primaryID.intValue < 0 )
1282
+ return NO;
1283
+
1284
+ NSString * JSONKey = self.activeJSONKey;
1285
+ NSDictionary * propertySet = self.activePropertySet;
1286
+
1287
+ // step 1, update inner AR objects
1288
+
1289
+ for ( NSString * key in propertySet.allKeys )
1290
+ {
1291
+ NSDictionary * property = [propertySet objectForKey:key];
1292
+ NSNumber * type = [property objectForKey:@"type"];
1293
+
1294
+ if ( BeeTypeEncoding.OBJECT == type.intValue )
1295
+ {
1296
+ NSString * name = [property objectForKey:@"name"];
1297
+ NSObject * value = [self valueForKey:name];
1298
+
1299
+ if ( value && [value isKindOfClass:[BeeActiveRecord class]] )
1300
+ {
1301
+ BeeActiveRecord * record = (BeeActiveRecord *)value;
1302
+ [record exists] ? [record update] : [record insert];
1303
+ }
1304
+ }
1305
+ }
1306
+
1307
+ // step 2, update this object
1308
+
1309
+ super.DB
1310
+ .FROM( self.tableName )
1311
+ .WHERE( primaryKey, primaryID );
1312
+
1313
+ for ( NSString * key in propertySet.allKeys )
1314
+ {
1315
+ NSDictionary * property = [propertySet objectForKey:key];
1316
+
1317
+ NSString * name = [property objectForKey:@"name"];
1318
+ NSNumber * type = [property objectForKey:@"type"];
1319
+
1320
+ if ( [name isEqualToString:JSONKey] || [name isEqualToString:primaryKey] )
1321
+ continue;
1322
+
1323
+ NSObject * value = [self valueForKey:name];
1324
+ if ( value )
1325
+ {
1326
+ if ( BeeTypeEncoding.NSNUMBER == type.intValue )
1327
+ {
1328
+ value = [value asNSNumber];
1329
+ }
1330
+ else if ( BeeTypeEncoding.NSSTRING == type.intValue )
1331
+ {
1332
+ value = [value asNSString];
1333
+ }
1334
+ else if ( BeeTypeEncoding.NSDATE == type.intValue )
1335
+ {
1336
+ value = [[value asNSDate] description];
1337
+ }
1338
+ else if ( BeeTypeEncoding.OBJECT == type.intValue )
1339
+ {
1340
+ if ( [value isKindOfClass:[BeeActiveRecord class]] )
1341
+ {
1342
+ BeeActiveRecord * record = (BeeActiveRecord *)value;
1343
+ NSString * primaryKey = [value class].activePrimaryKey;
1344
+ if ( primaryKey )
1345
+ {
1346
+ value = [record valueForKey:primaryKey];
1347
+ }
1348
+ else
1349
+ {
1350
+ value = nil;
1351
+ }
1352
+ }
1353
+ else
1354
+ {
1355
+ value = nil;
1356
+ }
1357
+ }
1358
+ else
1359
+ {
1360
+ // value = [value asNSNumber];
1361
+ }
1362
+
1363
+ super.DB.SET( name, value );
1364
+ }
1365
+ }
1366
+
1367
+ if ( [[self class] usingJSON] )
1368
+ {
1369
+ super.DB.SET( self.activeJSONKey, self.JSONString );
1370
+ }
1371
+
1372
+ super.DB.UPDATE();
1373
+
1374
+ if ( super.DB.succeed )
1375
+ {
1376
+ _changed = NO;
1377
+ return YES;
1378
+ }
1379
+
1380
+ return NO;
1381
+ }
1382
+
1383
+ - (BOOL)delete
1384
+ {
1385
+ if ( _deleted )
1386
+ return NO;
1387
+
1388
+ NSString * primaryKey = self.activePrimaryKey;
1389
+ if ( nil == primaryKey )
1390
+ return NO;
1391
+
1392
+ NSObject * primaryID = [self valueForKey:primaryKey];
1393
+ if ( nil == primaryID )
1394
+ return NO;
1395
+
1396
+ super.DB
1397
+ .FROM( self.tableName )
1398
+ .WHERE( primaryKey, primaryID )
1399
+ .DELETE();
1400
+
1401
+ if ( super.DB.succeed )
1402
+ {
1403
+ NSString * JSONKey = self.activeJSONKey;
1404
+ NSDictionary * propertySet = self.activePropertySet;
1405
+
1406
+ [self setValue:[NSNumber numberWithInt:-1] forKey:primaryKey];
1407
+
1408
+ for ( NSString * key in propertySet.allKeys )
1409
+ {
1410
+ NSDictionary * property = [propertySet objectForKey:key];
1411
+
1412
+ NSString * name = [property objectForKey:@"name"];
1413
+ if ( [name isEqualToString:JSONKey] )
1414
+ continue;
1415
+
1416
+ NSObject * value = [property objectForKey:@"value"];
1417
+ if ( value && NO == [value isKindOfClass:[NonValue class]] )
1418
+ {
1419
+ [self setValue:value forKey:name];
1420
+ }
1421
+ else
1422
+ {
1423
+ [self setValue:nil forKey:name];
1424
+ }
1425
+ }
1426
+
1427
+ [_JSON removeAllObjects];
1428
+
1429
+ _changed = NO;
1430
+ _deleted = YES;
1431
+
1432
+ // // 将嵌套的AR对象也删一遍
1433
+ //
1434
+ // for ( NSString * key in propertySet.allKeys )
1435
+ // {
1436
+ // NSDictionary * property = [propertySet objectForKey:key];
1437
+ // NSNumber * type = [property objectForKey:@"type"];
1438
+ //
1439
+ // if ( BeeTypeEncoding.OBJECT == type.intValue )
1440
+ // {
1441
+ // NSString * name = [property objectForKey:@"name"];
1442
+ // NSObject * value = [self valueForKey:name];
1443
+ //
1444
+ // if ( value && [value isKindOfClass:[BeeActiveRecord class]] )
1445
+ // {
1446
+ // BeeActiveRecord * record = (BeeActiveRecord *)value;
1447
+ // [record delete];
1448
+ // }
1449
+ // }
1450
+ // }
1451
+
1452
+ return YES;
1453
+ }
1454
+
1455
+ return NO;
1456
+ }
1457
+
1458
+ - (BeeDatabaseBoolBlock)EXISTS
1459
+ {
1460
+ BeeDatabaseBoolBlock block = ^ BOOL ( void )
1461
+ {
1462
+ return [self exists];
1463
+ };
1464
+
1465
+ return [[block copy] autorelease];
1466
+ }
1467
+
1468
+ - (BeeDatabaseBoolBlock)INSERT
1469
+ {
1470
+ BeeDatabaseBoolBlock block = ^ BOOL ( void )
1471
+ {
1472
+ return [self insert];
1473
+ };
1474
+
1475
+ return [[block copy] autorelease];
1476
+ }
1477
+
1478
+ - (BeeDatabaseBoolBlock)UPDATE
1479
+ {
1480
+ BeeDatabaseBoolBlock block = ^ BOOL ( void )
1481
+ {
1482
+ return [self update];
1483
+ };
1484
+
1485
+ return [[block copy] autorelease];
1486
+ }
1487
+
1488
+ - (BeeDatabaseBoolBlock)DELETE
1489
+ {
1490
+ BeeDatabaseBoolBlock block = ^ BOOL ( void )
1491
+ {
1492
+ return [self delete];
1493
+ };
1494
+
1495
+ return [[block copy] autorelease];
1496
+ }
1497
+
1498
+ - (BeeDatabaseBoolBlock)LOAD
1499
+ {
1500
+ BeeDatabaseBoolBlock block = ^ BOOL ( void )
1501
+ {
1502
+ return [self get];
1503
+
1504
+ return YES;
1505
+ };
1506
+
1507
+ return [[block copy] autorelease];
1508
+ }
1509
+
1510
+ - (BeeDatabaseBoolBlock)SAVE
1511
+ {
1512
+ BeeDatabaseBoolBlock block = ^ BOOL ( void )
1513
+ {
1514
+ BOOL ret = [self exists];
1515
+ if ( NO == ret )
1516
+ {
1517
+ ret = [self insert];
1518
+ }
1519
+ else
1520
+ {
1521
+ ret = [self update];
1522
+ }
1523
+ return ret;
1524
+ };
1525
+
1526
+ return [[block copy] autorelease];
1527
+ }
1528
+
1529
+ @end
1530
+
1531
+ #pragma mark -
1532
+
1533
+ @implementation NSArray(BeeActiveRecord)
1534
+
1535
+ - (NSArray *)activeRecordsFromArray:(Class)clazz
1536
+ {
1537
+ NSMutableArray * array = [NSMutableArray array];
1538
+
1539
+ for ( NSObject * obj in self )
1540
+ {
1541
+ if ( [obj isKindOfClass:[NSDictionary class]] )
1542
+ {
1543
+ BeeActiveRecord * record = [(NSDictionary *)obj activeRecordFromDictionary:clazz];
1544
+ if ( record )
1545
+ {
1546
+ [array addObject:record];
1547
+ }
1548
+ }
1549
+ }
1550
+
1551
+ return array;
1552
+ }
1553
+
1554
+ @end
1555
+
1556
+ #pragma mark -
1557
+
1558
+ @implementation NSDictionary(BeeActiveRecord)
1559
+
1560
+ - (BeeActiveRecord *)activeRecordFromDictionary:(Class)clazz
1561
+ {
1562
+ if ( NO == [clazz isSubclassOfClass:[BeeActiveRecord class]] )
1563
+ return nil;
1564
+
1565
+ return [[[clazz alloc] initWithDictionary:self] autorelease];
1566
+ }
1567
+
1568
+ @end
1569
+
1570
+ #pragma mark -
1571
+
1572
+ @implementation BeeDatabase(BeeActiveRecord)
1573
+
1574
+ @dynamic SAVE;
1575
+ @dynamic SAVE_DATA;
1576
+ @dynamic SAVE_STRING;
1577
+ @dynamic SAVE_ARRAY;
1578
+ @dynamic SAVE_DICTIONARY;
1579
+
1580
+ @dynamic GET_RECORDS;
1581
+ @dynamic FIRST_RECORD;
1582
+ @dynamic FIRST_RECORD_BY_ID;
1583
+ @dynamic LAST_RECORD;
1584
+ @dynamic LAST_RECORD_BY_ID;
1585
+
1586
+ - (BeeDatabaseBlockN)SAVE
1587
+ {
1588
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
1589
+ {
1590
+ if ( [first isKindOfClass:[NSArray class]] )
1591
+ {
1592
+ return [self saveArray:(NSArray *)first];
1593
+ }
1594
+ else if ( [first isKindOfClass:[NSDictionary class]] )
1595
+ {
1596
+ return [self saveDictionary:(NSDictionary *)first];
1597
+ }
1598
+ else if ( [first isKindOfClass:[NSString class]] )
1599
+ {
1600
+ return [self saveString:(NSString *)first];
1601
+ }
1602
+ else if ( [first isKindOfClass:[NSData class]] )
1603
+ {
1604
+ return [self saveData:(NSData *)first];
1605
+ }
1606
+
1607
+ return self;
1608
+ };
1609
+
1610
+ return [[block copy] autorelease];
1611
+ }
1612
+
1613
+ - (BeeDatabaseBlockN)SAVE_DATA
1614
+ {
1615
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
1616
+ {
1617
+ return [self saveData:(NSData *)first];
1618
+ };
1619
+
1620
+ return [[block copy] autorelease];
1621
+ }
1622
+
1623
+ - (BeeDatabaseBlockN)SAVE_STRING
1624
+ {
1625
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
1626
+ {
1627
+ return [self saveString:(NSString *)first];
1628
+ };
1629
+
1630
+ return [[block copy] autorelease];
1631
+ }
1632
+
1633
+ - (BeeDatabaseBlockN)SAVE_ARRAY
1634
+ {
1635
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
1636
+ {
1637
+ return [self saveArray:(NSArray *)first];
1638
+ };
1639
+
1640
+ return [[block copy] autorelease];
1641
+ }
1642
+
1643
+ - (BeeDatabaseBlockN)SAVE_DICTIONARY
1644
+ {
1645
+ BeeDatabaseBlockN block = ^ BeeDatabase * ( id first, ... )
1646
+ {
1647
+ return [self saveDictionary:(NSDictionary *)first];
1648
+ };
1649
+
1650
+ return [[block copy] autorelease];
1651
+ }
1652
+
1653
+ - (BeeDatabaseArrayBlock)GET_RECORDS
1654
+ {
1655
+ BeeDatabaseArrayBlock block = ^ NSArray * ( void )
1656
+ {
1657
+ return [self getRecords];
1658
+ };
1659
+
1660
+ return [[block copy] autorelease];
1661
+ }
1662
+
1663
+ - (BeeDatabaseObjectBlock)FIRST_RECORD
1664
+ {
1665
+ BeeDatabaseObjectBlock block = ^ NSArray * ( void )
1666
+ {
1667
+ return [self firstRecord];
1668
+ };
1669
+
1670
+ return [[block copy] autorelease];
1671
+ }
1672
+
1673
+ - (BeeDatabaseObjectBlockN)FIRST_RECORD_BY_ID
1674
+ {
1675
+ BeeDatabaseObjectBlockN block = ^ NSArray * ( id first, ... )
1676
+ {
1677
+ return [self firstRecord:nil byID:first];
1678
+ };
1679
+
1680
+ return [[block copy] autorelease];
1681
+ }
1682
+
1683
+ - (BeeDatabaseObjectBlock)LAST_RECORD
1684
+ {
1685
+ BeeDatabaseObjectBlock block = ^ NSArray * ( void )
1686
+ {
1687
+ return [self lastRecord];
1688
+ };
1689
+
1690
+ return [[block copy] autorelease];
1691
+ }
1692
+
1693
+ - (BeeDatabaseObjectBlockN)LAST_RECORD_BY_ID
1694
+ {
1695
+ BeeDatabaseObjectBlockN block = ^ NSArray * ( id first, ... )
1696
+ {
1697
+ return [self lastRecord:nil byID:first];
1698
+ };
1699
+
1700
+ return [[block copy] autorelease];
1701
+ }
1702
+
1703
+ - (id)saveData:(NSData *)data
1704
+ {
1705
+ NSObject * obj = [data objectFromJSONData];
1706
+ if ( nil == obj )
1707
+ return self;
1708
+
1709
+ if ( [obj isKindOfClass:[NSArray class]] )
1710
+ {
1711
+ return [self saveArray:(NSArray *)obj];
1712
+ }
1713
+ else if ( [obj isKindOfClass:[NSDictionary class]] )
1714
+ {
1715
+ return [self saveDictionary:(NSDictionary *)obj];
1716
+ }
1717
+
1718
+ return self;
1719
+ }
1720
+
1721
+ - (id)saveString:(NSString *)string
1722
+ {
1723
+ if ( string && [string rangeOfString:@"'"].length > 0 )
1724
+ {
1725
+ string = [string stringByReplacingOccurrencesOfString:@"'" withString:@"\""];
1726
+ }
1727
+
1728
+ NSObject * obj = [string objectFromJSONString];
1729
+ if ( nil == obj )
1730
+ return self;
1731
+
1732
+ if ( [obj isKindOfClass:[NSArray class]] )
1733
+ {
1734
+ return [self saveArray:(NSArray *)obj];
1735
+ }
1736
+ else if ( [obj isKindOfClass:[NSDictionary class]] )
1737
+ {
1738
+ return [self saveDictionary:(NSDictionary *)obj];
1739
+ }
1740
+
1741
+ return self;
1742
+ }
1743
+
1744
+ - (id)saveArray:(NSArray *)array
1745
+ {
1746
+ self.BATCH_BEGIN();
1747
+
1748
+ for ( NSObject * obj in array )
1749
+ {
1750
+ if ( NO == [obj isKindOfClass:[NSDictionary class]] )
1751
+ continue;
1752
+
1753
+ [self saveDictionary:(NSDictionary *)obj];
1754
+ }
1755
+
1756
+ self.BATCH_END();
1757
+
1758
+ return self;
1759
+ }
1760
+
1761
+ - (id)saveDictionary:(NSDictionary *)dict
1762
+ {
1763
+ Class classType = self.classType;
1764
+ if ( NO == [classType isSubclassOfClass:[BeeActiveRecord class]] )
1765
+ return self;
1766
+
1767
+ BeeActiveRecord * record = [dict activeRecordFromDictionary:classType];
1768
+ if ( record )
1769
+ {
1770
+ record.SAVE();
1771
+ }
1772
+
1773
+ return self;
1774
+ }
1775
+
1776
+ - (id)firstRecord
1777
+ {
1778
+ return [self firstRecord:nil];
1779
+ }
1780
+
1781
+ - (id)firstRecord:(NSString *)table
1782
+ {
1783
+ NSArray * array = [self getRecords:table limit:1 offset:0];
1784
+ if ( array && array.count )
1785
+ {
1786
+ return [array objectAtIndex:0];
1787
+ }
1788
+
1789
+ return nil;
1790
+ }
1791
+
1792
+ - (id)firstRecordByID:(id)key
1793
+ {
1794
+ return [self firstRecord:nil byID:key];
1795
+ }
1796
+
1797
+ - (id)firstRecord:(NSString *)table byID:(id)key
1798
+ {
1799
+ if ( nil == key )
1800
+ return nil;
1801
+
1802
+ [self __internalResetResult];
1803
+
1804
+ Class classType = [self classType];
1805
+ if ( NULL == classType )
1806
+ return nil;
1807
+
1808
+ NSString * primaryKey = [BeeActiveRecord activePrimaryKeyFor:classType];
1809
+ if ( nil == primaryKey )
1810
+ return nil;
1811
+
1812
+ [classType setAssociateConditions];
1813
+ [classType setHasConditions];
1814
+
1815
+ self.WHERE( primaryKey, key ).OFFSET( 0 ).LIMIT( 1 ).GET();
1816
+ if ( NO == self.succeed )
1817
+ return nil;
1818
+
1819
+ NSArray * array = self.resultArray;
1820
+ if ( nil == array || 0 == array.count )
1821
+ return nil;
1822
+
1823
+ NSDictionary * dict = [array objectAtIndex:0];
1824
+ if ( dict )
1825
+ {
1826
+ return [[[classType alloc] initWithDictionary:dict] autorelease];
1827
+ }
1828
+
1829
+ return nil;
1830
+ }
1831
+
1832
+ - (id)lastRecord
1833
+ {
1834
+ return [self lastRecord:nil];
1835
+ }
1836
+
1837
+ - (id)lastRecord:(NSString *)table
1838
+ {
1839
+ NSArray * array = [self getRecords:table limit:1 offset:0];
1840
+ if ( array && array.count )
1841
+ {
1842
+ return array.lastObject;
1843
+ }
1844
+
1845
+ return nil;
1846
+ }
1847
+
1848
+ - (id)lastRecordByID:(id)key
1849
+ {
1850
+ return [self lastRecord:nil byID:key];
1851
+ }
1852
+
1853
+ - (id)lastRecord:(NSString *)table byID:(id)key
1854
+ {
1855
+ if ( nil == key )
1856
+ return nil;
1857
+
1858
+ [self __internalResetResult];
1859
+
1860
+ Class classType = [self classType];
1861
+ if ( NULL == classType )
1862
+ return nil;
1863
+
1864
+ NSString * primaryKey = [BeeActiveRecord activePrimaryKeyFor:classType];
1865
+ if ( nil == primaryKey )
1866
+ return nil;
1867
+
1868
+ [classType setAssociateConditions];
1869
+ [classType setHasConditions];
1870
+
1871
+ self.WHERE( primaryKey, key ).OFFSET( 0 ).LIMIT( 1 ).GET();
1872
+ if ( NO == self.succeed )
1873
+ return nil;
1874
+
1875
+ NSArray * array = self.resultArray;
1876
+ if ( nil == array || 0 == array.count )
1877
+ return nil;
1878
+
1879
+ NSDictionary * dict = array.lastObject;
1880
+ if ( dict )
1881
+ {
1882
+ return [[[classType alloc] initWithDictionary:dict] autorelease];
1883
+ }
1884
+
1885
+ return nil;
1886
+ }
1887
+
1888
+ - (NSArray *)getRecords
1889
+ {
1890
+ return [self getRecords:nil limit:0 offset:0];
1891
+ }
1892
+
1893
+ - (NSArray *)getRecords:(NSString *)table
1894
+ {
1895
+ return [self getRecords:table limit:0 offset:0];
1896
+ }
1897
+
1898
+ - (NSArray *)getRecords:(NSString *)table limit:(NSUInteger)limit
1899
+ {
1900
+ return [self getRecords:table limit:limit offset:0];
1901
+ }
1902
+
1903
+ - (NSArray *)getRecords:(NSString *)table limit:(NSUInteger)limit offset:(NSUInteger)offset
1904
+ {
1905
+ [self __internalResetResult];
1906
+
1907
+ Class classType = [self classType];
1908
+ if ( NULL == classType )
1909
+ return [NSArray array];
1910
+
1911
+ NSString * primaryKey = [BeeActiveRecord activePrimaryKeyFor:classType];
1912
+ if ( nil == primaryKey )
1913
+ return [NSArray array];
1914
+
1915
+ self.FROM( table );
1916
+
1917
+ if ( offset )
1918
+ {
1919
+ self.OFFSET( offset );
1920
+ }
1921
+
1922
+ if ( limit )
1923
+ {
1924
+ self.LIMIT( limit );
1925
+ }
1926
+
1927
+ [classType setAssociateConditions];
1928
+ [classType setHasConditions];
1929
+
1930
+ self.GET();
1931
+ if ( NO == self.succeed )
1932
+ return [NSArray array];
1933
+
1934
+ NSArray * array = self.resultArray;
1935
+ if ( nil == array || 0 == array.count )
1936
+ return [NSArray array];
1937
+
1938
+ NSMutableArray * activeRecords = [[NSMutableArray alloc] init];
1939
+
1940
+ for ( NSDictionary * dict in array )
1941
+ {
1942
+ BeeActiveRecord * object = [[[classType alloc] initWithDictionary:dict] autorelease];
1943
+ [activeRecords addObject:object];
1944
+ }
1945
+
1946
+ [_resultArray removeAllObjects];
1947
+ [_resultArray addObjectsFromArray:activeRecords];
1948
+
1949
+ _resultCount = activeRecords.count;
1950
+
1951
+ [activeRecords release];
1952
+
1953
+ return _resultArray;
1954
+ }
1955
+
1956
+ @end