Class: Editus::Script::DSL
- Inherits:
-
Object
- Object
- Editus::Script::DSL
- Defined in:
- lib/editus/script.rb
Constant Summary collapse
- TASKS =
%w[up down].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #desc(description) ⇒ Object
-
#initialize(name) ⇒ DSL
constructor
A new instance of DSL.
- #query(method, &block) ⇒ Object
- #task(method, &block) ⇒ Object
- #title(txt) ⇒ Object
Constructor Details
#initialize(name) ⇒ DSL
Returns a new instance of DSL.
56 57 58 59 |
# File 'lib/editus/script.rb', line 56 def initialize name @name = name @query_index = 0 end |
Class Method Details
.run(name, &block) ⇒ Object
52 53 54 |
# File 'lib/editus/script.rb', line 52 def self.run name, &block new(name).instance_eval(&block) end |
Instance Method Details
#desc(description) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/editus/script.rb', line 74 def desc description @description = if description.blank? || !description.is_a?(String) @query_index += 1 "Query##{@query_index}" else description end end |
#query(method, &block) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/editus/script.rb', line 83 def query method, &block internal = Internal.find_or_create @name internal.proxy ||= Editus::DefinitionProxy.new(@name) query_name = "query_#{method}" internal.proxy.define_singleton_method(query_name, &block) add_query_to_internal internal, query_name end |
#task(method, &block) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/editus/script.rb', line 61 def task method, &block return unless TASKS.include?(method.to_s) internal = Internal.find_or_create @name internal.proxy ||= Editus::DefinitionProxy.new(@name) internal.proxy.define_singleton_method(method, &block) end |
#title(txt) ⇒ Object
69 70 71 72 |
# File 'lib/editus/script.rb', line 69 def title txt internal = Internal.find_or_create @name internal.title = txt end |