forked from clayallsopp/formotion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use class level inheritable attributes for form_properties and form_t…
…itle Solves clashing of class variables when having two formable classes
- Loading branch information
Showing
3 changed files
with
31 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module ClassLevelInheritableAttributes | ||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end | ||
|
||
module ClassMethods | ||
def inheritable_attributes(*args) | ||
@inheritable_attributes ||= [:inheritable_attributes] | ||
@inheritable_attributes += args | ||
args.each do |arg| | ||
self.class.send(:attr_accessor, arg.to_sym) | ||
end | ||
@inheritable_attributes | ||
end | ||
|
||
def inherited(subclass) | ||
@inheritable_attributes.each do |inheritable_attribute| | ||
instance_var = "@#{inheritable_attribute}" | ||
subclass.instance_variable_set(instance_var, instance_variable_get(instance_var)) | ||
end | ||
end | ||
end | ||
end |