Class: Settings::Variable
- Inherits:
-
Object
- Object
- Settings::Variable
- Defined in:
- lib/character/settings.rb
Instance Attribute Summary collapse
-
#default_value ⇒ Object
Returns the value of attribute default_value.
-
#description ⇒ Object
Returns the value of attribute description.
-
#group ⇒ Object
Returns the value of attribute group.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(group, name, attrs) ⇒ Variable
constructor
A new instance of Variable.
- #stored_object ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(group, name, attrs) ⇒ Variable
Returns a new instance of Variable.
59 60 61 62 63 64 65 |
# File 'lib/character/settings.rb', line 59 def initialize(group, name, attrs) @group = group @name = name @type = attrs['type'] || 'string' @description = attrs['description'] || '' @default_value = attrs['default_value'] || '' end |
Instance Attribute Details
#default_value ⇒ Object
Returns the value of attribute default_value.
53 54 55 |
# File 'lib/character/settings.rb', line 53 def default_value @default_value end |
#description ⇒ Object
Returns the value of attribute description.
53 54 55 |
# File 'lib/character/settings.rb', line 53 def description @description end |
#group ⇒ Object
Returns the value of attribute group.
53 54 55 |
# File 'lib/character/settings.rb', line 53 def group @group end |
#name ⇒ Object
Returns the value of attribute name.
53 54 55 |
# File 'lib/character/settings.rb', line 53 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
53 54 55 |
# File 'lib/character/settings.rb', line 53 def type @type end |
Instance Method Details
#stored_object ⇒ Object
67 68 69 |
# File 'lib/character/settings.rb', line 67 def stored_object Character::Settings::Variable.find_or_create_by(name: @name, group: @group) end |
#value ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/character/settings.rb', line 71 def value object = stored_object value = object.value || @default_value if @type == 'file' if object.has_file_uploaded? # return uploaded file return object.file.to_s elsif value.include? '//' # return direct link to file return value elsif value.empty? # return empty string return value else # return rails asset return ActionController::Base.helpers.asset_path(value) end elsif @type == 'integer' return value.to_i elsif @type == 'float' return value.to_f else # string return value end end |