Class: IronHide::Storage::FileAdapter Private

Inherits:
AbstractAdapter show all
Defined in:
lib/iron_hide/storage/file_adapter.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFileAdapter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of FileAdapter.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/iron_hide/storage/file_adapter.rb', line 7

def initialize
  json = IronHide.json.each_with_object([]) do |files, ary|
    Array(files).map do |file|
      ary.concat(MultiJson.load(File.open(file).read, minify: true))
    end
  end
  @rules = unfold(json)
rescue MultiJson::ParseError => e
  raise IronHideError, "#{e.cause}: #{e.data}"
rescue => e
  raise IronHideError, "Invalid or missing JSON file: #{e.to_s}"
end

Instance Attribute Details

#rulesObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



5
6
7
# File 'lib/iron_hide/storage/file_adapter.rb', line 5

def rules
  @rules
end

Instance Method Details

#unfold(json) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Unfold the JSON definitions of the rules into a Hash with this structure: {

"com::test::TestResource" => {
  "action" => [
    { ... }, { ... }, { ... }
  ]
}

}

Parameters:

  • json (Array<Hash>)

Returns:

  • (Hash)


35
36
37
38
39
40
41
# File 'lib/iron_hide/storage/file_adapter.rb', line 35

def unfold(json)
  json.inject(hash_of_hashes) do |rules, json_rule|
    resource, actions = json_rule["resource"], json_rule["action"]
    actions.each { |act| rules[resource][act] << json_rule }
    rules
  end
end

#where(opts = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
# File 'lib/iron_hide/storage/file_adapter.rb', line 20

def where(opts = {})
  self[opts[:resource]][opts[:action]]
end