Module: AskAwesomely::DSL::ClassMethods
- Defined in:
- lib/ask_awesomely/dsl.rb
Instance Method Summary collapse
- #_api_client ⇒ Object
- #_state ⇒ Object
- #build(context = nil) ⇒ Object
- #design(id = nil, &block) ⇒ Object
- #field(type, &block) ⇒ Object
- #jump(conditions) ⇒ Object
- #no_branding ⇒ Object
- #send_responses_to(url) ⇒ Object
- #tags(*tags) ⇒ Object
- #title(title) ⇒ Object
Instance Method Details
#_api_client ⇒ Object
10 11 12 |
# File 'lib/ask_awesomely/dsl.rb', line 10 def _api_client @api_client = ApiClient.new end |
#_state ⇒ Object
14 15 16 17 18 19 |
# File 'lib/ask_awesomely/dsl.rb', line 14 def _state @state ||= OpenStruct.new( title: "", fields: [] ) end |
#build(context = nil) ⇒ Object
21 22 23 24 25 |
# File 'lib/ask_awesomely/dsl.rb', line 21 def build(context = nil) structure = new(context) typeform = Typeform.new(structure) _api_client.submit_typeform(typeform) end |
#design(id = nil, &block) ⇒ Object
44 45 46 |
# File 'lib/ask_awesomely/dsl.rb', line 44 def design(id = nil, &block) _state.design_id = id || ->(_) { Design.new(&block).id } end |
#field(type, &block) ⇒ Object
35 36 37 |
# File 'lib/ask_awesomely/dsl.rb', line 35 def field(type, &block) _state.fields << Field::Field.of_type(type, &block) end |
#jump(conditions) ⇒ Object
39 40 41 42 |
# File 'lib/ask_awesomely/dsl.rb', line 39 def jump(conditions) _state.logic_jumps ||= [] _state.logic_jumps << LogicJump.new(conditions) end |
#no_branding ⇒ Object
48 49 50 |
# File 'lib/ask_awesomely/dsl.rb', line 48 def no_branding _state.branding = false end |
#send_responses_to(url) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/ask_awesomely/dsl.rb', line 52 def send_responses_to(url) unless url =~ /\A#{URI::regexp(['http', 'https'])}\z/ raise AskAwesomely::InvalidUrlError, "you must use a valid URL for webhooks, e.g https://example.com/webhook" end _state.webhook_submit_url = url end |
#tags(*tags) ⇒ Object
31 32 33 |
# File 'lib/ask_awesomely/dsl.rb', line 31 def (*) _state. = end |
#title(title) ⇒ Object
27 28 29 |
# File 'lib/ask_awesomely/dsl.rb', line 27 def title(title) _state.title = title end |