moonrope 1.3.3 → 1.4.0

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: 477458a2ba0a81369f1b993a0be430c0af5f176c
4
- data.tar.gz: 5e79acdedb3a0440bcc45096ccac42ef906d8415
3
+ metadata.gz: 03ef56897296df607155e3db243142135a9934bb
4
+ data.tar.gz: 8d9e84279e48a610c54f791782993a54620eba6d
5
5
  SHA512:
6
- metadata.gz: a1749b675d587ee6913c4fca9c69fb98123c3bf64e7f2102a4136d63a9b0a2b60488f471cd356461094e26d84e679e69dc0d4740b8be5b531fdae0b4c876d6ed
7
- data.tar.gz: 88895948f31a23a3db44b8d74ac9663379807d9553ded73d0e7f31afecb0b037c92f7d48b138b6da19be1f219f2a599bfa938febcdfca657feb4e64f85b1be9b
6
+ metadata.gz: ea2654b89ef07c235e91b3c3e39a2333af2ef29dd2751d51518e377812f807adab86fc5844a92aeb9f382370743d7f1ae5f860c1679da5bf91ee4ab9f28e4c1e
7
+ data.tar.gz: 7f154d360c7da6dfa8fc7b0d246a874d666e9a4587ffb9db120d9edf6abbc0035b16bd7a7acc65237c1584353c5a93657f56bf4352f3c6f62fb38e1754c1e4b7
@@ -84,7 +84,7 @@ module Moonrope
84
84
 
85
85
  def expansion(name, *args, &block)
86
86
  if block_given?
87
- @structure.expansions[name] = block
87
+ @structure.expansions[name] = {:block => block, :conditions => @conditions}
88
88
  else
89
89
  attribute(:expansion, name, *args)
90
90
  end
@@ -22,6 +22,16 @@ module Moonrope
22
22
  end
23
23
  end
24
24
 
25
+ class StructuredError < RequestError
26
+ def status
27
+ "error"
28
+ end
29
+
30
+ def data
31
+ @options
32
+ end
33
+ end
34
+
25
35
  class AccessDenied < RequestError
26
36
  def status
27
37
  'access-denied'
@@ -7,17 +7,33 @@ module Moonrope
7
7
  # @param type [Symbol] the type of error to raise
8
8
  # @param message [String, Hash or Array] options to pass with the error (usually a message)
9
9
  #
10
- def error(type, message)
10
+ def error(type, code_or_message, message = nil)
11
11
  case type
12
- when :not_found then raise(Moonrope::Errors::NotFound, message)
13
- when :access_denied then raise(Moonrope::Errors::AccessDenied, message)
14
- when :validation_error then raise(Moonrope::Errors::ValidationError, message)
15
- when :parameter_error then raise(Moonrope::Errors::ParameterError, message)
12
+ when :not_found then raise(Moonrope::Errors::NotFound, code_or_message)
13
+ when :access_denied then raise(Moonrope::Errors::AccessDenied, code_or_message)
14
+ when :validation_error then raise(Moonrope::Errors::ValidationError, code_or_message)
15
+ when :parameter_error then raise(Moonrope::Errors::ParameterError, code_or_message)
16
+ when :structured_error then structured_error(code_or_message, message)
16
17
  else
17
- raise Moonrope::Errors::RequestError, message
18
+ if type.is_a?(String)
19
+ structured_error(type, code_or_message, message.is_a?(Hash) ? message : {})
20
+ else
21
+ raise Moonrope::Errors::RequestError, code_or_message
22
+ end
18
23
  end
19
24
  end
20
25
 
26
+ #
27
+ # Raises a structured error.
28
+ #
29
+ # @param code [String] the code to return
30
+ # @param message [String] explantory text to return
31
+ # @param additional [Hash] additional data to return with the error
32
+ #
33
+ def structured_error(code, message, additional = {})
34
+ raise Moonrope::Errors::StructuredError, additional.merge(:code => code, :message => message)
35
+ end
36
+
21
37
  #
22
38
  # Return paginated information
23
39
  #
@@ -83,7 +83,8 @@ module Moonrope
83
83
  # Add the expansions
84
84
  expansions.each do |name, expansion|
85
85
  next if options[:expansions].is_a?(Array) && !options[:expansions].include?(name.to_sym)
86
- DeepMerge.deep_merge!({name.to_sym => environment.instance_eval(&expansion)}, hash)
86
+ next unless expansion[:conditions].all? { |condition| environment.instance_eval(&condition) }
87
+ DeepMerge.deep_merge!({name.to_sym => environment.instance_eval(&expansion[:block])}, hash)
87
88
  end
88
89
  end
89
90
 
@@ -1,3 +1,3 @@
1
1
  module Moonrope
2
- VERSION = '1.3.3'
2
+ VERSION = '1.4.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moonrope
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-04 00:00:00.000000000 Z
11
+ date: 2015-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json