nali 0.3.2 → 0.3.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.
@@ -60,10 +60,12 @@ Nali.extend Model:
60
60
 
61
61
  save: ( success, failure ) ->
62
62
  # отправляет на сервер запрос на сохранение модели, вызывает success в случае успеха и failure при неудаче
63
+ @beforeSave?()
63
64
  if @isValid()
64
65
  @query "#{ @_name.lower() }s.save", @attributes,
65
66
  ( { attributes, created, updated } ) =>
66
67
  @update( attributes, updated, created ).write()
68
+ @afterSave?()
67
69
  success? @
68
70
  else failure? @
69
71
  @
@@ -72,7 +74,10 @@ Nali.extend Model:
72
74
  # синхронизирует пришедшую с сервера модель с локальной, либо создает новую
73
75
  if model = @extensions[ _name ].find attributes.id
74
76
  if destroyed then model.remove()
75
- else model.update attributes, updated, created
77
+ else if updated > @updated
78
+ model.updated = updated
79
+ model.created = created
80
+ model.update attributes
76
81
  else
77
82
  model = @extensions[ _name ].new attributes
78
83
  model.updated = updated
@@ -127,23 +132,20 @@ Nali.extend Model:
127
132
  # создает модель, и сохраняет её на сервере, вызывает success в случае успеха и failure при неудаче
128
133
  @new( attributes ).save success, failure
129
134
 
130
- update: ( attributes, updated = 0, created = 0 ) ->
135
+ update: ( attributes, checkValidation = true ) ->
131
136
  # обновляет атрибуты модели, проверяя их валидность, генерирует событие update
132
- if not updated or updated > @updated
133
- @created = created if created
134
- changed = []
135
- changed.push name for name, value of attributes when @updateProperty name, value
136
- if changed.length
137
- @updated = updated if updated
138
- @onUpdate? changed
139
- @trigger 'update', changed
140
- @Model.trigger "update.#{ @_name.lower() }", @
137
+ changed = []
138
+ changed.push name for name, value of attributes when @updateProperty name, value, checkValidation
139
+ if changed.length
140
+ @onUpdate? changed
141
+ @trigger 'update', changed
142
+ @Model.trigger "update.#{ @_name.lower() }", @
141
143
  @
142
144
 
143
- updateProperty: ( name, value ) ->
145
+ updateProperty: ( name, value, checkValidation = true ) ->
144
146
  # обновляет один атрибут модели, проверяя его валидность, генерирует событие update.propertyName
145
147
  value = @normalizeValue value
146
- if @[ name ] isnt value and @isValidAttributeValue( name, value )
148
+ if @[ name ] isnt value and ( not checkValidation or @isValidAttributeValue( name, value ) )
147
149
  @[ name ] = value
148
150
  @[ 'onUpdate' + name.capitalize() ]?()
149
151
  @trigger "update.#{ name }"
@@ -65,20 +65,18 @@ module Nali
65
65
  end
66
66
 
67
67
  def self.access_options
68
- if settings.environment == :development
69
- YAML.load_file( File.join( root, 'app/server/models/access.yml' ) ).keys_to_sym!
70
- else
71
- @access_options ||= YAML.load_file( File.join( root, 'app/server/models/access.yml' ) ).keys_to_sym!
72
- end
68
+ settings.environment == :development ? get_access_options : @access_options ||= get_access_options
73
69
  end
74
70
 
75
71
  def self.initialize!
76
- Dir[ File.join( root, 'lib/*/**/*.rb' ) ].each { |file| require( file ) }
77
- require File.join( root, 'app/server/controllers/application_controller.rb' )
78
- Dir[ File.join( root, 'app/server/**/*.rb' ) ].each { |file| require( file ) }
79
- require File.join( root, 'config/application' )
80
- require File.join( root, 'app/server/clients' )
81
- Dir[ File.join( root, 'config/initializers/**/*.rb' ) ].each { |file| require( file ) }
72
+ %w(
73
+ lib/*/**/*.rb
74
+ app/server/controllers/application_controller.rb
75
+ app/server/**/*.rb
76
+ config/application
77
+ app/server/clients
78
+ config/initializers/**/*.rb
79
+ ).each { |path| Dir[ File.join( root, path ) ].each { |file| require( file ) } }
82
80
  self
83
81
  end
84
82
 
@@ -89,6 +87,28 @@ module Nali
89
87
  require 'nali/tasks'
90
88
  Nali::Tasks.new
91
89
  end
90
+
91
+ private
92
+
93
+ def self.get_access_options
94
+ YAML.load_file( File.join( root, 'app/server/models/access.yml' ) ).keys_to_sym!.each_value do |sections|
95
+ [ :create, :read, :update ].each do |type|
96
+ if section = sections[ type ]
97
+ section.each_key { |level| parse_access_level section, level }
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ def self.parse_access_level( section, level )
104
+ parsed = []
105
+ if section[ level ]
106
+ section[ level ].each do |value|
107
+ value =~ /^\+/ ? parsed += parse_access_level( section, value[ /[^\+]+/ ].to_sym ) : parsed << value
108
+ end
109
+ end
110
+ section[ level ] = parsed
111
+ end
92
112
 
93
113
  end
94
114
 
data/lib/nali/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Nali
2
2
 
3
- VERSION = '0.3.2'
3
+ VERSION = '0.3.3'
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.2
4
+ version: 0.3.3
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-03 00:00:00.000000000 Z
12
+ date: 2014-12-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thin