Module: Portrayal

Defined in:
lib/portrayal.rb,
lib/portrayal/version.rb

Defined Under Namespace

Classes: Default, Schema

Constant Summary collapse

VERSION =
'0.9.0'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#portrayalObject (readonly)

Returns the value of attribute portrayal.



5
6
7
# File 'lib/portrayal.rb', line 5

def portrayal
  @portrayal
end

Class Method Details

.extended(c) ⇒ Object



6
# File 'lib/portrayal.rb', line 6

def self.extended(c); c.instance_variable_set(:@portrayal, Schema.new) end

Instance Method Details

#inherited(c) ⇒ Object



8
9
10
11
# File 'lib/portrayal.rb', line 8

def inherited(c)
  c.instance_variable_set(:@portrayal, portrayal.dup)
  c.include(c.portrayal.module)
end

#keyword(name, default: Schema::NULL, define: nil, &block) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/portrayal.rb', line 13

def keyword(name, default: Schema::NULL, define: nil, &block)
  include portrayal.module
  portrayal.add_keyword(name, default)
  return name unless block_given?
  nested = Class.new(superclass) { extend ::Portrayal }
  const_set(define || portrayal.camelize(name), nested).class_eval(&block)
  name
end