immutabler 0.1.9 → 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.
- checksums.yaml +4 -4
- data/GETTING_STARTED.md +13 -10
- data/immutabler.gemspec +2 -2
- data/lib/immutabler/dsl/props_builder.rb +4 -3
- data/lib/immutabler/template/header_template.rb +5 -3
- data/lib/immutabler/type_mapper.rb +13 -21
- data/lib/immutabler/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b988c688568544db5349c6927ef6dec0d6aeb2be
|
4
|
+
data.tar.gz: 19e97a7fc6dbe1c67bbeabca39ed07b80e6b3515
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c04672fd825c54996958301afb89873ac121468585b722e9ce3259b030ec4a5969e04a4f1b9ee220ee958903037719139240738897cc59f80c9a30bc3467d1be
|
7
|
+
data.tar.gz: b80e1c70e72d7087005ee2d6dca60466cffde2175927d69dc5b257135a3229e57a60ca1a0455d5682247a7264a392fd7a8a28eb40b17d84b3c806b97dce77a6e
|
data/GETTING_STARTED.md
CHANGED
@@ -88,24 +88,27 @@ end
|
|
88
88
|
Each field is defining by
|
89
89
|
|
90
90
|
```ruby
|
91
|
-
prop :fieldName, :fieldType
|
91
|
+
prop :fieldName, :fieldType, :name_prefix => your_custom_prefix(string, optional), :is_ref => true or false(optional), :ref_type => 'assign', 'weak', 'strong'(optional), :is_id => true or false(optional)
|
92
92
|
```
|
93
93
|
|
94
94
|
There are predefined types:
|
95
|
-
* int
|
96
|
-
* float
|
97
|
-
*
|
98
|
-
*
|
99
|
-
*
|
100
|
-
*
|
101
|
-
*
|
95
|
+
* int -> NSInteger in Objective-C
|
96
|
+
* float -> CGFloat in Objective-C
|
97
|
+
* double -> double in Objective-C
|
98
|
+
* bool -> BOOL in Objective-C
|
99
|
+
* string -> NSString* in Objective-C
|
100
|
+
* array -> NSArray* in Objective-C
|
101
|
+
* dict -> NSDictionary* in Objective-C
|
102
|
+
* id -> id in Objective-C
|
102
103
|
|
103
104
|
When you use custom type and it will be transformed into the same.
|
104
105
|
|
105
106
|
You can pass additional parameters for prop:
|
106
107
|
|
107
|
-
+
|
108
|
-
+
|
108
|
+
+ name_prefix: name_prefix to include (please, don't use it for adding/supressing asterisk before property name - use `is_ref`, `is_id` instead)
|
109
|
+
+ is_ref: defines whether property is reference type (pointer) or value type
|
110
|
+
+ ref_type: property memory management specifier (`weak`, `strong`, `assign`, default - `strong` when `is_ref` is `true`, `assign` when `is_ref` is `false`)
|
111
|
+
+ is_id: `id` is Objective-C special built-in type. Despite it's reference type, '*' is assumed implicitly and shouldn't be specified manually. Whenever you want to define something of type like `id<MyAwesomeProtocol>` don't forget to add :is_id => true to property definition to suppress asterisk
|
109
112
|
|
110
113
|
Example:
|
111
114
|
```ruby
|
data/immutabler.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'immutabler/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'immutabler'
|
8
8
|
spec.version = Immutabler::VERSION
|
9
|
-
spec.authors = ['Serhij Korochanskyj', 'Sergey Zenchenko']
|
10
|
-
spec.email = ['serge.k@techery.io', 'serge.z@techery.io']
|
9
|
+
spec.authors = ['Serhij Korochanskyj', 'Sergey Zenchenko', 'Petro Korienev']
|
10
|
+
spec.email = ['serge.k@techery.io', 'serge.z@techery.io', 'soxjke@gmail.com']
|
11
11
|
|
12
12
|
spec.summary = 'Generator of Objective-C immutable models'
|
13
13
|
spec.description = 'Generator of Objective-C immutable models'
|
@@ -10,9 +10,10 @@ module Immutabler
|
|
10
10
|
|
11
11
|
def prop(name, type, options={})
|
12
12
|
prop_options = {}
|
13
|
-
prop_options[:is_ref] =
|
14
|
-
prop_options[:ref_type] = options[:
|
15
|
-
prop_options[:name_prefix] = options[:
|
13
|
+
prop_options[:is_ref] = options[:is_ref] if options.key?(:is_ref)
|
14
|
+
prop_options[:ref_type] = options[:ref_type] if options.key?(:ref_type)
|
15
|
+
prop_options[:name_prefix] = options[:name_prefix] if options.key?(:name_prefix)
|
16
|
+
prop_options[:is_id] = options[:is_id] if options.key?(:is_id)
|
16
17
|
@props << Prop.new(name.to_s, type.to_s, prop_options)
|
17
18
|
end
|
18
19
|
end
|
@@ -25,9 +25,11 @@ module Immutabler
|
|
25
25
|
arg.map do |prop|
|
26
26
|
options = block[:hash]
|
27
27
|
access_type = options[:readOnly] ? 'readonly' : 'readwrite'
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
asterisk = prop[:is_ref] && !prop[:is_id] ? '*' : ''
|
29
|
+
asterisk_and_prefix = "#{asterisk}#{prop[:name_prefix]}"
|
30
|
+
memory_management = prop[:is_ref] ? prop[:ref_type] : 'assign';
|
31
|
+
prop_arguments = "@property(nonatomic, #{memory_management}, #{access_type})"
|
32
|
+
prop_field = "#{prop[:type]} #{asterisk_and_prefix}#{prop[:name]}"
|
31
33
|
"#{prop_arguments} #{prop_field};"
|
32
34
|
end.join("\n")
|
33
35
|
end
|
@@ -3,50 +3,42 @@ module Immutabler
|
|
3
3
|
TYPE_MAPPING = {
|
4
4
|
'int' => {
|
5
5
|
type: 'NSInteger',
|
6
|
-
is_ref: false
|
7
|
-
ref_type: 'assign',
|
8
|
-
name_prefix: ''
|
6
|
+
is_ref: false
|
9
7
|
},
|
10
8
|
'float' => {
|
11
9
|
type: 'CGFloat',
|
12
|
-
is_ref: false
|
13
|
-
ref_type: 'assign',
|
14
|
-
name_prefix: ''
|
10
|
+
is_ref: false
|
15
11
|
},
|
12
|
+
'double' => {
|
13
|
+
type: 'double',
|
14
|
+
is_ref: false
|
15
|
+
},
|
16
16
|
'bool' => {
|
17
17
|
type: 'BOOL',
|
18
|
-
is_ref: false
|
19
|
-
ref_type: 'assign',
|
20
|
-
name_prefix: ''
|
18
|
+
is_ref: false
|
21
19
|
},
|
22
20
|
'array' => {
|
23
21
|
type: 'NSArray',
|
24
|
-
is_ref: true
|
25
|
-
ref_type: 'strong',
|
26
|
-
name_prefix: '*'
|
22
|
+
is_ref: true
|
27
23
|
},
|
28
24
|
'string' => {
|
29
25
|
type: 'NSString',
|
30
|
-
is_ref: true
|
31
|
-
ref_type: 'strong',
|
32
|
-
name_prefix: '*'
|
26
|
+
is_ref: true
|
33
27
|
},
|
34
28
|
'dict' => {
|
35
29
|
type: 'NSDictionary',
|
36
|
-
is_ref: true
|
37
|
-
ref_type: 'strong',
|
38
|
-
name_prefix: '*',
|
30
|
+
is_ref: true
|
39
31
|
},
|
40
32
|
'id' => {
|
41
33
|
type: 'id',
|
42
34
|
is_ref: true,
|
43
35
|
ref_type: 'strong',
|
44
|
-
|
36
|
+
is_id: true
|
45
37
|
}
|
46
38
|
}
|
47
39
|
|
48
40
|
def self.map(type, options)
|
49
|
-
TYPE_MAPPING.fetch(type, default_mapping(type)).merge(options)
|
41
|
+
default_mapping(type).merge(TYPE_MAPPING.fetch(type, default_mapping(type))).merge(options)
|
50
42
|
end
|
51
43
|
|
52
44
|
private
|
@@ -56,7 +48,7 @@ module Immutabler
|
|
56
48
|
type: type,
|
57
49
|
is_ref: true,
|
58
50
|
ref_type: 'strong',
|
59
|
-
|
51
|
+
is_id: false
|
60
52
|
}
|
61
53
|
end
|
62
54
|
end
|
data/lib/immutabler/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: immutabler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Serhij Korochanskyj
|
8
8
|
- Sergey Zenchenko
|
9
|
+
- Petro Korienev
|
9
10
|
autorequire:
|
10
11
|
bindir: exe
|
11
12
|
cert_chain: []
|
12
|
-
date: 2016-
|
13
|
+
date: 2016-05-18 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: handlebars
|
@@ -71,6 +72,7 @@ description: Generator of Objective-C immutable models
|
|
71
72
|
email:
|
72
73
|
- serge.k@techery.io
|
73
74
|
- serge.z@techery.io
|
75
|
+
- soxjke@gmail.com
|
74
76
|
executables: []
|
75
77
|
extensions: []
|
76
78
|
extra_rdoc_files: []
|