Skip to content

Support namespaces#79

Merged
dmytro-savochkin merged 1 commit into
jpignata:masterfrom
dmytro-savochkin:add-namespaces
Nov 6, 2022
Merged

Support namespaces#79
dmytro-savochkin merged 1 commit into
jpignata:masterfrom
dmytro-savochkin:add-namespaces

Conversation

@dmytro-savochkin

@dmytro-savochkin dmytro-savochkin commented Nov 5, 2022

Copy link
Copy Markdown
Collaborator

Closes feature request #17.

Now if Temping detects you wanted to create a namespace for your model it will create it if it doesn't exist yet or use the existing one. During .teardown it will undefine all the modules from the namespace previously created by itself.

A fresh entry in the Readme:

Temping supports creating models within namespaces.
You can do this either by just including the full namespace in the name:

Temping.create('animal/cat')

Animal::Cat.create # => <Animal::Cat id: 1>
Animal::Cat.table_name # => "cats"
Animal::Cat # => Animal::Cat(id: integer)

Or you can create the module(s) yourself:

module Engineers
  def self.table_name_prefix
    "hard_working_"
  end
end
Temping.create('engineers/developers')

Engineers::Developer.create # => <Engineers::Developer id: 1> 
Engineers::Developer.table_name # => "hard_working_developers"
Engineers::Developer # => Engineers::Developer(id: integer)

Please note that if you create the modules yourself, Temping will NOT attempt
to undefine them when you call Temping.teardown, it will only undefine the modules
created by itself:

module Engineers; end
Temping.create('engineers/developers')
Temping.create('animal/cat')

Temping.teardown

Object.const_defined?(:Engineers) # => true
Object.const_defined?(:Animal) # => false

Deep namespaces are supported as well:

Temping.create('continents/countries/cities/streets/buildings')

# => Continents::Countries::Cities::Streets::Building(id: integer) 

@dmytro-savochkin dmytro-savochkin linked an issue Nov 6, 2022 that may be closed by this pull request
@dmytro-savochkin dmytro-savochkin merged commit 32ce139 into jpignata:master Nov 6, 2022
@dmytro-savochkin dmytro-savochkin deleted the add-namespaces branch November 6, 2022 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Namespaced temps

1 participant