Class: Helioth::Dsl
- Inherits:
-
Object
- Object
- Helioth::Dsl
- Defined in:
- lib/helioth/dsl.rb
Constant Summary collapse
- DSL_FILE =
Pathname.new(Rails.root || '').join("config", "helioth.rb").to_s
Class Method Summary collapse
-
.load(file = nil) ⇒ Object
Should be loaded only one time using Helioth::DSL.dsl.
Instance Method Summary collapse
-
#action(feature_name, action_name) ⇒ Object
Get feature action.
- #authorized_for_instance?(feature_name, *actions_name, role) ⇒ Boolean
-
#authorized_for_locale?(feature_name, *actions_name, locale) ⇒ Boolean
Check authorization.
- #authorized_for_user?(feature_name, *actions_name, role) ⇒ Boolean
-
#feature(feature_name) ⇒ Object
Get feature.
-
#features(&block) ⇒ Object
Configure features.
-
#initialize ⇒ Dsl
constructor
A new instance of Dsl.
-
#method_missing(method_name, *args, &block) ⇒ Object
In case the DSL is not well used.
-
#relations(&block) ⇒ Object
Configure relations.
-
#roles(&block) ⇒ Object
Configure roles.
Constructor Details
#initialize ⇒ Dsl
Returns a new instance of Dsl.
6 7 8 |
# File 'lib/helioth/dsl.rb', line 6 def initialize Rails.logger.debug("Loading the DSL for the first time") end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
In case the DSL is not well used
20 21 22 |
# File 'lib/helioth/dsl.rb', line 20 def method_missing(method_name, *args, &block) raise "No such method #{__method__} in #{__FILE__}" end |
Class Method Details
.load(file = nil) ⇒ Object
Should be loaded only one time using Helioth::DSL.dsl
11 12 13 14 15 16 17 |
# File 'lib/helioth/dsl.rb', line 11 def self.load(file = nil) dsl = new dsl.instance_eval(file.nil? ? File.read(DSL_FILE) : File.read(file)) return(dsl) rescue Errno::ENOENT raise "Helioth::DSL DSL file missing" end |
Instance Method Details
#action(feature_name, action_name) ⇒ Object
Get feature action
51 52 53 54 55 |
# File 'lib/helioth/dsl.rb', line 51 def action(feature_name, action_name) feature(feature_name).actions.map{|action| action if action.name == action_name }.compact.first end |
#authorized_for_instance?(feature_name, *actions_name, role) ⇒ Boolean
66 67 68 |
# File 'lib/helioth/dsl.rb', line 66 def (feature_name, *actions_name, role) (feature_name, actions_name.flatten, {role: role, type: :instance}) end |
#authorized_for_locale?(feature_name, *actions_name, locale) ⇒ Boolean
Check authorization
58 59 60 |
# File 'lib/helioth/dsl.rb', line 58 def (feature_name, *actions_name, locale) (feature_name, actions_name.flatten, {locale: locale}) end |
#authorized_for_user?(feature_name, *actions_name, role) ⇒ Boolean
62 63 64 |
# File 'lib/helioth/dsl.rb', line 62 def (feature_name, *actions_name, role) (feature_name, actions_name.flatten, {role: role, type: :user}) end |
#feature(feature_name) ⇒ Object
Get feature
44 45 46 47 48 |
# File 'lib/helioth/dsl.rb', line 44 def feature(feature_name) @features.list.map{|feature| feature if feature.name == feature_name }.compact.first end |
#features(&block) ⇒ Object
Configure features
35 36 37 38 39 40 41 |
# File 'lib/helioth/dsl.rb', line 35 def features(&block) if block @features ||= Features.new(&block) else @features.list end end |
#relations(&block) ⇒ Object
Configure relations
30 31 32 |
# File 'lib/helioth/dsl.rb', line 30 def relations(&block) @relations ||= Relation.new(&block) end |
#roles(&block) ⇒ Object
Configure roles
25 26 27 |
# File 'lib/helioth/dsl.rb', line 25 def roles(&block) @roles ||= Role.new(&block) end |