Class: Mccloud::Definitions
- Inherits:
-
Hash
- Object
- Hash
- Mccloud::Definitions
- Defined in:
- lib/mccloud/definitions.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
- #create ⇒ Object
- #define(name, templatename) ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(env) ⇒ Definitions
constructor
A new instance of Definitions.
- #load! ⇒ Object
- #path ⇒ Object
- #registered?(name) ⇒ Boolean
Constructor Details
#initialize(env) ⇒ Definitions
Returns a new instance of Definitions.
8 9 10 |
# File 'lib/mccloud/definitions.rb', line 8 def initialize(env) @env=env end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/mccloud/definitions.rb', line 6 def env @env end |
Instance Method Details
#create ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/mccloud/definitions.rb', line 56 def create begin unless self.exists? env.logger.info "Creating the definitions directory #{self.path} as it doesn't exist yet" FileUtils.mkdir(self.path) end rescue Exception => ex raise ::Mccloud::Error, "Error creating definitions directory #{self.path}: \n#{ex}" end end |
#define(name, templatename) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mccloud/definitions.rb', line 12 def define(name,templatename) # Check if template exists unless env.config.templates.registered?(templatename) raise ::Mccloud::Error, "Template #{templatename} does not exist" end # Create the definitions dir if needed unless self.exists? self.create end definition=::Mccloud::Definition.new(name,env) unless definition.exists? definition.copy_template(templatename) end end |
#exists? ⇒ Boolean
48 49 50 |
# File 'lib/mccloud/definitions.rb', line 48 def exists? File.directory?(self.path) end |
#load! ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mccloud/definitions.rb', line 28 def load! if self.exists? Dir[File.join(self.path,"**")].each do |dir| definition_name=File.basename(dir) d=Definition.new(definition_name,env) if d.valid? d.load! else env.logger.info "Skipping loading of definitions #{dir}" end end else env.logger.info "Skipping loading of definitions as the definition_path does exist" end end |
#path ⇒ Object
44 45 46 |
# File 'lib/mccloud/definitions.rb', line 44 def path @env.config.mccloud.definition_path end |
#registered?(name) ⇒ Boolean
52 53 54 |
# File 'lib/mccloud/definitions.rb', line 52 def registered?(name) return self.has_key?(name) end |