Class: Rays::AppModule::Module

Inherits:
Object
  • Object
show all
Defined in:
lib/rays/models/appmodule/base.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Module

Returns a new instance of Module.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/rays/models/appmodule/base.rb', line 79

def initialize(name)
  @name = name

  # transfer class properties to instance properties
  @type = self.class.type
  @archetype_name = self.class.archetype_name
  @generator = self.class.generate_worker
  @builder = self.class.build_worker
  @deployer = self.class.deploy_worker
  @cleaner = self.class.clean_worker
  @skip_mass_deploy = false

  descriptor = load_descriptor
  unless descriptor.nil?
    unless descriptor['builder'].nil?
      @builder = Worker::Manager.instnace.create :builder, descriptor['builder'].to_sym
    end
    unless descriptor['deployer'].nil?
      @deployer = Worker::Manager.instnace.create :deployer, descriptor['deployer'].to_sym
    end
    unless descriptor['cleaner'].nil?
      @cleaner = Worker::Manager.instnace.create :cleaner, descriptor['cleaner'].to_sym
    end
    unless descriptor['skip_mass_deploy'].nil?
      @skip_mass_deploy = true if descriptor['skip_mass_deploy'].to_s.strip.eql? 'true'
    end
  end
end

Class Attribute Details

.archetype_nameObject (readonly)

Returns the value of attribute archetype_name.



33
34
35
# File 'lib/rays/models/appmodule/base.rb', line 33

def archetype_name
  @archetype_name
end

.base_directoryObject (readonly)

Returns the value of attribute base_directory.



33
34
35
# File 'lib/rays/models/appmodule/base.rb', line 33

def base_directory
  @base_directory
end

.build_workerObject (readonly)

Returns the value of attribute build_worker.



33
34
35
# File 'lib/rays/models/appmodule/base.rb', line 33

def build_worker
  @build_worker
end

.clean_workerObject (readonly)

Returns the value of attribute clean_worker.



33
34
35
# File 'lib/rays/models/appmodule/base.rb', line 33

def clean_worker
  @clean_worker
end

.deploy_workerObject (readonly)

Returns the value of attribute deploy_worker.



33
34
35
# File 'lib/rays/models/appmodule/base.rb', line 33

def deploy_worker
  @deploy_worker
end

.generate_workerObject (readonly)

Returns the value of attribute generate_worker.



33
34
35
# File 'lib/rays/models/appmodule/base.rb', line 33

def generate_worker
  @generate_worker
end

.typeObject (readonly)

Returns the value of attribute type.



33
34
35
# File 'lib/rays/models/appmodule/base.rb', line 33

def type
  @type
end

Instance Attribute Details

#archetype_nameObject (readonly)

INSTANCE



77
78
79
# File 'lib/rays/models/appmodule/base.rb', line 77

def archetype_name
  @archetype_name
end

#nameObject (readonly)

INSTANCE



77
78
79
# File 'lib/rays/models/appmodule/base.rb', line 77

def name
  @name
end

#skip_mass_deployObject (readonly)

INSTANCE



77
78
79
# File 'lib/rays/models/appmodule/base.rb', line 77

def skip_mass_deploy
  @skip_mass_deploy
end

#typeObject (readonly)

INSTANCE



77
78
79
# File 'lib/rays/models/appmodule/base.rb', line 77

def type
  @type
end

Class Method Details

.archetype(archetype) ⇒ Object



46
47
48
# File 'lib/rays/models/appmodule/base.rb', line 46

def archetype(archetype)
  @archetype_name = archetype
end

.base_pathObject

Get module’s base directory path.



69
70
71
# File 'lib/rays/models/appmodule/base.rb', line 69

def base_path
  File.join($rays_config.project_root, @base_directory)
end

.builder(build_worker) ⇒ Object



54
55
56
# File 'lib/rays/models/appmodule/base.rb', line 54

def builder(build_worker)
  @build_worker = build_worker
end

.cleaner(clean_worker) ⇒ Object



62
63
64
# File 'lib/rays/models/appmodule/base.rb', line 62

def cleaner(clean_worker)
  @clean_worker = clean_worker
end

.deployer(deploy_worker) ⇒ Object



58
59
60
# File 'lib/rays/models/appmodule/base.rb', line 58

def deployer(deploy_worker)
  @deploy_worker = deploy_worker
end

.directory(directory_name) ⇒ Object



42
43
44
# File 'lib/rays/models/appmodule/base.rb', line 42

def directory(directory_name)
  @base_directory = directory_name
end

.generator(generate_worker) ⇒ Object



50
51
52
# File 'lib/rays/models/appmodule/base.rb', line 50

def generator(generate_worker)
  @generate_worker = generate_worker
end

.register(type) ⇒ Object

Class initializers



37
38
39
40
# File 'lib/rays/models/appmodule/base.rb', line 37

def register(type)
  @type = type.to_s
  Manager.instance.register_module_type(@type, self)
end

Instance Method Details

#build(skip_test = false) ⇒ Object

Builder



111
112
113
# File 'lib/rays/models/appmodule/base.rb', line 111

def build(skip_test = false)
  @builder.build self, skip_test
end

#cleanObject

Clean



125
126
127
# File 'lib/rays/models/appmodule/base.rb', line 125

def clean
  @cleaner.clean self
end

#create(generator_name = nil) ⇒ Object

Create a new module or initialize if a directory exists but no .module file.



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/rays/models/appmodule/base.rb', line 132

def create(generator_name=nil)

  if Dir.exist?(path)
    task("found <!#{@type} #{@name}!>", "", "failed to initialize <!#{@type} #{@name}!>") do
      create_descriptor
    end
  else

    generator = nil
    begin
      generator = Worker::Manager.instance.create(:generator, generator_name.to_sym) unless generator_name.nil?
    rescue RaysException
      # do nothing
    end
    generator ||= @generator

    FileUtils.mkdir_p(self.class.base_path) unless Dir.exist?(self.class.base_path)

    in_directory(self.class.base_path) do
      task("creating <!#{@type} #{@name}!>", "done", "failed") do
        generator.create self
        create_descriptor
      end
    end
  end
end

#deployObject

Deploy



118
119
120
# File 'lib/rays/models/appmodule/base.rb', line 118

def deploy
  @deployer.deploy self
end

#group_idObject

Group ID



162
163
164
# File 'lib/rays/models/appmodule/base.rb', line 162

def group_id
  "#{Project.instance.package}.#{type}"
end

#pathObject



166
167
168
169
170
171
# File 'lib/rays/models/appmodule/base.rb', line 166

def path
  if 'ear'.eql? type
    return self.class.base_path
  end
  File.join(self.class.base_path, @name)
end