Class: GcalMapper::Mapper::DSL
- Inherits:
-
Object
- Object
- GcalMapper::Mapper::DSL
- 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
-
#calendar(id) ⇒ Object
Add new calendar id.
-
#configure(options = {}) ⇒ Object
Add authentification configuration.
-
#field(name, options = {}) ⇒ Object
Add a new field.
-
#google_id(name) ⇒ Object
Give the field in DB that is reserved to put event id given by google.
-
#initialize(config) ⇒ DSL
constructor
Intitialize config.
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
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
40 41 42 43 44 45 46 |
# File 'lib/gcal_mapper/mapper/dsl.rb', line 40 def configure( = {}) raise GcalMapper::DSLSyntaxError, 'you must give a credential file' if [:file].nil? @config.file = [:file] @config.client_email = [:client_email] @config.user_email = [:user_email] @config.password = [:password] end |
#field(name, options = {}) ⇒ Object
Add a new field
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gcal_mapper/mapper/dsl.rb', line 26 def field(name, = {}) raise GcalMapper::DSLSyntaxError, 'Source option must be present' if !.include?(:source) raise GcalMapper::DSLSyntaxError, 'field option not available' if (.keys != VALID_FIELD_OPTIONS & .keys) if [:match] raise GcalMapper::DSLSyntaxError, 'invalid regex' if [:match].class != Regexp end @config.fields.merge!(name => ) end |
#google_id(name) ⇒ Object
Give the field in DB that is reserved to put event id given by google
51 52 53 |
# File 'lib/gcal_mapper/mapper/dsl.rb', line 51 def google_id(name) @config.gid = name end |