immutabler 0.1.1 → 0.1.2
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 +12 -2
- data/lib/immutabler/dsl/group.rb +2 -1
- data/lib/immutabler/dsl/model.rb +3 -2
- data/lib/immutabler/template/body_template.rb +7 -0
- data/lib/immutabler/template/builder.rb +1 -0
- data/lib/immutabler/version.rb +1 -1
- data/templates/body_template.hbs +2 -1
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: d1c29279d88ef6c07612b6784f0b8ac7a376317a
         | 
| 4 | 
            +
              data.tar.gz: 023694188d0b20e9a2923a966919a3a50040d8f7
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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>') #  | 
| 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', | 
| 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
         | 
    
        data/lib/immutabler/dsl/group.rb
    CHANGED
    
    | @@ -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
         | 
    
        data/lib/immutabler/dsl/model.rb
    CHANGED
    
    | @@ -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
         | 
    
        data/lib/immutabler/version.rb
    CHANGED
    
    
    
        data/templates/body_template.hbs
    CHANGED