Module: Vinber

Defined in:
lib/vinber.rb,
lib/vinber/version.rb,
lib/vinber/translate.rb,
lib/vinber/vinber_klass.rb,
lib/vinber/current_vinbers.rb,
lib/vinber/vinber_instance.rb

Defined Under Namespace

Modules: Instance, Klass Classes: CurrentVinbers, Translate, VinberUndefined

Constant Summary collapse

VERSION =
"0.3.2"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



10
11
12
13
# File 'lib/vinber.rb', line 10

def self.extended(base)
  base.class_attribute(:defined_vinbers, instance_writer: false)
  base.defined_vinbers = {}
end

Instance Method Details

#inherited(base) ⇒ Object



15
16
17
18
# File 'lib/vinber.rb', line 15

def inherited(base)
  base.defined_vinbers = defined_vinbers.deep_dup
  super
end

#vinber(definitions) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vinber.rb', line 20

def vinber(definitions)
  need_validates = definitions.delete(:validates)
  need_scope = definitions.delete(:scope)
  definitions.each do |name, values|
    detect_vinber_conflict! name
    validates_from_vinber name, values if need_validates
    scope_from_vinber name, values if need_scope
    defined_vinbers[name.to_s] = case
    when values.is_a?(Hash)
      values.with_indifferent_access
    when values.is_a?(Array)
      values
    else
      Array.wrap values.to_s
    end
  end
end

#vinber_defined?(attr_key = nil) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/vinber.rb', line 42

def vinber_defined?(attr_key = nil)
  attr_key ? defined_vinbers.has_key?(attr_key.to_s) : defined_vinbers.present?
end

#vinbersObject



38
39
40
# File 'lib/vinber.rb', line 38

def vinbers
  Vinber::CurrentVinbers.new defined_vinbers
end