immutabler 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e79dd86a282c324736e936292414708843017c6f
4
- data.tar.gz: 7ec40540a6509d5991daaff80ff17870560459ee
3
+ metadata.gz: d1c29279d88ef6c07612b6784f0b8ac7a376317a
4
+ data.tar.gz: 023694188d0b20e9a2923a966919a3a50040d8f7
5
5
  SHA512:
6
- metadata.gz: c522a8ba5de365cf09d3e64a88da531417c7c9be92de532909fd8ef4950cb8c1b519913065449ba5328852c4a108015b9fc966e31750b6ee7a7966d19de05934
7
- data.tar.gz: 08e00ad01dd981ab8efc51ca60d2abd11b43554bb337c0c816762e99adfb4c93e7196a6846f6d52cfae16fa3143412eb47814569908e9c1950c02b6aee408fa9
6
+ metadata.gz: fd1aa3eb3f988faeca28d3ee250bce97c9e47f401030564f2c29efbb57396b949d5e2a7835389efd38d187311a1df15b8ac69caa1e1d8ed73a5cd7b06a7b7252
7
+ data.tar.gz: f8903fbcc6cbc1d731d6b4bef3edfbac946e17d67c728a3f79acc8f7b8238b19b994757931e84bf885c67507d86e57bf92cdfb4c47f9a2b6dbb8fb3fd28778e9
data/GETTING_STARTED.md CHANGED
@@ -35,6 +35,14 @@ model :User, base: MyModel do
35
35
  end
36
36
  ```
37
37
 
38
+ If base class is immutable and must be instantiated with builder, you can use `base_immutable` option:
39
+
40
+ ```ruby
41
+ model :User, base: MyModel, base_immutable: true do
42
+
43
+ end
44
+ ```
45
+
38
46
  You can specify base class for model builder using `builder_base` option:
39
47
 
40
48
  ```ruby
@@ -163,14 +171,16 @@ Immutabler.group :TESalonModels do
163
171
 
164
172
  output_dir(gen_path)
165
173
  prefix('TE')
166
- base_model('MTLModel<MTLJSONSerializing>') # Defaut base model for group
174
+ base_model('MTLModel<MTLJSONSerializing>') # Default base model for group
167
175
 
168
176
  enum :ServiceState do
169
177
  attr :Archived
170
178
  attr :Active
171
179
  end
172
180
 
173
- model :Salon, base: 'CustomModel', builder_base: 'CustomBuilder' do
181
+ model :Salon, base: 'CustomModel',
182
+ base_immutable: true,
183
+ builder_base: 'CustomBuilder' do
174
184
  fields do
175
185
  prop :modelId, :int
176
186
  prop :address, :string
@@ -43,12 +43,13 @@ module Immutabler
43
43
  def model(name, options = {}, &block)
44
44
  prefix = @prefix + name.to_s
45
45
  base = options.fetch(:base, @base_model).to_s
46
+ base_immutable = options.fetch(:base_immutable, false)
46
47
  builder_base = options.fetch(:builder_base, base).to_s
47
48
  props = []
48
49
  mappings = []
49
50
  ModelAttributesBuilder.new(props, mappings, &block)
50
51
 
51
- model = Model.new(prefix, base, builder_base, props, mappings)
52
+ model = Model.new(prefix, base, base_immutable, builder_base, props, mappings)
52
53
 
53
54
  models << model
54
55
  end
@@ -1,11 +1,12 @@
1
1
  module Immutabler
2
2
  module DSL
3
3
  class Model
4
- attr_accessor :name, :base, :builder_base, :props, :mappings
4
+ attr_accessor :name, :base, :base_immutable, :builder_base, :props, :mappings
5
5
 
6
- def initialize(name, base, builder_base, props, mappings)
6
+ def initialize(name, base, base_immutable, builder_base, props, mappings)
7
7
  @name = name
8
8
  @base = base
9
+ @base_immutable = base_immutable
9
10
  @builder_base = builder_base
10
11
  @props = props
11
12
  @mappings = mappings
@@ -34,6 +34,13 @@ module Immutabler
34
34
  body << "\n};"
35
35
  end
36
36
 
37
+ helper(:init_with_builder) do |context, arg, block|
38
+ if arg[:base_immutable]
39
+ " self = [super initWithBuilder:builder modelVersion:modelVersion];\n"
40
+ else
41
+ " self = [super init];\n"
42
+ end
43
+ end
37
44
  end
38
45
 
39
46
  def render
@@ -21,6 +21,7 @@ module Immutabler
21
21
  {
22
22
  name: model.name,
23
23
  base_class: model.base,
24
+ base_immutable: model.base_immutable,
24
25
  builder_base_class: model.builder_base,
25
26
  props: build_props(model.props),
26
27
  any_mappings: model.mappings.any?,
@@ -1,3 +1,3 @@
1
1
  module Immutabler
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -57,7 +57,8 @@
57
57
 
58
58
  - (instancetype)initWithBuilder:({{name}}Builder*)builder modelVersion:(int)modelVersion
59
59
  {
60
- self = [super init];
60
+ {{#init_with_builder .}}
61
+ {{/init_with_builder}}
61
62
 
62
63
  if (self) {
63
64
  __modelVersion = modelVersion;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immutabler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serhij Korochanskyj