Created
February 24, 2016 19:24
-
-
Save moofkit/b48941d746c429876873 to your computer and use it in GitHub Desktop.
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
https://www.dropbox.com/s/qylqw48lcehszkz/Screenshot%202016-02-24%2022.03.19.png?dl=0 | |
https://www.dropbox.com/s/pqju8wg70b76rnz/Screenshot%202016-02-24%2022.04.47.png?dl=0 | |
https://www.dropbox.com/s/imqnlyem413vauz/Screenshot%202016-02-24%2022.15.05.png?dl=0 |
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
module ApplicationType | |
extend ActiveSupport::Concern | |
module ClassMethods | |
def model_name | |
superclass.model_name | |
end | |
def name | |
superclass.name | |
end | |
def permit(*args) | |
@_args = args | |
end | |
def progress(*args) | |
@_progress_args = args | |
end | |
def _progress_args | |
@_progress_args | |
end | |
def _args | |
@_args | |
end | |
end | |
def assign_attributes(attrs = {}, options = {}) | |
raise ArgumentError, "expected hash" if attrs.nil? | |
if attrs.respond_to? :permit | |
permitted_attrs = attrs.send :permit, self.class._args | |
super(permitted_attrs) | |
else | |
super(attrs) | |
end | |
end | |
def total_fields | |
attributes.select { |name, val| self.class._progress_args.include?(name.to_sym) } | |
end | |
def completed_fields | |
total_fields.select{ |key, val| val.present? } | |
end | |
def progress | |
(completed_fields.count / total_fields.count.to_f * 100).to_i | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment