motion-loco 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,108 +3,112 @@ motion_require 'resizable'
3
3
 
4
4
  module Loco
5
5
 
6
- class TableViewCell < UITableViewCell
7
- include Observable
6
+ module UI
7
+
8
+ class TableViewCell < UITableViewCell
9
+ include Observable
8
10
 
9
- property :content
11
+ property :content
10
12
 
11
- def initWithStyle(style, reuseIdentifier:reuseIdentifier)
12
- if super
13
- view_setup # Needed because it's not Loco::Resizable
13
+ def initWithStyle(style, reuseIdentifier:reuseIdentifier)
14
+ if super
15
+ view_setup # Needed because it's not Loco::Resizable
16
+ end
17
+ self
14
18
  end
15
- self
16
- end
17
-
18
- def select
19
- Loco.debug("Override #{self.class}#select with the action to take when the row is selected")
20
- end
21
19
 
22
- def view_controller(superview=nil)
23
- if superview
24
- view_controller = superview.nextResponder
25
- else
26
- view_controller = self.superview.nextResponder
20
+ def select
21
+ Loco.debug("Override #{self.class}#select with the action to take when the row is selected")
27
22
  end
28
- if view_controller.is_a? UIViewController
29
- view_controller
30
- elsif view_controller.is_a? UIView
31
- self.view_controller(view_controller)
23
+
24
+ def view_controller(superview=nil)
25
+ if superview
26
+ view_controller = superview.nextResponder
27
+ else
28
+ view_controller = self.superview.nextResponder
29
+ end
30
+ if view_controller.is_a? UIViewController
31
+ view_controller
32
+ elsif view_controller.is_a? UIView
33
+ self.view_controller(view_controller)
34
+ end
32
35
  end
33
- end
34
- alias_method :viewController, :view_controller
36
+ alias_method :viewController, :view_controller
35
37
 
36
- def view_setup
37
- viewSetup
38
- end
38
+ def view_setup
39
+ viewSetup
40
+ end
39
41
 
40
- def viewSetup
41
- Loco.debug("Override #{self.class}#viewSetup or #{self.class}#view_setup to customize the view")
42
+ def viewSetup
43
+ Loco.debug("Override #{self.class}#viewSetup or #{self.class}#view_setup to customize the view")
44
+ end
42
45
  end
43
- end
44
46
 
45
- class TableView < UITableView
46
- include Resizable
47
- include Observable
47
+ class TableView < UITableView
48
+ include Resizable
49
+ include Observable
48
50
 
49
- property :content
50
-
51
- def content=(value)
52
- super
53
- self.reloadData
54
- end
51
+ property :content
55
52
 
56
- def cell_id
57
- @cell_id ||= "CELL_#{self.object_id}"
58
- end
59
-
60
- def initWithFrame(frame)
61
- super(frame)
62
- self.dataSource = self.delegate = self
63
- end
53
+ def content=(value)
54
+ super
55
+ self.reloadData
56
+ end
64
57
 
65
- def item_view_class
66
- self.class.send(:get_item_view_class)
67
- end
58
+ def cell_id
59
+ @cell_id ||= "CELL_#{self.object_id}"
60
+ end
68
61
 
69
- # UITableViewDelegate implementation for returning the cell at a given indexPath.
70
- # @return [Loco::TableViewCell]
71
- def tableView(tableView, cellForRowAtIndexPath:indexPath)
72
- cell = tableView.dequeueReusableCellWithIdentifier(cell_id)
73
- unless cell
74
- cell = self.item_view_class.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier:cell_id)
62
+ def initWithFrame(frame)
63
+ super(frame)
64
+ self.dataSource = self.delegate = self
65
+ end
66
+
67
+ def item_view_class
68
+ self.class.get_item_view_class
69
+ end
70
+
71
+ # UITableViewDelegate implementation for returning the cell at a given indexPath.
72
+ # @return [Loco::TableViewCell]
73
+ def tableView(tableView, cellForRowAtIndexPath:indexPath)
74
+ cell = tableView.dequeueReusableCellWithIdentifier(cell_id)
75
+ unless cell
76
+ cell = self.item_view_class.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier:cell_id)
77
+ end
78
+ cell.content = self.content[indexPath.row]
79
+ cell
75
80
  end
76
- cell.content = self.content[indexPath.row]
77
- cell
78
- end
79
81
 
80
- # UITableViewDelegate implementation for selecting a cell at a given indexPath.
81
- def tableView(tableView, didSelectRowAtIndexPath:indexPath)
82
- cell = tableView.cellForRowAtIndexPath(indexPath)
83
- cell.select
84
- end
82
+ # UITableViewDelegate implementation for selecting a cell at a given indexPath.
83
+ def tableView(tableView, didSelectRowAtIndexPath:indexPath)
84
+ cell = tableView.cellForRowAtIndexPath(indexPath)
85
+ cell.select
86
+ end
85
87
 
86
- # UITableViewDelegate implementation for returning the number of rows in a section.
87
- # @return [Integer]
88
- def tableView(tableView, numberOfRowsInSection:section)
89
- if self.content.is_a? Array
90
- self.content.length
91
- else
92
- 0
88
+ # UITableViewDelegate implementation for returning the number of rows in a section.
89
+ # @return [Integer]
90
+ def tableView(tableView, numberOfRowsInSection:section)
91
+ if self.content.is_a? Array
92
+ self.content.length
93
+ else
94
+ 0
95
+ end
93
96
  end
94
- end
95
97
 
96
- class << self
98
+ class << self
97
99
 
98
- def item_view_class(view_class)
99
- @item_view_class = view_class
100
- end
101
- alias_method :itemViewClass, :item_view_class
100
+ def item_view_class(view_class)
101
+ @item_view_class = view_class
102
+ end
103
+ alias_method :itemViewClass, :item_view_class
102
104
 
103
- def get_item_view_class
104
- @item_view_class ||= TableViewCell
105
- end
105
+ def get_item_view_class
106
+ @item_view_class ||= TableViewCell
107
+ end
106
108
 
109
+ end
107
110
  end
111
+
108
112
  end
109
113
 
110
114
  end
@@ -1,3 +1,3 @@
1
1
  module Loco
2
- VERSION = '0.1.3'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -3,64 +3,68 @@ motion_require 'resizable'
3
3
 
4
4
  module Loco
5
5
 
6
- class Button < UIButton
7
- include Resizable
8
- include Observable
9
- end
6
+ module UI
10
7
 
11
- class DatePicker < UIDatePicker
12
- include Resizable
13
- include Observable
14
- end
8
+ class Button < UIButton
9
+ include Resizable
10
+ include Observable
11
+ end
15
12
 
16
- class ImageView < UIImageView
17
- include Resizable
18
- include Observable
19
- end
13
+ class DatePicker < UIDatePicker
14
+ include Resizable
15
+ include Observable
16
+ end
17
+
18
+ class ImageView < UIImageView
19
+ include Resizable
20
+ include Observable
21
+ end
20
22
 
21
- class Label < UILabel
22
- include Resizable
23
- include Observable
24
- end
23
+ class Label < UILabel
24
+ include Resizable
25
+ include Observable
26
+ end
25
27
 
26
- class PickerView < UIPickerView
27
- include Resizable
28
- include Observable
29
- end
28
+ class PickerView < UIPickerView
29
+ include Resizable
30
+ include Observable
31
+ end
30
32
 
31
- class ProgressView < UIProgressView
32
- include Resizable
33
- include Observable
34
- end
33
+ class ProgressView < UIProgressView
34
+ include Resizable
35
+ include Observable
36
+ end
35
37
 
36
- class ScrollView < UIScrollView
37
- include Resizable
38
- include Observable
39
- end
38
+ class ScrollView < UIScrollView
39
+ include Resizable
40
+ include Observable
41
+ end
40
42
 
41
- class Slider < UISlider
42
- include Resizable
43
- include Observable
44
- end
43
+ class Slider < UISlider
44
+ include Resizable
45
+ include Observable
46
+ end
45
47
 
46
- class TextView < UITextView
47
- include Resizable
48
- include Observable
49
- end
48
+ class TextView < UITextView
49
+ include Resizable
50
+ include Observable
51
+ end
50
52
 
51
- class Toolbar < UIToolbar
52
- include Resizable
53
- include Observable
54
- end
53
+ class Toolbar < UIToolbar
54
+ include Resizable
55
+ include Observable
56
+ end
55
57
 
56
- class View < UIView
57
- include Resizable
58
- include Observable
59
- end
58
+ class View < UIView
59
+ include Resizable
60
+ include Observable
61
+ end
60
62
 
61
- class WebView < UIWebView
62
- include Resizable
63
- include Observable
63
+ class WebView < UIWebView
64
+ include Resizable
65
+ include Observable
66
+ end
67
+
64
68
  end
65
69
 
66
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-loco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Pattison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-08 00:00:00.000000000 Z
11
+ date: 2013-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print_motion
@@ -100,7 +100,7 @@ files:
100
100
  - lib/motion-loco/record_array.rb
101
101
  - lib/motion-loco/resizable.rb
102
102
  - lib/motion-loco/rest_adapter.rb
103
- - lib/motion-loco/savable.rb
103
+ - lib/motion-loco/sqlite_adapter.rb
104
104
  - lib/motion-loco/table_view.rb
105
105
  - lib/motion-loco/version.rb
106
106
  - lib/motion-loco/view_controller.rb
@@ -1,127 +0,0 @@
1
- motion_require 'observable'
2
- motion_require 'record_array'
3
-
4
- module Loco
5
-
6
- module Savable
7
-
8
- def destroy(&block)
9
- adapter = self.class.get_class_adapter
10
- unless self.id.nil?
11
- adapter.delete_record(self) do |record|
12
- self.did_delete
13
- block.call(record) if block.is_a? Proc
14
- end
15
- end
16
- end
17
-
18
- def did_create
19
- # Override to perform actions after creating the record
20
- end
21
- alias_method :didCreate, :did_create
22
-
23
- def did_load
24
- # Override to perform actions after loading data
25
- end
26
- alias_method :didLoad, :did_load
27
-
28
- def did_update
29
- # Override to perform actions after updating the record
30
- end
31
- alias_method :didUpdate, :did_update
32
-
33
- def load(id, data)
34
- data.merge!({ id: id })
35
- self.set_properties(data)
36
- self.did_load
37
- self
38
- end
39
-
40
- def save(&block)
41
- adapter = self.class.get_class_adapter
42
- if self.id.nil?
43
- adapter.create_record(self) do |record|
44
- self.did_create
45
- block.call(record) if block.is_a? Proc
46
- end
47
- else
48
- adapter.update_record(self) do |record|
49
- self.did_update
50
- block.call(record) if block.is_a? Proc
51
- end
52
- end
53
- end
54
-
55
- def serialize(options={})
56
- json = {}
57
- if options[:root] == false
58
- self.class.send(:get_class_properties).each do |key|
59
- json[key.to_sym] = self.send(key)
60
- end
61
- else
62
- if options[:root].nil? || options[:root] == true
63
- root = self.class.to_s.underscore.to_sym
64
- else
65
- root = options[:root].to_sym
66
- end
67
- json[root] = {}
68
- self.class.send(:get_class_properties).each do |key|
69
- json[root][key.to_sym] = self.send(key)
70
- end
71
- end
72
- json
73
- end
74
-
75
- module ClassMethods
76
-
77
- def adapter(adapter_class, *args)
78
- if adapter_class.is_a? String
79
- @adapter = adapter_class.split('::').inject(Object) {|mod, class_name| mod.const_get(class_name) }.new(*args)
80
- else
81
- @adapter = adapter_class.new(*args)
82
- end
83
- end
84
-
85
- def find(id=nil, &block)
86
- adapter = self.get_class_adapter
87
- if id.nil?
88
- # Return all records
89
- records = RecordArray.new
90
- adapter.find_all(self, records) do |records|
91
- block.call(records) if block.is_a? Proc
92
- end
93
- elsif id.is_a? Array
94
- # Return records with given ids
95
- records = RecordArray.new
96
- adapter.find_many(self, records, id) do |records|
97
- block.call(records) if block.is_a? Proc
98
- end
99
- elsif id.is_a? Hash
100
- # Return records matching query
101
- records = RecordArray.new
102
- adapter.find_query(self, records, id) do |records|
103
- block.call(records) if block.is_a? Proc
104
- end
105
- else
106
- record = self.new(id: id)
107
- adapter.find(record, id) do |record|
108
- block.call(record) if block.is_a? Proc
109
- end
110
- end
111
- end
112
- alias_method :all, :find
113
- alias_method :where, :find
114
-
115
- def get_class_adapter
116
- @adapter ||= Adapter.new
117
- end
118
-
119
- end
120
-
121
- def self.included(base)
122
- base.extend(ClassMethods)
123
- end
124
-
125
- end
126
-
127
- end