Module: Population
- Extended by:
- Definition
- Defined in:
- lib/population.rb,
lib/population/railtie.rb,
lib/population/version.rb,
lib/population/database.rb,
lib/population/populate.rb,
lib/population/definition.rb,
lib/population/configuration.rb,
lib/population/find_definitions.rb
Defined Under Namespace
Modules: Definition Classes: Configuration, Database, Populate, Railtie
Constant Summary collapse
- VERSION =
"0.0.9"
Class Attribute Summary collapse
-
.definition_file_paths ⇒ Object
Returns the value of attribute definition_file_paths.
Class Method Summary collapse
- .configuration ⇒ Object
- .find_definitions ⇒ Object
-
.populate(*table_names) ⇒ Object
Populate one or many tables specified by their table name.
-
.register_populate(populate) ⇒ Object
Register a populate in the populations register.
-
.reset(*table_names) ⇒ Object
Reset one or many tables specified by their class Constant.
Methods included from Definition
Class Attribute Details
.definition_file_paths ⇒ Object
Returns the value of attribute definition_file_paths.
3 4 5 |
# File 'lib/population/find_definitions.rb', line 3 def definition_file_paths @definition_file_paths end |
Class Method Details
.configuration ⇒ Object
14 15 16 |
# File 'lib/population.rb', line 14 def self.configuration @configuration ||= Configuration.new end |
.find_definitions ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/population/find_definitions.rb', line 8 def self.find_definitions absolute_definition_file_paths = definition_file_paths.map {|path| File.(path) } absolute_definition_file_paths.uniq.each do |path| load("#{path}.rb") if File.exists?("#{path}.rb") if File.directory? path Dir[File.join(path, '**', '*.rb')].sort.each do |file| load file end end end end |
.populate(*table_names) ⇒ Object
Populate one or many tables specified by their table name.
Arguments:
- klasses - One or many table names.
Examples:
Population.populate(:users)
Population.populate(:users, :articles)
61 62 63 64 65 |
# File 'lib/population.rb', line 61 def self.populate(*table_names) table_names.each do |name| populations[name].up end end |
.register_populate(populate) ⇒ Object
Register a populate in the populations register.
25 26 27 28 29 |
# File 'lib/population.rb', line 25 def self.register_populate(populate) # Register the populate definition in a hash of all populates. populations[populate.name] = populate populate end |
.reset(*table_names) ⇒ Object
Reset one or many tables specified by their class Constant.
Arguments:
- klasses - One or many class constants.
Examples:
Population.reset(User)
Population.reset(User, Article)
43 44 45 46 47 |
# File 'lib/population.rb', line 43 def self.reset(*table_names) table_names.each do |name| populations[name].down end end |