Class: EasyAttributes::Config
- Inherits:
-
Object
- Object
- EasyAttributes::Config
- Defined in:
- lib/easy_attributes.rb
Overview
Configuration class for EasyAttributes, set at load time.
Constant Summary collapse
- @@orm =
:attr, :active_model
:attr
- @@attributes =
{}
- @@values =
{}
- @@kb_size =
:iec
Class Method Summary collapse
-
.attributes ⇒ Object
Returns the symbol table.
-
.define(name, hash) ⇒ Object
Defines a symbol name to a hash of :name=>value.
-
.kb_size ⇒ Object
Returns the kb_size setting.
-
.kb_size=(b) ⇒ Object
Values: :old, :jedec, or 1024 uses KB=1024 :new, :iec uses KiB=1024, no KB 1000, :decimal uses only KB (1000) (other values mix KB and KiB units).
-
.load(filename) ⇒ Object
Loads a tab-delimted filename into the symbol table in format: attribute value role symbolic_name short_description long_description (useful for “<option>” data) If a block is given, it should parse a file line and return an array of [attribute, value, role*, name, short*, long_description*], *denotes not required, but placeholder required.
-
.orm ⇒ Object
Returns the ORM setting.
-
.orm=(o) ⇒ Object
Set the ORM or attribute manager, currently to :attr (attr_accessor) or :active_model.
- .values ⇒ Object
Class Method Details
.attributes ⇒ Object
Returns the symbol table
43 44 45 |
# File 'lib/easy_attributes.rb', line 43 def self.attributes @@attributes end |
.define(name, hash) ⇒ Object
Defines a symbol name to a hash of :name=>value
38 39 40 |
# File 'lib/easy_attributes.rb', line 38 def self.define(name, hash) @@attributes[name] = hash end |
.kb_size ⇒ Object
Returns the kb_size setting
23 24 25 |
# File 'lib/easy_attributes.rb', line 23 def self.kb_size @@kb_size end |
.kb_size=(b) ⇒ Object
Values: :old, :jedec, or 1024 uses KB=1024
:new, :iec uses KiB=1024, no KB
1000, :decimal uses only KB (1000) (other values mix KB and KiB units)
18 19 20 |
# File 'lib/easy_attributes.rb', line 18 def self.kb_size=(b) @@kb_size = b end |
.load(filename) ⇒ Object
Loads a tab-delimted filename into the symbol table in format: attribute value role symbolic_name short_description long_description (useful for “<option>” data) If a block is given, it should parse a file line and return an array of [attribute, value, role*, name, short*, long_description*], *denotes not required, but placeholder required
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/easy_attributes.rb', line 59 def self.load(filename) File.open(filename).each do |r| next unless r =~ /^\w/ (col, val, priv, symbol, word, desc) = block_given? ? yield(r) : r.split(/\t/) next if desc.nil? || desc.empty? || symbol.empty? || word.empty? || symbol.nil? col = col.to_sym @@values[col] = {:sym=>{}, :val=>{}, :rec=>{}} unless @@values.has_key?(col) @@values[col][:sym][symbol.to_sym] = val.to_i @@values[col][:val][val] = symbol.to_sym @@values[col][:rec][symbol.to_sym] = {:word=>word, :description=>desc.chomp, :value=>val.to_i} @@attributes[col.to_s] ||= {} @@attributes[col.to_s][symbol.to_sym] = val.to_i end end |
.orm ⇒ Object
Returns the ORM setting
33 34 35 |
# File 'lib/easy_attributes.rb', line 33 def self.orm @@orm end |
.orm=(o) ⇒ Object
Set the ORM or attribute manager, currently to :attr (attr_accessor) or :active_model
28 29 30 |
# File 'lib/easy_attributes.rb', line 28 def self.orm=(o) @@orm = o end |
.values ⇒ Object
Returns the value table:
values[:name][:rec][:setting] = {:word, :description, :value}
values[:name][:sym][:setting] = value
values[:name][:value]["value"] = :symbol
51 52 53 |
# File 'lib/easy_attributes.rb', line 51 def self.values @@values end |