motion_model_resource 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjM1MjQ3MDJkZjIwNTA3MjQ3NjA4NDVhMjVmNmFjNjk5YzE3OWM5Yg==
4
+ ZTc1MTZkYTZhM2QyYjFkMjViN2VjNDNlNDhmMmUxNzhlZjdhZjMyZQ==
5
5
  data.tar.gz: !binary |-
6
- NWY0MGU1YzliMjdkMDBmODRkNGZkMTg5YzllYWJlOTg5ZmNkMzFiYg==
6
+ ZDEyNzY4ZjVmZTc0ODQ4MzY4Y2EzNmM4YWM0ZDMyZDYyMDc3NGE5Yg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MWU2NDA0ZWNlNDA3NzczYmU3MDAzYmY5YjE1ZTgwMzQ3YTJkNDE2ZDc3NjBh
10
- MjNlZDQzY2FjOGNlYTMyNmM3YWQ2Njc3MDU0MzRhOTdmNmEwMjdjMDNhMjZj
11
- NDU5N2Q1Y2QxOGQ2ODk5Mzc4ZmU0MGNjYTQwMDdiYzk4NTQ5NmM=
9
+ MzhiMjcxNjEwMjZkYjZiYjIxMTRiM2FjNTc0ZmNhYTAzODBmZDc0NjZlOTMx
10
+ ZWM2MDY4ZTcyYTIzODM4MzMzYWY3YzYzM2NlMGQ0YTUwZDAzYWY2NmM5MjIz
11
+ ZDdhNWE3ODcwMTk2MDdmOTcxYTBiNjdiZjY3NjJmMThhM2U3NjI=
12
12
  data.tar.gz: !binary |-
13
- OGExNTBkZTU1NzE0OWZjYjBjYTczOGZmMWFiMDA5NjAwOWNkODIxNDUzMGM4
14
- NWVlNGE3Njc2YWVlMTdmODRlZDc1ZjhmNTViNmUyYTZlN2QwMjM1Y2RjOTUy
15
- NzhiMDdiYzg4MDVmNzIxNjE3ZjVmNzU4N2FhOGZkYzI0N2M3MjQ=
13
+ ZDg5ZTg0N2IzZDA4NzA2NGM4Y2M3MTNhMzdkNDJkNmEyZWY0NzdlZmQxNmFh
14
+ YjE2MjE1MGZlNzYxMjZiYzg5MDYyNjNmNDkzMzUwNDBlY2JlZDhjNzRiNDJk
15
+ MzMyZWI1ZTY2YmFlNzYzMjBmYmRjYjNlYjY1MjcxZTQ4ODY5YTg=
@@ -1,8 +1,9 @@
1
1
  module MotionModelResource
2
2
  module DateParser
3
3
  def self.parseDate(arg)
4
+ additional_parsestring = arg.include?(".") ? ".SSS" : ""
4
5
  date_formatter = NSDateFormatter.alloc.init
5
- date_formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZ"
6
+ date_formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss#{additional_parsestring}ZZZZ"
6
7
  date = date_formatter.dateFromString arg
7
8
 
8
9
  return nil if date.blank?
@@ -121,6 +121,36 @@ module MotionModelResource
121
121
  end
122
122
  end
123
123
  alias_method :save_remote, :save
124
+
125
+ # Destroys a remote model
126
+ # UNTESTED # TODO write a test
127
+ def destroy(options = {}, &block)
128
+ if block.present?
129
+ raise MotionModelResource::URLNotDefinedError.new "URL is not defined for #{self.class.name}!" unless self.class.respond_to?(:url)
130
+
131
+ model = self
132
+
133
+ BW::HTTP.delete("#{self.try(:url)}" || "#{self.class.url}/#{model.id}", {payload: options[:params]}) do |response|
134
+ if response.ok? || options[:force] == true
135
+ model.delete
136
+ end
137
+
138
+ block.call if block.present? && block.respond_to?(:call)
139
+ end
140
+ else
141
+ super
142
+ end
143
+ end
144
+ alias_method :destroy_remote, :destroy
145
+
146
+ # Takes no care of the server response.
147
+ # UNTESTED # TODO write a test
148
+ def destroy!(options = {}, &block)
149
+ options.merge!(force: true)
150
+
151
+ destroy(options, &block)
152
+ end
153
+ alias_method :destroy_remote!, :destroy!
124
154
 
125
155
  # Returns a hash with given model
126
156
  def buildHashFromModel(mainKey, model)
@@ -153,7 +183,7 @@ module MotionModelResource
153
183
  # Loads the given URL and parse the JSON for a model.
154
184
  # If the model is present, the model will updates.
155
185
  # If block given, the block will called, when the the model is saved. The model will be passed as an argument to the block.
156
- def fetch(site, params, &block)
186
+ def fetch(site, params = {}, &block)
157
187
  raise MotionModelResource::WrapperNotDefinedError.new "Wrapper is not defined!" unless self.class.respond_to?(:wrapper)
158
188
  model = self
159
189
  BW::HTTP.get(site, params) do |response|
@@ -199,7 +229,7 @@ module MotionModelResource
199
229
  # Currently only Date/Time support needed
200
230
  def parseValue(key, value)
201
231
  case self.column_type(key.to_sym)
202
- when :date, :time then MotionModelResource::DateParser.parseDate value
232
+ when :time then MotionModelResource::DateParser.parseDate value
203
233
  else value
204
234
  end
205
235
  end
@@ -1,3 +1,3 @@
1
1
  module MotionModelResource
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion_model_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Torben Toepper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-14 00:00:00.000000000 Z
11
+ date: 2013-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bubble-wrap