Class: Breeze::OptionDefinition

Inherits:
SharedBase show all
Defined in:
app/models/breeze/option_definition.rb

Overview

Quite simple mapping from name to usually a selection of values. Options have type that can be set but usually is inferred from wether there is one values (select) other wise text. date is also supported.

a corresponding ./app/views/breeze/sections/_option_form_TYPE.haml nust exist to render the type.

Also values may be provided by a module function/attribute on Breeze. eg option text_color (also shade_color) have a Breeze.text_color that return a hash. In this case so it is easy to customize the colors of the app.

Instance Attribute Summary

Attributes inherited from ActiveYaml

#data

Instance Method Summary collapse

Methods inherited from SharedBase

load_file

Methods inherited from ActiveYaml

all, append, define_access, define_association, delete, fields, find, find_all, find_by, first, full_path, #id, #id=, #initialize, load_file, #persisted?, primary_key, reload, save_all, set_root_path, the_meta_class

Constructor Details

This class inherits a constructor from Breeze::ActiveYaml

Instance Method Details

#has_values?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'app/models/breeze/option_definition.rb', line 30

def has_values?
  return true if Breeze.respond_to?( name.to_sym )
  return false if data[:values].nil?
  ! data[:values].empty?
end

#typeObject



21
22
23
24
25
26
27
28
# File 'app/models/breeze/option_definition.rb', line 21

def type
  return data[:type] unless data[:type].blank?
  if has_values?
    "select"
  else
    "text"
  end
end

#valuesObject



36
37
38
39
40
# File 'app/models/breeze/option_definition.rb', line 36

def values
  return Breeze.send(name.to_sym).keys if Breeze.respond_to?( name.to_sym )
  return [] unless has_values?
  data[:values].split(" ")
end