Module: FreshBooks::Schema::Mixin::ClassMethods

Defined in:
lib/freshbooks/schema/mixin.rb

Instance Method Summary collapse

Instance Method Details

#define_schema {|self.schema_definition| ... } ⇒ Object

Yields:

  • (self.schema_definition)

11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/freshbooks/schema/mixin.rb', line 11

def define_schema
  # Create the class method accessor for the schema definition
  cattr_accessor :schema_definition
  self.schema_definition ||= FreshBooks::Schema::Definition.new
  
  # Yield to the block for the user to define the schema
  yield self.schema_definition
  
  # Process the schema additions
  schema_definition.members.each do |member|
    process_schema_member(member)
  end
end

#process_schema_member(member) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/freshbooks/schema/mixin.rb', line 25

def process_schema_member(member)
  member_name = member.first
  member_options = member.last
  
  # Create accessor
  attr_accessor member_name
  
  # Protect write if read only
  if member_options[:read_only]
    protected "#{member_name}="
  end
end