Class: Conjur::Policy::Ruby::Loader

Inherits:
Object
  • Object
show all
Includes:
Delegation
Defined in:
lib/conjur/policy/ruby/loader.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Delegation

#method_missing, #respond_to?

Constructor Details

#initialize(script, filename = nil) ⇒ Loader

Returns a new instance of Loader.



202
203
204
205
206
# File 'lib/conjur/policy/ruby/loader.rb', line 202

def initialize script, filename = nil
  @script = script
  @filename = filename
  @scope = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Conjur::Policy::Ruby::Delegation

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



185
186
187
# File 'lib/conjur/policy/ruby/loader.rb', line 185

def filename
  @filename
end

#scriptObject (readonly)

Returns the value of attribute script.



185
186
187
# File 'lib/conjur/policy/ruby/loader.rb', line 185

def script
  @script
end

Class Method Details

.create(yaml, filename = nil) ⇒ Object



196
197
198
# File 'lib/conjur/policy/ruby/loader.rb', line 196

def create(yaml, filename=nil)
  new(yaml, filename)
end

.load(yaml, filename = nil) ⇒ Object



192
193
194
# File 'lib/conjur/policy/ruby/loader.rb', line 192

def load yaml, filename = nil
  create(yaml, filename).load
end

.load_file(filename) ⇒ Object



188
189
190
# File 'lib/conjur/policy/ruby/loader.rb', line 188

def load_file filename
  load File.read(filename), filename
end

Instance Method Details

#do_scope(obj, &block) ⇒ Object



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/conjur/policy/ruby/loader.rb', line 234

def do_scope obj, &block
  push_scope obj
  class << obj
    attr_accessor :loader
    
    def do_scope obj, &block
      loader.do_scope obj, &block
    end
    
    def scope
      loader.scope
    end
    
    def to_yaml_properties
      super - [ :"@loader" ]
    end
  end
  obj.loader = self
  begin
    yield if block_given?
  ensure
    pop_scope
  end
end

#load(root = nil) ⇒ Object



212
213
214
215
216
217
218
219
220
# File 'lib/conjur/policy/ruby/loader.rb', line 212

def load root = nil
  args = [ script ]
  args << filename if filename
  root ||= Entitlements.new
  do_scope root do
    instance_eval(*args)
  end
  root
end

#loaderObject



208
209
210
# File 'lib/conjur/policy/ruby/loader.rb', line 208

def loader
  self
end

#pop_scopeObject



230
231
232
# File 'lib/conjur/policy/ruby/loader.rb', line 230

def pop_scope
  @scope.pop
end

#push_scope(obj) ⇒ Object



222
223
224
# File 'lib/conjur/policy/ruby/loader.rb', line 222

def push_scope obj
  @scope.push obj
end

#scopeObject



226
227
228
# File 'lib/conjur/policy/ruby/loader.rb', line 226

def scope
  @scope.last
end