Class: FormKeeper::Messages

Inherits:
Object
  • Object
show all
Defined in:
lib/formkeeper.rb

Constant Summary collapse

DEFAULT_ACTION_NAME =
'DEFAULT'
DEFAULT_CONSTRAINT_NAME =
'DEFAULT'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Messages

Returns a new instance of Messages.



367
368
369
# File 'lib/formkeeper.rb', line 367

def initialize(data)
  @data = data
end

Class Method Details

.from_file(path) ⇒ Object



363
364
365
366
# File 'lib/formkeeper.rb', line 363

def self.from_file(path)
  data = YAML.load_file(path)
  self.new(data)
end

Instance Method Details

#get(action_name, target_name, constraint_name) ⇒ Object



370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/formkeeper.rb', line 370

def get(action_name, target_name, constraint_name)
  if @data.has_key?(action_name.to_s)
    action = @data[action_name.to_s]
    return search_from_action_part(action, target_name, constraint_name)
  else
    if @data.has_key?(DEFAULT_ACTION_NAME)
      action = @data[DEFAULT_ACTION_NAME]
      return search_from_action_part(action, target_name, constraint_name)
    else
      return handle_missing_message(target_name)
    end
  end
end