Class: Waw::ResourceCollection
Overview
Localized resources
Defined Under Namespace
Classes: DSL
Instance Attribute Summary collapse
-
#__name ⇒ Object
readonly
Resource name.
Class Method Summary collapse
-
.parse_resource_file(f, name = File.basename(f, '.rs')) ⇒ Object
Parses a resource file.
-
.parse_resources(str, name = "unnamed") ⇒ Object
Parses some resource string.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Returns the resource installed under name.
-
#each ⇒ Object
(also: #each_pair)
Yields the block with each resource key,value pair.
-
#has_resource?(name) ⇒ Boolean
Checks if a resource exists.
-
#initialize(name = "unnamed") ⇒ ResourceCollection
constructor
Creates a resource collection.
-
#method_missing(name, *args) ⇒ Object
Logs a friendly message and returns nil.
Constructor Details
#initialize(name = "unnamed") ⇒ ResourceCollection
Creates a resource collection
32 33 34 35 |
# File 'lib/waw/resource_collection.rb', line 32 def initialize(name = "unnamed") @resources = {} @__name = name end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
Logs a friendly message and returns nil
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/waw/resource_collection.rb', line 75 def method_missing(name, *args) if args.size==1 args[0] elsif args.size==0 Waw.logger.warn("No such resource #{name} on #{@__name}, (#{caller[0]})") nil else super end end |
Instance Attribute Details
#__name ⇒ Object (readonly)
Resource name
29 30 31 |
# File 'lib/waw/resource_collection.rb', line 29 def __name @__name end |
Class Method Details
.parse_resource_file(f, name = File.basename(f, '.rs')) ⇒ Object
Parses a resource file
94 95 96 |
# File 'lib/waw/resource_collection.rb', line 94 def self.parse_resource_file(f, name=File.basename(f, '.rs')) parse_resources File.read(f), name end |
.parse_resources(str, name = "unnamed") ⇒ Object
Parses some resource string
87 88 89 90 91 |
# File 'lib/waw/resource_collection.rb', line 87 def self.parse_resources(str, name = "unnamed") r = ResourceCollection.new(name) DSL.new(r).instance_eval str r end |
Instance Method Details
#[](name) ⇒ Object
Returns the resource installed under name
44 45 46 |
# File 'lib/waw/resource_collection.rb', line 44 def [](name) @resources[name] end |
#each ⇒ Object Also known as: each_pair
Yields the block with each resource key,value pair
38 39 40 |
# File 'lib/waw/resource_collection.rb', line 38 def each @resources.each_pair {|k, v| yield(k, v)} end |
#has_resource?(name) ⇒ Boolean
Checks if a resource exists
49 50 51 |
# File 'lib/waw/resource_collection.rb', line 49 def has_resource?(name) @resources.has_key?(name) end |