moonrope 1.1.3 → 1.1.4

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: 77cbbacd319f472da01acaa7be887855096facf6
4
- data.tar.gz: e198ad723b9e7431a29a93cd6527f2ab65927ee9
3
+ metadata.gz: a9692810430240c41d7a72ae72a4c9db1134359e
4
+ data.tar.gz: f87635e0c45475aab9be1f764af4661f736bd3a3
5
5
  SHA512:
6
- metadata.gz: 97c16159042f72c46ab081f889bf6db8fae3e7b06ef6909a814fdafd945dd13ad5d3ac3672ac89500a38694b1819d512f7360e0ad1274072399043427842af1a
7
- data.tar.gz: a0c2475a80583da947f65e9f25f11970e8214d4e2671a4305d30f7b5cbceae51eabf6122e310049d38cb68e9851d843efc6c7c9336cf6d2b95ebb8a3b21b09e4
6
+ metadata.gz: 3d2a7fdb9279de606ea73fcb20dc6fe18bf6e2e13eb5016ee0bf6f513f3391fdc10d345eacab8b90474c249261e883af8312ea80c9004666fd092414f35f0586
7
+ data.tar.gz: 37b832788c055a6fc24361d9f7acae8957eed70fb392210500cfcd25f6232c97e7b259d6c2e3ea0f4776448bb5bb43ce57be4cb69a8af6bd8759cfbc86079031
data/lib/moonrope/base.rb CHANGED
@@ -52,7 +52,7 @@ module Moonrope
52
52
  def unload
53
53
  @structures = []
54
54
  @controllers = []
55
- @helpers = []
55
+ @helpers = @helpers.is_a?(Array) ? @helpers.select { |h| h.options[:unloadable] == false } : []
56
56
  @authenticator = nil
57
57
  @default_access = nil
58
58
  end
@@ -70,7 +70,7 @@ module Moonrope
70
70
  self.loaded_from = directory
71
71
  self
72
72
  else
73
- raise Moonrope::Error, "Can't reload Moonrope::Base as it wasn't required from a directory"
73
+ raise Moonrope::Errors::Error, "Can't reload Moonrope::Base as it wasn't required from a directory"
74
74
  end
75
75
  end
76
76
 
@@ -67,8 +67,12 @@ module Moonrope
67
67
  # @param name [Symbol] the name of the helper
68
68
  # @yield stores the block to execute for the helper
69
69
  #
70
- def helper(name, &block)
71
- helper_instance = Moonrope::Helper.new(name, nil, &block)
70
+ def helper(name, options = {}, &block)
71
+ if @base.helper(name, nil)
72
+ raise Moonrope::Errors::HelperAlreadyDefined, "Helper has already been defined with name `#{name}`"
73
+ end
74
+
75
+ helper_instance = Moonrope::Helper.new(name, nil, options, &block)
72
76
  @base.helpers << helper_instance
73
77
  helper_instance
74
78
  end
@@ -49,8 +49,12 @@ module Moonrope
49
49
  # @param name [Symbol] the name of the helper
50
50
  # @yield stores the block to execute for the helper
51
51
  #
52
- def helper(name, &block)
53
- @controller.base.helpers << Moonrope::Helper.new(name, @controller, &block)
52
+ def helper(name, options = {}, &block)
53
+ if @controller.base.helper(name, @controller)
54
+ raise Moonrope::Errors::HelperAlreadyDefined, "Helper has already been defined with name `#{name}`"
55
+ end
56
+
57
+ @controller.base.helpers << Moonrope::Helper.new(name, @controller, options, &block)
54
58
  end
55
59
  end
56
60
  end
@@ -4,6 +4,8 @@ module Moonrope
4
4
  class Error < StandardError
5
5
  end
6
6
 
7
+ class HelperAlreadyDefined < Error; end
8
+
7
9
  class RequestError < Error
8
10
  attr_reader :options
9
11
 
@@ -10,6 +10,8 @@ module Moonrope
10
10
  # @return [Proc] the proc to execute
11
11
  attr_reader :block
12
12
 
13
+ # @return [Hash] options for this helper
14
+ attr_reader :options
13
15
 
14
16
  #
15
17
  # Initialize a new helper
@@ -18,9 +20,10 @@ module Moonrope
18
20
  # @param controller [Moonrope::Controller] the controller the helper belongs to
19
21
  # @yield stores the block for use later
20
22
  #
21
- def initialize(name, controller, &block)
23
+ def initialize(name, controller, options = {}, &block)
22
24
  @name = name
23
25
  @controller = controller
26
+ @options = options
24
27
  @block = block
25
28
  end
26
29
 
@@ -27,8 +27,20 @@ module Moonrope
27
27
  result.status = 'not-found'
28
28
  result.data = {:message => exception.message}
29
29
  end
30
+
31
+ # Add a helper for auto setting parameters
32
+ app.config.moonrope.dsl.instance_eval do
33
+ helper :auto_set_params_for, :unloadable => false do |object|
34
+ current_action = object.new_record? ? :create_only : :update_only
35
+ request.action.params.select { |k,v| v[:set] == true || v[:set] == current_action }.keys.each do |param|
36
+ object.send("#{param}=", params[param]) if params.has?(param)
37
+ end
38
+ end
39
+ end
30
40
  end
31
41
 
42
+ puts app.config.moonrope.helpers.inspect
43
+
32
44
  # Insert the Moonrope middleware into the application's middleware
33
45
  # stack (at the bottom).
34
46
  app.middleware.use(
@@ -1,3 +1,3 @@
1
1
  module Moonrope
2
- VERSION = '1.1.3'
2
+ VERSION = '1.1.4'
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.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-29 00:00:00.000000000 Z
11
+ date: 2014-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  requirements: []
146
146
  rubyforge_project:
147
- rubygems_version: 2.2.0
147
+ rubygems_version: 2.2.2
148
148
  signing_key:
149
149
  specification_version: 4
150
150
  summary: An API server DSL.