moonrope 1.2.1 → 1.2.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: daba7a2efd635f91a04eb69d14fcea60738c8be6
4
- data.tar.gz: 79bfec85cd725a038f2922c38e69fedb4e3a1a85
3
+ metadata.gz: 7ca039ed24cf2290a693a3114f6c814394126950
4
+ data.tar.gz: c3b20c6c65d8fedc44bb81e2416ee8a80ab7dd49
5
5
  SHA512:
6
- metadata.gz: 1d3ce17c2a410105909bd97ebbac3b8ee2e362c5945805772f02fe9f5038a42241d19cb5a2f9c9cabb71c753ee3a385becdd102e7ef10d13d51899702c515531
7
- data.tar.gz: e44eb7bc43ea321a06f10549dd9e4551fd5d43a3a24e928590b669e63e3ba1b805b60f9b9734707d4635c7f0cfab6f9f6436b335a9edad6eeb1e5c2b099bb50b
6
+ metadata.gz: d9498a71459b3944f2054b5636ba09f7f7c3c0436697dbccb822849c8af7b3e65c977594bd2731d2b151c5596cfa189de440b993888379033e6383b303bf6828
7
+ data.tar.gz: 6371c78a68ff96cd6f376e20d05832fb97f6659e28e47b48258fe1e92fe27e46808a7165e3785c63716427d1d1f4cb7ba34353eb1347cd67de3fa22ffc63bfbd
data/lib/moonrope.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'json'
2
2
  require 'logger'
3
- require 'deep_merge'
3
+ require 'deep_merge/core'
4
4
 
5
5
  require 'moonrope/action'
6
6
  require 'moonrope/action_result'
@@ -147,7 +147,7 @@ module Moonrope
147
147
  eval_environment = EvalEnvironment.new(@controller.base, request)
148
148
  end
149
149
 
150
- access_condition = self.access || @controller.base.default_access
150
+ access_condition = self.access || @controller.access || @controller.base.default_access
151
151
 
152
152
  if eval_environment.auth
153
153
  # If there's no authentication object, access is permitted otherwise
@@ -1,7 +1,7 @@
1
1
  module Moonrope
2
2
  class Controller
3
3
 
4
- attr_accessor :name, :actions, :befores
4
+ attr_accessor :name, :actions, :access, :befores
5
5
  attr_reader :base, :dsl
6
6
 
7
7
  #
@@ -15,6 +15,7 @@ module Moonrope
15
15
  @base = base
16
16
  @name = name
17
17
  @actions = {}
18
+ @access = nil
18
19
  @befores = []
19
20
  @dsl = Moonrope::DSL::ControllerDSL.new(self)
20
21
  @dsl.instance_eval(&block) if block_given?
@@ -57,8 +57,8 @@ module Moonrope
57
57
  #
58
58
  # @yield stores the block as the access check
59
59
  #
60
- def default_access(&block)
61
- @base.default_access = block
60
+ def default_access(value = nil, &block)
61
+ @base.default_access = block_given? ? block : value
62
62
  end
63
63
 
64
64
  #
@@ -43,6 +43,14 @@ module Moonrope
43
43
  before_action
44
44
  end
45
45
 
46
+ #
47
+ # Defines the access required for controller methods which do not
48
+ # define their own access.
49
+ #
50
+ def access(value = nil, &block)
51
+ @controller.access = block_given? ? block : value
52
+ end
53
+
46
54
  #
47
55
  # Defines a new helper for this controller.
48
56
  #
@@ -51,6 +51,7 @@ module Moonrope
51
51
  attribute.value_type = options[:type]
52
52
  attribute.source_attribute = options[:source_attribute]
53
53
  attribute.value = options[:value]
54
+ attribute.example = options[:eg] || options[:example]
54
55
  attribute.groups = @groups
55
56
  attribute.conditions = @conditions
56
57
  @structure.attributes[type] << attribute
@@ -52,22 +52,22 @@ module Moonrope
52
52
  hash = Hash.new
53
53
 
54
54
  # Add the 'basic' structured fields
55
- hash.deep_merge! hash_for_attributes(@attributes[:basic], object, environment)
55
+ DeepMerge.deep_merge! hash_for_attributes(@attributes[:basic], object, environment), hash
56
56
 
57
57
  # Always get a basic hash to work from
58
58
  if self.basic.is_a?(Proc)
59
- hash.deep_merge! environment.instance_eval(&self.basic)
59
+ DeepMerge.deep_merge! environment.instance_eval(&self.basic), hash
60
60
  end
61
61
 
62
62
  # Enhance with the full hash if requested
63
63
  if options[:full]
64
64
 
65
65
  # Add the 'full' structured fields
66
- hash.deep_merge! hash_for_attributes(@attributes[:full], object, environment)
66
+ DeepMerge.deep_merge! hash_for_attributes(@attributes[:full], object, environment), hash
67
67
 
68
68
  if self.full.is_a?(Proc)
69
69
  full_hash = environment.instance_eval(&self.full)
70
- hash.deep_merge! full_hash
70
+ DeepMerge.deep_merge! full_hash,hash
71
71
  end
72
72
  end
73
73
 
@@ -76,14 +76,14 @@ module Moonrope
76
76
 
77
77
  # Add structured expansions
78
78
  @attributes[:expansion].each do |attribute|
79
- next if options[:expansions].is_a?(Array) && !options[:expansions].include?(name.to_sym)
80
- hash.deep_merge!(hash_for_attributes([attribute], object, environment))
79
+ next if options[:expansions].is_a?(Array) && !options[:expansions].include?(attribute.name.to_sym)
80
+ DeepMerge.deep_merge! hash_for_attributes([attribute], object, environment), hash
81
81
  end
82
82
 
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
- hash.deep_merge!(name.to_sym => environment.instance_eval(&expansion))
86
+ DeepMerge.deep_merge!({name.to_sym => environment.instance_eval(&expansion)}, hash)
87
87
  end
88
88
  end
89
89
 
@@ -146,7 +146,7 @@ module Moonrope
146
146
  #
147
147
  def value_for_attribute(object, environment, attribute)
148
148
  value = object.send(attribute.source_attribute)
149
- if attribute.structure
149
+ if value && attribute.structure
150
150
  # If a structure is required, lookup the desired structure and set the
151
151
  # hash value as appropriate.
152
152
  if structure = self.base.structure(attribute.structure)
@@ -10,6 +10,7 @@ module Moonrope
10
10
  attr_accessor :structure
11
11
  attr_accessor :structure_opts
12
12
  attr_accessor :value
13
+ attr_accessor :example
13
14
 
14
15
  def initialize(type, name, description)
15
16
  @type = type
@@ -1,3 +1,3 @@
1
1
  module Moonrope
2
- VERSION = '1.2.1'
2
+ VERSION = '1.2.2'
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.2.1
4
+ version: 1.2.2
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-07-01 00:00:00.000000000 Z
11
+ date: 2014-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json