class Parsable::Context
Attributes
variables[RW]
Public Class Methods
new(args={})
click to toggle source
# File lib/parsable/context.rb, line 10 def initialize args={} today = Date.today @variables = args.fetch(:variables, { :random => OpenStruct.new(:hex => SecureRandom.hex, :integer => Time.now.to_i), :date => OpenStruct.new(:today => today.to_s, :year => today.year.to_s, :month => sprintf('%02d', today.month), :day => sprintf('%02d', today.day)), :time => OpenStruct.new(:now => Time.now.to_s), :custom => OpenStruct.new }) @variables.store(:remote, Parsable::Remote.new) @variables.store(:sremote, Parsable::Remote.new(:secure => true)) end
Public Instance Methods
custom_store(attribute, value)
click to toggle source
# File lib/parsable/context.rb, line 23 def custom_store attribute, value store :custom, attribute, value end
purge(object_key)
click to toggle source
# File lib/parsable/context.rb, line 31 def purge object_key variables.delete(object_key.to_sym) end
read(object_key, attribute)
click to toggle source
# File lib/parsable/context.rb, line 35 def read object_key, attribute object(object_key).send(attribute.to_sym) end
system_store(object_key, attribute, value)
click to toggle source
# File lib/parsable/context.rb, line 27 def system_store object_key, attribute, value store object_key, attribute, value end
Private Instance Methods
object(object_key)
click to toggle source
# File lib/parsable/context.rb, line 41 def object object_key variables[object_key.to_sym] ||= OpenStruct.new end
store(object_key, attribute, value)
click to toggle source
# File lib/parsable/context.rb, line 45 def store object_key, attribute, value object(object_key).send("#{attribute}=".to_sym, value) end