Class: GcalMapper::Mapper::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/gcal_mapper/mapper/dsl.rb

Overview

Provide DSL to configure gem

Constant Summary collapse

VALID_FIELD_OPTIONS =

options available in DSL

[:source, :if_empty, :match, :default]

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ DSL

Intitialize config



11
12
13
# File 'lib/gcal_mapper/mapper/dsl.rb', line 11

def initialize(config)
  @config = config
end

Instance Method Details

#calendar(id) ⇒ Object

Add new calendar id

Parameters:

  • id (string)

    calendar id to add



18
19
20
# File 'lib/gcal_mapper/mapper/dsl.rb', line 18

def calendar (id)
  @config.calendars.push(id)
end

#configure(options = {}) ⇒ Object

Add authentification configuration

Parameters:

  • options (Hash) (defaults to: {})

    contains the stuff to configure authetification

Raises:



40
41
42
43
44
45
46
# File 'lib/gcal_mapper/mapper/dsl.rb', line 40

def configure(options = {})
  raise GcalMapper::DSLSyntaxError, 'you must give a credential file' if options[:file].nil?
  @config.file = options[:file]
  @config.client_email = options[:client_email]
  @config.user_email = options[:user_email]
  @config.password = options[:password]
end

#field(name, options = {}) ⇒ Object

Add a new field

Parameters:

  • name (String)

    DB field name

  • options (Hash) (defaults to: {})

    contains source options used to fill the field

Raises:



26
27
28
29
30
31
32
33
34
35
# File 'lib/gcal_mapper/mapper/dsl.rb', line 26

def field(name, options = {})
  raise GcalMapper::DSLSyntaxError, 'Source option must be present' if !options.include?(:source)
  raise GcalMapper::DSLSyntaxError, 'field option not available' if (options.keys != VALID_FIELD_OPTIONS & options.keys)

  if options[:match]
    raise GcalMapper::DSLSyntaxError, 'invalid regex' if options[:match].class != Regexp
  end

  @config.fields.merge!(name => options)
end

#google_id(name) ⇒ Object

Give the field in DB that is reserved to put event id given by google

Parameters:

  • name (String)

    DB field name



51
52
53
# File 'lib/gcal_mapper/mapper/dsl.rb', line 51

def google_id(name)
  @config.gid = name
end