Class: AppScrollsScrolls::Scroll
- Inherits:
-
Object
- Object
- AppScrollsScrolls::Scroll
- Extended by:
- Comparable
- Defined in:
- lib/appscrolls/scroll.rb
Constant Summary collapse
- ATTRIBUTES =
%w(key args category name description template config exclusive tags run_before run_after requires website)
- DEFAULT_ATTRIBUTES =
{ :category => 'other', :args => [], :tags => [], :run_after => [], :run_before => [], :requires => [] }
Class Method Summary collapse
- .<=>(another) ⇒ Object
-
.attributes ⇒ Object
The attributes hash containing any set values for.
- .attributes=(hash) ⇒ Object
- .compile ⇒ Object
- .config ⇒ Object
- .from_mongo(key) ⇒ Object
- .generate(key, template_or_file, attributes = {}) ⇒ Object
- .get_binding ⇒ Object
- .to_mongo(value) ⇒ Object
Instance Method Summary collapse
Class Method Details
.<=>(another) ⇒ Object
11 12 13 14 15 |
# File 'lib/appscrolls/scroll.rb', line 11 def self.<=>(another) return -1 if another.run_after.include?(self.key) || self.run_before.include?(another.key) return 1 if another.run_before.include?(self.key) || self.run_after.include?(another.key) self.key <=> another.key end |
.attributes ⇒ Object
The attributes hash containing any set values for
66 67 68 |
# File 'lib/appscrolls/scroll.rb', line 66 def self.attributes @attributes ||= DEFAULT_ATTRIBUTES.dup end |
.attributes=(hash) ⇒ Object
70 71 72 |
# File 'lib/appscrolls/scroll.rb', line 70 def self.attributes=(hash) attributes.merge! hash end |
.compile ⇒ Object
83 84 85 |
# File 'lib/appscrolls/scroll.rb', line 83 def self.compile "# >#{"[ #{name} ]".center(75,'-')}<\n\n# #{description}\nsay_scroll '#{name}'\n\n#{template}\n" end |
.config ⇒ Object
74 75 76 77 |
# File 'lib/appscrolls/scroll.rb', line 74 def self.config return nil unless attributes[:config] AppScrollsScrolls::Config.new(attributes[:config]) end |
.from_mongo(key) ⇒ Object
97 98 99 100 |
# File 'lib/appscrolls/scroll.rb', line 97 def self.from_mongo(key) return key if key.respond_to?(:superclass) && key.superclass == AppScrollsScrolls::Scroll AppScrollsScrolls::Scrolls[key] end |
.generate(key, template_or_file, attributes = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/appscrolls/scroll.rb', line 27 def self.generate(key, template_or_file, attributes = {}) if template_or_file.respond_to?(:read) file = template_or_file.read parts = file.split(/^__END__$/) raise ArgumentError, "The scroll file must have YAML matter after an __END__" unless parts.size == 2 template = parts.first.strip attributes = YAML.load(parts.last).inject({}) do |h,(k,v)| h[k.to_sym] = v h end.merge!(attributes) else template = template_or_file end scroll_class = Class.new(AppScrollsScrolls::Scroll) scroll_class.attributes = attributes scroll_class.template = template scroll_class.key = key scroll_class end |
.get_binding ⇒ Object
102 103 104 |
# File 'lib/appscrolls/scroll.rb', line 102 def self.get_binding binding end |
.to_mongo(value) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/appscrolls/scroll.rb', line 88 def self.to_mongo(value) case value when Class value.key when String value end end |
Instance Method Details
#attributes ⇒ Object
79 80 81 |
# File 'lib/appscrolls/scroll.rb', line 79 def attributes self.class.attributes end |
#compile ⇒ Object
86 |
# File 'lib/appscrolls/scroll.rb', line 86 def compile; self.class.compile end |