Class: S3Master::Config
- Inherits:
-
Object
- Object
- S3Master::Config
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/s3_master/config.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #has_subpolicies?(bucket, policy_type) ⇒ Boolean
-
#initialize(cfg_file) ⇒ Config
constructor
A new instance of Config.
- #policy_ids(bucket, policy_type) ⇒ Object
- #region(bucket) ⇒ Object
- #template_relname(bucket, policy_type, policy_id = nil) ⇒ Object
Constructor Details
#initialize(cfg_file) ⇒ Config
Returns a new instance of Config.
10 11 12 |
# File 'lib/s3_master/config.rb', line 10 def initialize(cfg_file) @cfg = ActiveSupport::HashWithIndifferentAccess.new(YAML.load_file(cfg_file)) end |
Instance Method Details
#each(&block) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/s3_master/config.rb', line 35 def each(&block) @cfg[:buckets].each_pair do |bucket, policy_types| policy_types.each_pair do |policy_type, subpolicy| next if ! S3Master::RemotePolicy.known_policy_type?(policy_type) (policy_ids(bucket, policy_type) || [nil]).each do |policy_id| block.call(bucket, policy_type, policy_id) end end end end |
#has_subpolicies?(bucket, policy_type) ⇒ Boolean
16 17 18 |
# File 'lib/s3_master/config.rb', line 16 def has_subpolicies?(bucket, policy_type) @cfg[:buckets][bucket.to_s][policy_type.to_s].kind_of?(Hash) end |
#policy_ids(bucket, policy_type) ⇒ Object
29 30 31 32 33 |
# File 'lib/s3_master/config.rb', line 29 def policy_ids(bucket, policy_type) subpolicy = @cfg[:buckets][bucket][policy_type] policy_ids = subpolicy.kind_of?(Hash) ? subpolicy.keys : nil policy_ids end |
#region(bucket) ⇒ Object
14 |
# File 'lib/s3_master/config.rb', line 14 def region(bucket) @cfg[:buckets][bucket.to_s]["region"] ; end |
#template_relname(bucket, policy_type, policy_id = nil) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/s3_master/config.rb', line 20 def template_relname(bucket, policy_type, policy_id=nil) if self.has_subpolicies?(bucket, policy_type) raise(RuntimeError, "Bucket #{bucket} policy #{policy_type} has subpolicies so an id is required") if policy_id.nil? @cfg[:buckets][bucket][policy_type][policy_id] else @cfg[:buckets][bucket][policy_type] end end |