Class: DarDaDa::Config
- Inherits:
-
Hash
- Object
- Hash
- DarDaDa::Config
- Defined in:
- lib/dar_da_da/config.rb
Instance Attribute Summary collapse
-
#all_rights ⇒ Object
readonly
Returns the value of attribute all_rights.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #[](role_name) ⇒ Object
- #finalize ⇒ Object
-
#initialize(options = {}, &block) ⇒ Config
constructor
A new instance of Config.
- #reopen(&block) ⇒ Object
- #role(name, options = {}, &block) ⇒ Object
Constructor Details
Instance Attribute Details
#all_rights ⇒ Object (readonly)
Returns the value of attribute all_rights.
14 15 16 |
# File 'lib/dar_da_da/config.rb', line 14 def all_rights @all_rights end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/dar_da_da/config.rb', line 14 def @options end |
Instance Method Details
#[](role_name) ⇒ Object
24 25 26 27 |
# File 'lib/dar_da_da/config.rb', line 24 def [](role_name) role_name = role_name.to_sym unless role_name.blank? super(role_name) end |
#finalize ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/dar_da_da/config.rb', line 29 def finalize # Merge rights between roles each do |name, role| role.merge_rights do |role_name| self[role_name] end end # Check if default_role exists # and delete it if it does not .delete(:default_role) unless self[[:default_role]] # Set default role to first added # if not specified [:default_role] = @first_added_role_name unless [:default_role] # Finalize roles each{|name, role| role.finalize} # Collect and unify all_rights @all_rights = map do |role| role[1].to_a end @all_rights.flatten! @all_rights.uniq! end |
#reopen(&block) ⇒ Object
9 10 11 12 |
# File 'lib/dar_da_da/config.rb', line 9 def reopen(&block) instance_eval(&block) if block_given? finalize end |
#role(name, options = {}, &block) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/dar_da_da/config.rb', line 16 def role(name, ={}, &block) name = name.to_sym @options[:default_role] = name if [:default] @first_added_role_name = name if empty? self[name] ||= DarDaDa::Role.new(name) self[name].instance_eval(&block) if block_given? end |