Module: Phenomenal::DSL

Included in:
Kernel
Defined in:
lib/phenomenal/dsl.rb,
lib/phenomenal/viewer/dsl.rb,
lib/phenomenal/relationship/dsl.rb

Overview

Define the DSL methods for relationships

Class Method Summary collapse

Class Method Details

.define_relationships(klass) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/phenomenal/relationship/dsl.rb', line 3

def self.define_relationships(klass)
  klass.class_eval do
    # Requirements
    def phen_requirements_for(source,targets)
      Phenomenal::Manager.instance.default_feature.requirements_for(source,targets)
    end
    Phenomenal::DSL.phen_alias(:requirements_for,klass)
    
     # Implications
    def phen_implications_for(source,targets)
      Phenomenal::Manager.instance.default_feature.implications_for(source,targets)
    end
    Phenomenal::DSL.phen_alias(:implications_for,klass)
    
     # Suggestions
    def phen_suggestions_for(source,targets)
      Phenomenal::Manager.instance.default_feature.suggestions_for(source,targets)
    end
    Phenomenal::DSL.phen_alias(:suggestions_for,klass)
    
  end
end

.define_viewers(klass) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/phenomenal/viewer/dsl.rb', line 2

def self.define_viewers(klass)
  klass.class_eval do
    # Graphical
    def phen_graphical_view(file="view.png")
      Phenomenal::Viewer::Graphical.new(file).generate
    end
    
    #Textual
    def phen_textual_view
      Phenomenal::Viewer::Textual.new.generate
    end
  end
end

.included(klass) ⇒ Object

Override included hook method



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/phenomenal/dsl.rb', line 4

def self.included(klass)
  klass.class_eval do
    # Define context with adaptations
    def phen_context(context,*contexts,&block)
      Phenomenal::Context.create(false,nil,context,*contexts,&block)
    end
    Phenomenal::DSL.phen_alias(:context,klass)
    
    # Define context with adaptations
    def phen_feature(context,*contexts,&block)
      Phenomenal::Feature.create(false,nil,context,*contexts,&block)
    end
    Phenomenal::DSL.phen_alias(:feature,klass)
    
    # Forget Context
    def phen_forget_context(context)
      Phenomenal::Manager.instance.find_context(context).forget
    end
    
    # Add adaptation
    def phen_add_adaptation(context,klass, method_name, &implementation)
      Phenomenal::Manager.instance.find_context(context).add_adaptation(
        klass, method_name,true, &implementation
      )
    end
    
    def phen_add_class_adaptation(context,klass, method_name, &implementation)
      Phenomenal::Manager.instance.find_context(context).add_adaptation(
        klass, method_name,false, &implementation
      )
    end
    
    # Remove Adaptation
    def phen_remove_adaptation(context,klass,method_name) 
      Phenomenal::Manager.instance.find_context(context).remove_adaptation(
        klass,method_name,true
      )
    end
    
    def phen_remove_class_adaptation(context,klass,method_name) 
      Phenomenal::Manager.instance.find_context(context).remove_adaptation(
        klass,method_name,false
      )
    end
    
    # Activate Context
    def phen_activate_context(context,*contexts)
      Phenomenal::DSL.phen_switch_context_state(true,context,*contexts)
    end
    Phenomenal::DSL.phen_alias(:activate_context,klass)
    
    # Deactivate Context
    def phen_deactivate_context(context,*contexts)
      Phenomenal::DSL.phen_switch_context_state(false,context,*contexts)
    end
    Phenomenal::DSL.phen_alias(:deactivate_context,klass)
    
    # Context is active?
    def phen_context_active?(context)
      Phenomenal::Manager.instance.find_context(context).active?
    end
    
    # Context informations
    def phen_context_information(context)
      Phenomenal::Manager.instance.find_context(context).information
    end
    
    # Default Feature
    def phen_default_feature
      Phenomenal::Manager.instance.default_feature
    end
    
    # Defined context registered in the manager
    def phen_defined_contexts    
      Phenomenal::Manager.instance.contexts.values
    end
    
    # Proceed
    def phen_proceed(*args,&block)
      Phenomenal::Manager.instance.proceed(caller,self,*args,&block)
    end
    Phenomenal::DSL.phen_alias(:proceed,klass)

    # Change conflict resolution policy (for the proceed call)
    def phen_change_conflict_policy(&block)
      Phenomenal::Manager.instance.change_conflict_policy(&block) 
    end
  end
  # Add relationships specific DSL
  define_relationships(klass)
  # Add Viewers specific DSL
  define_viewers(klass)
end