Class: EasyAttributes::Config

Inherits:
Object
  • Object
show all
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

Class Method Details

.attributesObject

Returns the symbol table



45
46
47
# File 'lib/easy_attributes.rb', line 45

def self.attributes
  @@attributes
end

.define(name, hash) ⇒ Object

Defines a symbol name to a hash of :name=>value



40
41
42
# File 'lib/easy_attributes.rb', line 40

def self.define(name, hash)
  @@attributes[name] = hash
end

.kb_sizeObject

Returns the kb_size setting



25
26
27
# File 'lib/easy_attributes.rb', line 25

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)


20
21
22
# File 'lib/easy_attributes.rb', line 20

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



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/easy_attributes.rb', line 53

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, :value=>val.to_i}
    @@attributes[col.to_s] ||= {}
    @@attributes[col.to_s][symbol.to_sym] = val.to_i
  end
end

.ormObject

Returns the ORM setting



35
36
37
# File 'lib/easy_attributes.rb', line 35

def self.orm
  @@orm
end

.orm=(o) ⇒ Object

Set the ORM or attribute manager, currently to :attr (attr_accessor) or :active_model



30
31
32
# File 'lib/easy_attributes.rb', line 30

def self.orm=(o)
  @@orm = o
end