nali 0.3.7 → 0.3.8

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.
@@ -125,7 +125,7 @@ Nali.extend Model:
125
125
  new: ( attributes ) ->
126
126
  # создает модель, не сохраняя её на сервере
127
127
  model = @clone( attributes: @defaultAttributes() ).accessing()
128
- model[ name ] = @normalizeValue value for name, value of attributes
128
+ model[ name ] = @normalizeAttributeValue name, value for name, value of attributes
129
129
  model
130
130
 
131
131
  create: ( attributes, success, failure ) ->
@@ -144,7 +144,7 @@ Nali.extend Model:
144
144
 
145
145
  updateProperty: ( name, value, checkValidation = true ) ->
146
146
  # обновляет один атрибут модели, проверяя его валидность, генерирует событие update.propertyName
147
- value = @normalizeValue value
147
+ value = @normalizeAttributeValue name, value
148
148
  if @[ name ] isnt value and ( not checkValidation or @isValidAttributeValue( name, value ) )
149
149
  @[ name ] = value
150
150
  @[ 'onUpdate' + name.capitalize() ]?()
@@ -196,17 +196,13 @@ Nali.extend Model:
196
196
  attributes = id: @guid()
197
197
  for name, value of @attributes
198
198
  if value instanceof Object
199
- attributes[ name ] = if value.default? then @normalizeValue value.default else null
200
- else attributes[ name ] = @normalizeValue value
199
+ attributes[ name ] = if value.default? then @normalizeAttributeValue name, value.default else null
200
+ else attributes[ name ] = @normalizeAttributeValue name, value
201
201
  attributes
202
202
 
203
- normalizeValue: ( value ) ->
204
- # приводит значения к нормальному виду, если в строке только числа - преобразуется к числу
205
- # т.е. строка '123' становится числом 123, '123.5' становится 123.5, а '123abc' остается строкой
206
- if typeof value is 'string'
207
- value = "#{ value }".trim()
208
- if value is ( ( correct = + value ) + '' ) then correct else value
209
- else value
203
+ normalizeAttributeValue: ( name, value ) ->
204
+ # если формат свойства number пробует привести значение к числу
205
+ if @::attributes[ name ]?.format is 'number' and value is ( ( correct = + value ) + '' ) then correct else value
210
206
 
211
207
  isCorrect: ( filters = {} ) ->
212
208
  # проверяет соответствие аттрибутов модели определенному набору фильтров, возвращает true либо false
@@ -38,8 +38,8 @@ module Nali
38
38
  relations << value
39
39
  elsif value.is_a?( ActiveRecord::Base )
40
40
  relations << value
41
- if reflection = self.class.reflections[ option ] and reflection.macro == :belongs_to
42
- params[ :attributes ][ option.to_s + '_id' ] = value.id
41
+ if self.respond_to?( key = option.to_s + '_id' ) and self[ key ] == value.id
42
+ params[ :attributes ][ key ] = value.id
43
43
  end
44
44
  else
45
45
  params[ :attributes ][ option ] = value
@@ -1,5 +1,5 @@
1
1
  module Nali
2
2
 
3
- VERSION = '0.3.7'
3
+ VERSION = '0.3.8'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nali
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-18 00:00:00.000000000 Z
12
+ date: 2014-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thin