motion-support 0.2.2 → 0.2.3
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.
- data/README.md +0 -1
- data/motion/core_ext/ns_string.rb +3 -3
- data/motion/core_ext/string/inflections.rb +0 -17
- data/motion/descendants_tracker.rb +50 -0
- data/motion/version.rb +1 -1
- data/spec/motion-support/_helpers/inflector_test_cases.rb +0 -43
- data/spec/motion-support/descendants_tracker_spec.rb +58 -0
- metadata +53 -46
data/README.md
CHANGED
@@ -317,7 +317,6 @@ Things to do / to decide:
|
|
317
317
|
* Port callbacks.rb
|
318
318
|
* Port concern.rb
|
319
319
|
* Do we need the `Configurable` module?
|
320
|
-
* Do we need the `DescendantsTracker` module?
|
321
320
|
* Do we need the `OrderedOptions` class?
|
322
321
|
* Some extensions have to be made available for Cocoa classes (`NSArray`, `NSDictionary` etc.), since we want to effectively handle return values from Objective-C methods (they return Cocoa classes). The way to do this is to write a conversion method from Cocoa class to Ruby class and delegate the extension methods in the Cocoa class to the conversion method. See `motion/core_ext/ns_string.rb` for an example.
|
323
322
|
* Go through documentation and remove or rewrite things not relevant to RubyMotion, especially examples mentioning Rails components
|
@@ -7,8 +7,8 @@ class NSString
|
|
7
7
|
|
8
8
|
delegate :at, :blank?, :camelcase, :camelize, :classify, :constantize, :dasherize,
|
9
9
|
:deconstantize, :demodulize, :exclude?, :first, :foreign_key, :from, :humanize,
|
10
|
-
:indent, :indent!, :last, :
|
11
|
-
:
|
12
|
-
:
|
10
|
+
:indent, :indent!, :last, :pluralize, :safe_constantize, :singularize,
|
11
|
+
:squish, :squish!, :strip_heredoc, :tableize, :titlecase, :titleize, :to,
|
12
|
+
:truncate, :underscore,
|
13
13
|
:to => :to_s
|
14
14
|
end
|
@@ -132,23 +132,6 @@ class String
|
|
132
132
|
MotionSupport::Inflector.deconstantize(self)
|
133
133
|
end
|
134
134
|
|
135
|
-
# Replaces special characters in a string so that it may be used as part of a 'pretty' URL.
|
136
|
-
#
|
137
|
-
# class Person
|
138
|
-
# def to_param
|
139
|
-
# "#{id}-#{name.parameterize}"
|
140
|
-
# end
|
141
|
-
# end
|
142
|
-
#
|
143
|
-
# @person = Person.find(1)
|
144
|
-
# # => #<Person id: 1, name: "Donald E. Knuth">
|
145
|
-
#
|
146
|
-
# <%= link_to(@person.name, person_path) %>
|
147
|
-
# # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
|
148
|
-
def parameterize(sep = '-')
|
149
|
-
MotionSupport::Inflector.parameterize(self, sep)
|
150
|
-
end
|
151
|
-
|
152
135
|
# Creates the name of a table like Rails does for models to table names. This method
|
153
136
|
# uses the +pluralize+ method on the last word in the string.
|
154
137
|
#
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module MotionSupport
|
2
|
+
# This module provides an internal implementation to track descendants
|
3
|
+
# which is faster than iterating through ObjectSpace.
|
4
|
+
module DescendantsTracker
|
5
|
+
@@direct_descendants = {}
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def direct_descendants(klass)
|
9
|
+
@@direct_descendants[klass] || []
|
10
|
+
end
|
11
|
+
|
12
|
+
def descendants(klass)
|
13
|
+
arr = []
|
14
|
+
accumulate_descendants(klass, arr)
|
15
|
+
arr
|
16
|
+
end
|
17
|
+
|
18
|
+
def clear
|
19
|
+
@@direct_descendants.clear
|
20
|
+
end
|
21
|
+
|
22
|
+
# This is the only method that is not thread safe, but is only ever called
|
23
|
+
# during the eager loading phase.
|
24
|
+
def store_inherited(klass, descendant)
|
25
|
+
(@@direct_descendants[klass] ||= []) << descendant
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def accumulate_descendants(klass, acc)
|
30
|
+
if direct_descendants = @@direct_descendants[klass]
|
31
|
+
acc.concat(direct_descendants)
|
32
|
+
direct_descendants.each { |direct_descendant| accumulate_descendants(direct_descendant, acc) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def inherited(base)
|
38
|
+
DescendantsTracker.store_inherited(self, base)
|
39
|
+
super
|
40
|
+
end
|
41
|
+
|
42
|
+
def direct_descendants
|
43
|
+
DescendantsTracker.direct_descendants(self)
|
44
|
+
end
|
45
|
+
|
46
|
+
def descendants
|
47
|
+
DescendantsTracker.descendants(self)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/motion/version.rb
CHANGED
@@ -162,49 +162,6 @@ module InflectorTestCases
|
|
162
162
|
"NodeChild" => "node_children"
|
163
163
|
}
|
164
164
|
|
165
|
-
StringToParameterized = {
|
166
|
-
"Donald E. Knuth" => "donald-e-knuth",
|
167
|
-
"Random text with *(bad)* characters" => "random-text-with-bad-characters",
|
168
|
-
"Allow_Under_Scores" => "allow_under_scores",
|
169
|
-
"Trailing bad characters!@#" => "trailing-bad-characters",
|
170
|
-
"!@#Leading bad characters" => "leading-bad-characters",
|
171
|
-
"Squeeze separators" => "squeeze-separators",
|
172
|
-
"Test with + sign" => "test-with-sign",
|
173
|
-
"Test with malformed utf8 \251" => "test-with-malformed-utf8"
|
174
|
-
}
|
175
|
-
|
176
|
-
StringToParameterizeWithNoSeparator = {
|
177
|
-
"Donald E. Knuth" => "donaldeknuth",
|
178
|
-
"With-some-dashes" => "with-some-dashes",
|
179
|
-
"Random text with *(bad)* characters" => "randomtextwithbadcharacters",
|
180
|
-
"Trailing bad characters!@#" => "trailingbadcharacters",
|
181
|
-
"!@#Leading bad characters" => "leadingbadcharacters",
|
182
|
-
"Squeeze separators" => "squeezeseparators",
|
183
|
-
"Test with + sign" => "testwithsign",
|
184
|
-
"Test with malformed utf8 \251" => "testwithmalformedutf8"
|
185
|
-
}
|
186
|
-
|
187
|
-
StringToParameterizeWithUnderscore = {
|
188
|
-
"Donald E. Knuth" => "donald_e_knuth",
|
189
|
-
"Random text with *(bad)* characters" => "random_text_with_bad_characters",
|
190
|
-
"With-some-dashes" => "with-some-dashes",
|
191
|
-
"Retain_underscore" => "retain_underscore",
|
192
|
-
"Trailing bad characters!@#" => "trailing_bad_characters",
|
193
|
-
"!@#Leading bad characters" => "leading_bad_characters",
|
194
|
-
"Squeeze separators" => "squeeze_separators",
|
195
|
-
"Test with + sign" => "test_with_sign",
|
196
|
-
"Test with malformed utf8 \251" => "test_with_malformed_utf8"
|
197
|
-
}
|
198
|
-
|
199
|
-
StringToParameterizedAndNormalized = {
|
200
|
-
"Malmö" => "malmo",
|
201
|
-
"Garçons" => "garcons",
|
202
|
-
"Ops\331" => "opsu",
|
203
|
-
"Ærøskøbing" => "aeroskobing",
|
204
|
-
"Aßlar" => "asslar",
|
205
|
-
"Japanese: 日本語" => "japanese"
|
206
|
-
}
|
207
|
-
|
208
165
|
UnderscoreToHuman = {
|
209
166
|
"employee_salary" => "Employee salary",
|
210
167
|
"employee_id" => "Employee",
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module DescendantsTrackerSpec
|
2
|
+
class Parent
|
3
|
+
extend MotionSupport::DescendantsTracker
|
4
|
+
end
|
5
|
+
|
6
|
+
class Child1 < Parent
|
7
|
+
end
|
8
|
+
|
9
|
+
class Child2 < Parent
|
10
|
+
end
|
11
|
+
|
12
|
+
class Grandchild1 < Child1
|
13
|
+
end
|
14
|
+
|
15
|
+
class Grandchild2 < Child1
|
16
|
+
end
|
17
|
+
|
18
|
+
ALL = [Parent, Child1, Child2, Grandchild1, Grandchild2]
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "DescendatsTracker" do
|
22
|
+
describe "descendants" do
|
23
|
+
it "should get all descendants from parent class" do
|
24
|
+
[DescendantsTrackerSpec::Child1, DescendantsTrackerSpec::Child2, DescendantsTrackerSpec::Grandchild1, DescendantsTrackerSpec::Grandchild2].should == DescendantsTrackerSpec::Parent.descendants
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should get descendants from subclass" do
|
28
|
+
[DescendantsTrackerSpec::Grandchild1, DescendantsTrackerSpec::Grandchild2].should == DescendantsTrackerSpec::Child1.descendants
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return empty array for leaf class" do
|
32
|
+
[].should == DescendantsTrackerSpec::Child2.descendants
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "direct_descendants" do
|
37
|
+
it "should get direct descendants from parent class" do
|
38
|
+
[DescendantsTrackerSpec::Child1, DescendantsTrackerSpec::Child2].should == DescendantsTrackerSpec::Parent.direct_descendants
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should get direct descendants from subclass" do
|
42
|
+
[DescendantsTrackerSpec::Grandchild1, DescendantsTrackerSpec::Grandchild2].should == DescendantsTrackerSpec::Child1.direct_descendants
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return empty array for leaf class" do
|
46
|
+
[].should == DescendantsTrackerSpec::Child2.direct_descendants
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "clear" do
|
51
|
+
it "should remove all tracked descendants" do
|
52
|
+
MotionSupport::DescendantsTracker.clear
|
53
|
+
DescendantsTrackerSpec::ALL.each do |k|
|
54
|
+
MotionSupport::DescendantsTracker.descendants(k).should.be.empty
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,49 +1,56 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-support
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.3
|
4
5
|
prerelease:
|
5
|
-
version: 0.2.2
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Thomas Kadauke
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-05-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: motion-require
|
17
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
|
-
requirements:
|
20
|
-
- -
|
21
|
-
- !ruby/object:Gem::Version
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
22
21
|
version: 0.0.6
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements:
|
26
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.0.6
|
30
|
+
- !ruby/object:Gem::Dependency
|
27
31
|
name: rake
|
28
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
29
33
|
none: false
|
30
|
-
requirements:
|
31
|
-
- -
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
|
-
version_requirements:
|
37
|
-
|
38
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Commonly useful extensions to the standard library for RubyMotion. Ported
|
47
|
+
from ActiveSupport.
|
48
|
+
email:
|
39
49
|
- thomas.kadauke@googlemail.com
|
40
50
|
executables: []
|
41
|
-
|
42
51
|
extensions: []
|
43
|
-
|
44
52
|
extra_rdoc_files: []
|
45
|
-
|
46
|
-
files:
|
53
|
+
files:
|
47
54
|
- .gitignore
|
48
55
|
- .yardopts
|
49
56
|
- Gemfile
|
@@ -138,6 +145,7 @@ files:
|
|
138
145
|
- motion/core_ext/time/acts_like.rb
|
139
146
|
- motion/core_ext/time/calculations.rb
|
140
147
|
- motion/core_ext/time/conversions.rb
|
148
|
+
- motion/descendants_tracker.rb
|
141
149
|
- motion/duration.rb
|
142
150
|
- motion/hash_with_indifferent_access.rb
|
143
151
|
- motion/inflections.rb
|
@@ -202,6 +210,7 @@ files:
|
|
202
210
|
- spec/motion-support/core_ext/time/acts_like_spec.rb
|
203
211
|
- spec/motion-support/core_ext/time/calculation_spec.rb
|
204
212
|
- spec/motion-support/core_ext/time/conversion_spec.rb
|
213
|
+
- spec/motion-support/descendants_tracker_spec.rb
|
205
214
|
- spec/motion-support/duration_spec.rb
|
206
215
|
- spec/motion-support/hash_with_indifferent_access_spec.rb
|
207
216
|
- spec/motion-support/inflector_spec.rb
|
@@ -209,38 +218,35 @@ files:
|
|
209
218
|
- spec/motion-support/ns_string_spec.rb
|
210
219
|
homepage: https://github.com/tkadauke/motion-support
|
211
220
|
licenses: []
|
212
|
-
|
213
221
|
post_install_message:
|
214
222
|
rdoc_options: []
|
215
|
-
|
216
|
-
require_paths:
|
223
|
+
require_paths:
|
217
224
|
- lib
|
218
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
225
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
219
226
|
none: false
|
220
|
-
requirements:
|
221
|
-
- -
|
222
|
-
- !ruby/object:Gem::Version
|
223
|
-
|
224
|
-
segments:
|
227
|
+
requirements:
|
228
|
+
- - ! '>='
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: '0'
|
231
|
+
segments:
|
225
232
|
- 0
|
226
|
-
|
227
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
233
|
+
hash: -3381102909433523794
|
234
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
228
235
|
none: false
|
229
|
-
requirements:
|
230
|
-
- -
|
231
|
-
- !ruby/object:Gem::Version
|
232
|
-
|
233
|
-
segments:
|
236
|
+
requirements:
|
237
|
+
- - ! '>='
|
238
|
+
- !ruby/object:Gem::Version
|
239
|
+
version: '0'
|
240
|
+
segments:
|
234
241
|
- 0
|
235
|
-
|
242
|
+
hash: -3381102909433523794
|
236
243
|
requirements: []
|
237
|
-
|
238
244
|
rubyforge_project:
|
239
|
-
rubygems_version: 1.8.
|
245
|
+
rubygems_version: 1.8.25
|
240
246
|
signing_key:
|
241
247
|
specification_version: 3
|
242
248
|
summary: Commonly useful extensions to the standard library for RubyMotion
|
243
|
-
test_files:
|
249
|
+
test_files:
|
244
250
|
- spec/motion-support/_helpers/constantize_test_cases.rb
|
245
251
|
- spec/motion-support/_helpers/inflector_test_cases.rb
|
246
252
|
- spec/motion-support/core_ext/array/access_spec.rb
|
@@ -298,6 +304,7 @@ test_files:
|
|
298
304
|
- spec/motion-support/core_ext/time/acts_like_spec.rb
|
299
305
|
- spec/motion-support/core_ext/time/calculation_spec.rb
|
300
306
|
- spec/motion-support/core_ext/time/conversion_spec.rb
|
307
|
+
- spec/motion-support/descendants_tracker_spec.rb
|
301
308
|
- spec/motion-support/duration_spec.rb
|
302
309
|
- spec/motion-support/hash_with_indifferent_access_spec.rb
|
303
310
|
- spec/motion-support/inflector_spec.rb
|