The active support for Trax / Trax components.
Create a non anonymous class via a fully qualified class name note namespace it is created in must exist prior to creation
Trax::Core::NamedClass.new instead of Class.new differences
- Defines class within namespace, so no thing = some_module.const_set("Blah", Class.new) needed
- Allows you to access the created class name within the definition block, i.e.
myklass = some_module.const_set("Blah", Class.new do
puts name
end)
=> nil
Will put nil, as its referencing the anonymous class. However:
::Trax::Core::NamedClass.new("SomeModule::Blah") do
puts name
end
=> "SomeModule::Blah"
Holds reference to actual class being created.
- Allows you to pass an options hash which gets evaluated as class_attribute accessor
module Html
class Element
end
end
::Trax::Core::NamedClass.new(
"Html::DivWithDimensions",
Html::Element,
:default_height => "220px",
:default_width => "220px"
)
Html::Div.default_height => "220px"
Html::Div.default_width => "220px"
^ is probably a bad example, but you get the idea. Also note param 2 is the class you want to inherit from, which differs from the Class.new api which expects 1st param to be the class you are inheriting from. Broke from that api since its optional, and the thing that is not optional with a named class, is obviously the name.
Create a non anonymous module via a fully qualified module name note namespace it is created in must exist prior to creation
examples: (by default, any module args passed after the name of the module will be applied via extend)
With Args:
Trax::Core::NamedModule.new("Ecommerce::ItemExtensions", PricingExtension, ShippingExtension)
=> mod = Ecommerce.const_set("ItemExtensions")
mod.extend(PricingExtension)
mod.extend(ShippingExtension)
With :extensions keyword
Trax::Core::NamedModule.new("Ecommerce::ItemExtensions", :extensions => [::Ecommerce::PricingExtension])
With :includes keyword
Trax::Core::NamedModule.new("Ecommerce::ItemExtensions", :includes => [::Ecommerce::ShippingExtension])
Add this line to your application's Gemfile:
gem 'trax_core'
And then execute:
$ bundle
Or install it yourself as:
$ gem install trax_core
TODO: Write usage instructions here
- Fork it ( https://github.com/[my-github-username]/trax_core/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request